private void transformCode(Dex in, Code code, IndexMap indexMap) {
    contentsOut.codes.size++;
    codeOut.assertFourByteAligned();

    codeOut.writeUnsignedShort(code.getRegistersSize());
    codeOut.writeUnsignedShort(code.getInsSize());
    codeOut.writeUnsignedShort(code.getOutsSize());

    Code.Try[] tries = code.getTries();
    Code.CatchHandler[] catchHandlers = code.getCatchHandlers();
    codeOut.writeUnsignedShort(tries.length);

    int debugInfoOffset = code.getDebugInfoOffset();
    if (debugInfoOffset != 0) {
      codeOut.writeInt(debugInfoOut.getPosition());
      transformDebugInfoItem(in.open(debugInfoOffset), indexMap);
    } else {
      codeOut.writeInt(0);
    }

    short[] instructions = code.getInstructions();
    short[] newInstructions = instructionTransformer.transform(indexMap, instructions);
    codeOut.writeInt(newInstructions.length);
    codeOut.write(newInstructions);

    if (tries.length > 0) {
      if (newInstructions.length % 2 == 1) {
        codeOut.writeShort((short) 0); // padding
      }

      /*
       * We can't write the tries until we've written the catch handlers.
       * Unfortunately they're in the opposite order in the dex file so we
       * need to transform them out-of-order.
       */
      Dex.Section triesSection = dexOut.open(codeOut.getPosition());
      codeOut.skip(tries.length * SizeOf.TRY_ITEM);
      int[] offsets = transformCatchHandlers(indexMap, catchHandlers);
      transformTries(triesSection, tries, offsets);
    }
  }
Transform all annotation set ref lists.
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java