FileDocCategorySizeDatePackage
ParameterAnnotationStruct.javaAPI DocAndroid 5.1 API4971Thu Mar 12 22:18:30 GMT 2015com.android.dexgen.dex.file

ParameterAnnotationStruct

public final class ParameterAnnotationStruct extends Object implements com.android.dexgen.util.ToHuman, Comparable
Association of a method and its parameter annotations.

Fields Summary
private final com.android.dexgen.rop.cst.CstMethodRef
method
{@code non-null;} the method in question
private final com.android.dexgen.rop.annotation.AnnotationsList
annotationsList
{@code non-null;} the associated annotations list
private final UniformListItem
annotationsItem
{@code non-null;} the associated annotations list, as an item
Constructors Summary
public ParameterAnnotationStruct(com.android.dexgen.rop.cst.CstMethodRef method, com.android.dexgen.rop.annotation.AnnotationsList annotationsList)
Constructs an instance.

param
method {@code non-null;} the method in question
param
annotationsList {@code non-null;} the associated annotations list

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

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

        this.method = method;
        this.annotationsList = annotationsList;

        /*
         * Construct an item for the annotations list. TODO: This
         * requires way too much copying; fix it.
         */

        int size = annotationsList.size();
        ArrayList<AnnotationSetRefItem> arrayList = new
            ArrayList<AnnotationSetRefItem>(size);

        for (int i = 0; i < size; i++) {
            Annotations annotations = annotationsList.get(i);
            AnnotationSetItem item = new AnnotationSetItem(annotations);
            arrayList.add(new AnnotationSetRefItem(item));
        }

        this.annotationsItem = new UniformListItem<AnnotationSetRefItem>(
                ItemType.TYPE_ANNOTATION_SET_REF_LIST, arrayList);
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        MethodIdsSection methodIds = file.getMethodIds();
        MixedItemSection wordData = file.getWordData();

        methodIds.intern(method);
        wordData.add(annotationsItem);
    
public intcompareTo(com.android.dexgen.dex.file.ParameterAnnotationStruct other)
{@inheritDoc}

        return method.compareTo(other.method);
    
public booleanequals(java.lang.Object other)
{@inheritDoc}

        if (! (other instanceof ParameterAnnotationStruct)) {
            return false;
        }

        return method.equals(((ParameterAnnotationStruct) other).method);
    
public com.android.dexgen.rop.annotation.AnnotationsListgetAnnotationsList()
Gets the associated annotations list.

return
{@code non-null;} the annotations list

        return annotationsList;
    
public com.android.dexgen.rop.cst.CstMethodRefgetMethod()
Gets the method this item is for.

return
{@code non-null;} the method

        return method;
    
public inthashCode()
{@inheritDoc}

        return method.hashCode();
    
public java.lang.StringtoHuman()
{@inheritDoc}

        StringBuilder sb = new StringBuilder();

        sb.append(method.toHuman());
        sb.append(": ");

        boolean first = true;
        for (AnnotationSetRefItem item : annotationsItem.getItems()) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append(item.toHuman());
        }

        return sb.toString();
    
public voidwriteTo(DexFile file, com.android.dexgen.util.AnnotatedOutput out)
{@inheritDoc}

        int methodIdx = file.getMethodIds().indexOf(method);
        int annotationsOff = annotationsItem.getAbsoluteOffset();

        if (out.annotates()) {
            out.annotate(0, "    " + method.toHuman());
            out.annotate(4, "      method_idx:      " + Hex.u4(methodIdx));
            out.annotate(4, "      annotations_off: " +
                    Hex.u4(annotationsOff));
        }

        out.writeInt(methodIdx);
        out.writeInt(annotationsOff);