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

EncodedMethod

public final class EncodedMethod extends EncodedMember implements Comparable
Class that representats a method of a class.

Fields Summary
private final com.android.dexgen.rop.cst.CstMethodRef
method
{@code non-null;} constant for the method
private final CodeItem
code
{@code null-ok;} code for the method, if the method is neither {@code abstract} nor {@code native}
Constructors Summary
public EncodedMethod(com.android.dexgen.rop.cst.CstMethodRef method, int accessFlags, com.android.dexgen.dex.code.DalvCode code, com.android.dexgen.rop.type.TypeList throwsList)
Constructs an instance.

param
method {@code non-null;} constant for the method
param
accessFlags access flags
param
code {@code null-ok;} code for the method, if it is neither {@code abstract} nor {@code native}
param
throwsList {@code non-null;} list of possibly-thrown exceptions, just used in generating debugging output (listings)

        super(accessFlags);

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

        this.method = method;

        if (code == null) {
            this.code = null;
        } else {
            boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
            this.code = new CodeItem(method, code, isStatic, throwsList);
        }
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

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

        methodIds.intern(method);

        if (code != null) {
            wordData.add(code);
        }
    
public intcompareTo(com.android.dexgen.dex.file.EncodedMethod other)
{@inheritDoc}

Note: This compares the method constants only, ignoring any associated code, because it should never be the case that two different items with the same method constant ever appear in the same list (or same file, even).

        return method.compareTo(other.method);
    
public voiddebugPrint(java.io.PrintWriter out, boolean verbose)
{@inheritDoc}

        if (code == null) {
            out.println(getRef().toHuman() + ": abstract or native");
        } else {
            code.debugPrint(out, "  ", verbose);
        }
    
public intencode(DexFile file, com.android.dexgen.util.AnnotatedOutput out, int lastIndex, int dumpSeq)
{@inheritDoc}

        int methodIdx = file.getMethodIds().indexOf(method);
        int diff = methodIdx - lastIndex;
        int accessFlags = getAccessFlags();
        int codeOff = OffsettedItem.getAbsoluteOffsetOr0(code);
        boolean hasCode = (codeOff != 0);
        boolean shouldHaveCode = (accessFlags &
                (AccessFlags.ACC_ABSTRACT | AccessFlags.ACC_NATIVE)) == 0;

        /*
         * Verify that code appears if and only if a method is
         * declared to have it.
         */
        if (hasCode != shouldHaveCode) {
            throw new UnsupportedOperationException(
                    "code vs. access_flags mismatch");
        }

        if (out.annotates()) {
            out.annotate(0, String.format("  [%x] %s", dumpSeq,
                            method.toHuman()));
            out.annotate(Leb128Utils.unsignedLeb128Size(diff),
                    "    method_idx:   " + Hex.u4(methodIdx));
            out.annotate(Leb128Utils.unsignedLeb128Size(accessFlags),
                    "    access_flags: " +
                    AccessFlags.methodString(accessFlags));
            out.annotate(Leb128Utils.unsignedLeb128Size(codeOff),
                    "    code_off:     " + Hex.u4(codeOff));
        }

        out.writeUnsignedLeb128(diff);
        out.writeUnsignedLeb128(accessFlags);
        out.writeUnsignedLeb128(codeOff);

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

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

        return compareTo((EncodedMethod) other) == 0;
    
public final com.android.dexgen.rop.cst.CstUtf8getName()
{@inheritDoc}

        return method.getNat().getName();
    
public final com.android.dexgen.rop.cst.CstMethodRefgetRef()
Gets the constant for the method.

return
{@code non-null;} the constant

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

        return method.toHuman();
    
public java.lang.StringtoString()
{@inheritDoc}

        StringBuffer sb = new StringBuffer(100);

        sb.append(getClass().getName());
        sb.append('{");
        sb.append(Hex.u2(getAccessFlags()));
        sb.append(' ");
        sb.append(method);

        if (code != null) {
            sb.append(' ");
            sb.append(code);
        }

        sb.append('}");

        return sb.toString();