FileDocCategorySizeDatePackage
TypeIdsSection.javaAPI DocAndroid 5.1 API5440Thu Mar 12 22:18:30 GMT 2015com.android.dx.dex.file

TypeIdsSection

public final class TypeIdsSection extends UniformItemSection
Type identifiers list section of a {@code .dex} file.

Fields Summary
private final TreeMap
typeIds
{@code non-null;} map from types to {@link TypeIdItem} instances
Constructors Summary
public TypeIdsSection(DexFile file)
Constructs an instance. The file offset is initially unknown.

param
file {@code non-null;} file that this instance is part of

        super("type_ids", file, 4);

        typeIds = new TreeMap<Type, TypeIdItem>();
    
Methods Summary
public IndexedItemget(com.android.dx.rop.cst.Constant cst)
{@inheritDoc}

        if (cst == null) {
            throw new NullPointerException("cst == null");
        }

        throwIfNotPrepared();

        Type type = ((CstType) cst).getClassType();
        IndexedItem result = typeIds.get(type);

        if (result == null) {
            throw new IllegalArgumentException("not found: " + cst);
        }

        return result;
    
public intindexOf(com.android.dx.rop.type.Type type)
Gets the index of the given type, which must have been added to this instance.

param
type {@code non-null;} the type to look up
return
{@code >= 0;} the reference's index

        if (type == null) {
            throw new NullPointerException("type == null");
        }

        throwIfNotPrepared();

        TypeIdItem item = typeIds.get(type);

        if (item == null) {
            throw new IllegalArgumentException("not found: " + type);
        }

        return item.getIndex();
    
public intindexOf(com.android.dx.rop.cst.CstType type)
Gets the index of the given type, which must have been added to this instance.

param
type {@code non-null;} the type to look up
return
{@code >= 0;} the reference's index

        if (type == null) {
            throw new NullPointerException("type == null");
        }

        return indexOf(type.getClassType());
    
public TypeIdItemintern(com.android.dx.rop.type.Type type)
Interns an element into this instance.

param
type {@code non-null;} the type to intern
return
{@code non-null;} the interned reference

        if (type == null) {
            throw new NullPointerException("type == null");
        }

        throwIfPrepared();

        TypeIdItem result = typeIds.get(type);

        if (result == null) {
            result = new TypeIdItem(new CstType(type));
            typeIds.put(type, result);
        }

        return result;
    
public synchronized TypeIdItemintern(com.android.dx.rop.cst.CstType type)
Interns an element into this instance.

param
type {@code non-null;} the type to intern
return
{@code non-null;} the interned reference

        if (type == null) {
            throw new NullPointerException("type == null");
        }

        throwIfPrepared();

        Type typePerSe = type.getClassType();
        TypeIdItem result = typeIds.get(typePerSe);

        if (result == null) {
            result = new TypeIdItem(type);
            typeIds.put(typePerSe, result);
        }

        return result;
    
public java.util.Collectionitems()
{@inheritDoc}

        return typeIds.values();
    
protected voidorderItems()
{@inheritDoc}

        int idx = 0;

        for (Object i : items()) {
            ((TypeIdItem) i).setIndex(idx);
            idx++;
        }
    
public voidwriteHeaderPart(com.android.dx.util.AnnotatedOutput out)
Writes the portion of the file header that refers to this instance.

param
out {@code non-null;} where to write

        throwIfNotPrepared();

        int sz = typeIds.size();
        int offset = (sz == 0) ? 0 : getFileOffset();

        if (sz > DexFormat.MAX_TYPE_IDX + 1) {
            throw new DexIndexOverflowException("Too many type references: " + sz +
                    "; max is " + (DexFormat.MAX_TYPE_IDX + 1) + ".\n" +
                    Main.getTooManyIdsErrorMessage());
        }

        if (out.annotates()) {
            out.annotate(4, "type_ids_size:   " + Hex.u4(sz));
            out.annotate(4, "type_ids_off:    " + Hex.u4(offset));
        }

        out.writeInt(sz);
        out.writeInt(offset);