FileDocCategorySizeDatePackage
TypeIdsSection.javaAPI DocAndroid 1.5 API5034Wed May 06 22:41:02 BST 2009com.android.dx.dex.file

TypeIdsSection

public final class TypeIdsSection extends UniformItemSection
Type identifiers list section of a .dex file.

Fields Summary
private final TreeMap
typeIds
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 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 non-null; the type to look up
return
>= 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 non-null; the type to look up
return
>= 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 non-null; the type to intern
return
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 TypeIdItemintern(com.android.dx.rop.cst.CstType type)
Interns an element into this instance.

param
type non-null; the type to intern
return
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 non-null; where to write

        throwIfNotPrepared();

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

        if (sz > 65536) {
            throw new UnsupportedOperationException("too many type ids");
        }

        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);