FileDocCategorySizeDatePackage
ProtoIdItem.javaAPI DocAndroid 5.1 API5190Thu Mar 12 22:18:30 GMT 2015com.android.dexgen.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.dexgen.rop.type.Prototype
prototype
{@code non-null;} the wrapped prototype
private final com.android.dexgen.rop.cst.CstUtf8
shortForm
{@code non-null;} the short-form of the prototype
private TypeListItem
parameterTypes
{@code null-ok;} the list of parameter types or {@code null} if this prototype has no parameters
Constructors Summary
public ProtoIdItem(com.android.dexgen.rop.type.Prototype prototype)
Constructs an instance.

param
prototype {@code 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.dexgen.rop.cst.CstUtf8makeShortForm(com.android.dexgen.rop.type.Prototype prototype)
Creates the short-form of the given prototype.

param
prototype {@code non-null;} the prototype
return
{@code 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.dexgen.rop.type.Type type)
Gets the short-form character for the given type.

param
type {@code 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.dexgen.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);