FileDocCategorySizeDatePackage
IndexMap.javaAPI DocAndroid 5.1 API14193Thu Mar 12 22:18:30 GMT 2015com.android.dx.merge

IndexMap

public final class IndexMap extends Object
Maps the index offsets from one dex file to those in another. For example, if you have string #5 in the old dex file, its position in the new dex file is {@code strings[5]}.

Fields Summary
private final com.android.dex.Dex
target
public final int[]
stringIds
public final short[]
typeIds
public final short[]
protoIds
public final short[]
fieldIds
public final short[]
methodIds
private final HashMap
typeListOffsets
private final HashMap
annotationOffsets
private final HashMap
annotationSetOffsets
private final HashMap
annotationSetRefListOffsets
private final HashMap
annotationDirectoryOffsets
private final HashMap
staticValuesOffsets
Constructors Summary
public IndexMap(com.android.dex.Dex target, com.android.dex.TableOfContents tableOfContents)

        this.target = target;
        this.stringIds = new int[tableOfContents.stringIds.size];
        this.typeIds = new short[tableOfContents.typeIds.size];
        this.protoIds = new short[tableOfContents.protoIds.size];
        this.fieldIds = new short[tableOfContents.fieldIds.size];
        this.methodIds = new short[tableOfContents.methodIds.size];
        this.typeListOffsets = new HashMap<Integer, Integer>();
        this.annotationOffsets = new HashMap<Integer, Integer>();
        this.annotationSetOffsets = new HashMap<Integer, Integer>();
        this.annotationSetRefListOffsets = new HashMap<Integer, Integer>();
        this.annotationDirectoryOffsets = new HashMap<Integer, Integer>();
        this.staticValuesOffsets = new HashMap<Integer, Integer>();

        /*
         * A type list, annotation set, annotation directory, or static value at
         * offset 0 is always empty. Always map offset 0 to 0.
         */
        this.typeListOffsets.put(0, 0);
        this.annotationSetOffsets.put(0, 0);
        this.annotationDirectoryOffsets.put(0, 0);
        this.staticValuesOffsets.put(0, 0);
    
Methods Summary
public com.android.dex.MethodIdadjust(com.android.dex.MethodId methodId)

        return new MethodId(target,
                adjustType(methodId.getDeclaringClassIndex()),
                adjustProto(methodId.getProtoIndex()),
                adjustString(methodId.getNameIndex()));
    
public com.android.dex.FieldIdadjust(com.android.dex.FieldId fieldId)

        return new FieldId(target,
                adjustType(fieldId.getDeclaringClassIndex()),
                adjustType(fieldId.getTypeIndex()),
                adjustString(fieldId.getNameIndex()));

    
public com.android.dex.ProtoIdadjust(com.android.dex.ProtoId protoId)

        return new ProtoId(target,
                adjustString(protoId.getShortyIndex()),
                adjustType(protoId.getReturnTypeIndex()),
                adjustTypeListOffset(protoId.getParametersOffset()));
    
public com.android.dex.ClassDefadjust(com.android.dex.ClassDef classDef)

        return new ClassDef(target, classDef.getOffset(), adjustType(classDef.getTypeIndex()),
                classDef.getAccessFlags(), adjustType(classDef.getSupertypeIndex()),
                adjustTypeListOffset(classDef.getInterfacesOffset()), classDef.getSourceFileIndex(),
                classDef.getAnnotationsOffset(), classDef.getClassDataOffset(),
                classDef.getStaticValuesOffset());
    
public SortableTypeadjust(SortableType sortableType)

        return new SortableType(sortableType.getDex(), adjust(sortableType.getClassDef()));
    
public com.android.dex.Annotationadjust(com.android.dex.Annotation annotation)

        ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32);
        new EncodedValueTransformer(out).transformAnnotation(
                annotation.getReader());
        return new Annotation(target, annotation.getVisibility(),
                new EncodedValue(out.toByteArray()));
    
public intadjustAnnotation(int annotationOffset)

        return annotationOffsets.get(annotationOffset);
    
public intadjustAnnotationDirectory(int annotationDirectoryOffset)

        return annotationDirectoryOffsets.get(annotationDirectoryOffset);
    
public intadjustAnnotationSet(int annotationSetOffset)

        return annotationSetOffsets.get(annotationSetOffset);
    
public intadjustAnnotationSetRefList(int annotationSetRefListOffset)

        return annotationSetRefListOffsets.get(annotationSetRefListOffset);
    
public com.android.dex.EncodedValueadjustEncodedArray(com.android.dex.EncodedValue encodedArray)

        ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32);
        new EncodedValueTransformer(out).transformArray(
                new EncodedValueReader(encodedArray, ENCODED_ARRAY));
        return new EncodedValue(out.toByteArray());
    
public com.android.dex.EncodedValueadjustEncodedValue(com.android.dex.EncodedValue encodedValue)

        ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32);
        new EncodedValueTransformer(out).transform(new EncodedValueReader(encodedValue));
        return new EncodedValue(out.toByteArray());
    
public intadjustField(int fieldIndex)

        return fieldIds[fieldIndex] & 0xffff;
    
public intadjustMethod(int methodIndex)

        return methodIds[methodIndex] & 0xffff;
    
public intadjustProto(int protoIndex)

        return protoIds[protoIndex] & 0xffff;
    
public intadjustStaticValues(int staticValuesOffset)

        return staticValuesOffsets.get(staticValuesOffset);
    
public intadjustString(int stringIndex)

        return stringIndex == ClassDef.NO_INDEX ? ClassDef.NO_INDEX : stringIds[stringIndex];
    
public intadjustType(int typeIndex)

        return (typeIndex == ClassDef.NO_INDEX) ? ClassDef.NO_INDEX : (typeIds[typeIndex] & 0xffff);
    
public com.android.dex.TypeListadjustTypeList(com.android.dex.TypeList typeList)

        if (typeList == TypeList.EMPTY) {
            return typeList;
        }
        short[] types = typeList.getTypes().clone();
        for (int i = 0; i < types.length; i++) {
            types[i] = (short) adjustType(types[i]);
        }
        return new TypeList(target, types);
    
public intadjustTypeListOffset(int typeListOffset)

        return typeListOffsets.get(typeListOffset);
    
public voidputAnnotationDirectoryOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        annotationDirectoryOffsets.put(oldOffset, newOffset);
    
public voidputAnnotationOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        annotationOffsets.put(oldOffset, newOffset);
    
public voidputAnnotationSetOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        annotationSetOffsets.put(oldOffset, newOffset);
    
public voidputAnnotationSetRefListOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        annotationSetRefListOffsets.put(oldOffset, newOffset);
    
public voidputStaticValuesOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        staticValuesOffsets.put(oldOffset, newOffset);
    
public voidputTypeListOffset(int oldOffset, int newOffset)

        if (oldOffset <= 0 || newOffset <= 0) {
            throw new IllegalArgumentException();
        }
        typeListOffsets.put(oldOffset, newOffset);