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

ProtoIdItem

public final class ProtoIdItem extends IndexedItem
Representation of a method prototype reference inside a Dalvik file.

Fields Summary
public static final int
WRITE_SIZE
size of instances when written out to a file, in bytes
private final com.android.dx.rop.type.Prototype
prototype
non-null; the wrapped prototype
private final com.android.dx.rop.cst.CstUtf8
shortForm
non-null; the short-form of the prototype
private TypeListItem
parameterTypes
null-ok; the list of parameter types or null if this prototype has no parameters
Constructors Summary
public ProtoIdItem(com.android.dx.rop.type.Prototype prototype)
Constructs an instance.

param
prototype non-null; the constant for the prototype


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

        this.prototype = prototype;
        this.shortForm = makeShortForm(prototype);

        StdTypeList parameters = prototype.getParameterTypes();
        this.parameterTypes = (parameters.size() == 0) ? null 
            : new TypeListItem(parameters);
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        StringIdsSection stringIds = file.getStringIds();
        TypeIdsSection typeIds = file.getTypeIds();
        MixedItemSection typeLists = file.getTypeLists();

        typeIds.intern(prototype.getReturnType());
        stringIds.intern(shortForm);

        if (parameterTypes != null) {
            parameterTypes = typeLists.intern(parameterTypes);
        }
    
public ItemTypeitemType()
{@inheritDoc}

        return ItemType.TYPE_PROTO_ID_ITEM;
    
private static com.android.dx.rop.cst.CstUtf8makeShortForm(com.android.dx.rop.type.Prototype prototype)
Creates the short-form of the given prototype.

param
prototype non-null; the prototype
return
non-null; the short form

        StdTypeList parameters = prototype.getParameterTypes();
        int size = parameters.size();
        StringBuilder sb = new StringBuilder(size + 1);

        sb.append(shortFormCharFor(prototype.getReturnType()));

        for (int i = 0; i < size; i++) {
            sb.append(shortFormCharFor(parameters.getType(i)));
        }

        return new CstUtf8(sb.toString());
    
private static charshortFormCharFor(com.android.dx.rop.type.Type type)
Gets the short-form character for the given type.

param
type non-null; the type
return
the corresponding short-form character

        char descriptorChar = type.getDescriptor().charAt(0);

        if (descriptorChar == '[") {
            return 'L";
        }

        return descriptorChar;
    
public intwriteSize()
{@inheritDoc}

        return WRITE_SIZE;
    
public voidwriteTo(DexFile file, com.android.dx.util.AnnotatedOutput out)
{@inheritDoc}

        int shortyIdx = file.getStringIds().indexOf(shortForm);
        int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
        int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
            
        if (out.annotates()) {
            StringBuilder sb = new StringBuilder();
            sb.append(prototype.getReturnType().toHuman());
            sb.append(" proto(");

            StdTypeList params = prototype.getParameterTypes();
            int size = params.size();

            for (int i = 0; i < size; i++) {
                if (i != 0) {
                    sb.append(", ");
                }
                sb.append(params.getType(i).toHuman());
            }
            
            sb.append(")");
            out.annotate(0, indexString() + ' " + sb.toString());
            out.annotate(4, "  shorty_idx:      " + Hex.u4(shortyIdx) +
                    " // " + shortForm.toQuoted());
            out.annotate(4, "  return_type_idx: " + Hex.u4(returnIdx) +
                    " // " + prototype.getReturnType().toHuman());
            out.annotate(4, "  parameters_off:  " + Hex.u4(paramsOff));
        }

        out.writeInt(shortyIdx);
        out.writeInt(returnIdx);
        out.writeInt(paramsOff);