FileDocCategorySizeDatePackage
EncodedMethod.javaAPI DocAndroid 1.5 API5929Wed May 06 22:41:02 BST 2009com.android.dx.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.dx.rop.cst.CstMethodRef
method
non-null; constant for the method
private final CodeItem
code
null-ok; code for the method, if the method is neither abstract nor native
Constructors Summary
public EncodedMethod(com.android.dx.rop.cst.CstMethodRef method, int accessFlags, com.android.dx.dex.code.DalvCode code, com.android.dx.rop.type.TypeList throwsList)
Constructs an instance.

param
method non-null; constant for the method
param
accessFlags access flags
param
code null-ok; code for the method, if it is neither abstract nor native
param
throwsList 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.dx.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.dx.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.dx.rop.cst.CstUtf8getName()
{@inheritDoc}

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

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