FileDocCategorySizeDatePackage
ConcreteMethod.javaAPI DocAndroid 1.5 API8104Wed May 06 22:41:02 BST 2009com.android.dx.cf.code

ConcreteMethod

public final class ConcreteMethod extends Object implements com.android.dx.cf.iface.Method
Container for all the giblets that make up a concrete Java bytecode method. It implements {@link Method}, so it provides all the original access (by delegation), but it also constructs and keeps useful versions of stuff extracted from the method's Code attribute.

Fields Summary
private final com.android.dx.cf.iface.Method
method
non-null; method being wrapped
private final com.android.dx.rop.cst.CstUtf8
sourceFile
null-ok; the class's SourceFile attribute value, if any
private final boolean
accSuper
whether the class that this method is part of is defined with ACC_SUPER
private final com.android.dx.cf.attrib.AttCode
attCode
non-null; the code attribute
private final LineNumberList
lineNumbers
non-null; line number list
private final LocalVariableList
localVariables
non-null; local variable list
Constructors Summary
public ConcreteMethod(com.android.dx.cf.iface.Method method, com.android.dx.cf.iface.ClassFile cf, boolean keepLines, boolean keepLocals)
Constructs an instance.

param
method non-null; the method to be based on
param
cf non-null; the class file that contains this method
param
keepLines whether to keep the line number information (if any)
param
keepLocals whether to keep the local variable information (if any)

        this.method = method;
        this.accSuper = (cf.getAccessFlags() & AccessFlags.ACC_SUPER) != 0;
        this.sourceFile = cf.getSourceFile();

        AttributeList attribs = method.getAttributes();
        this.attCode = (AttCode) attribs.findFirst(AttCode.ATTRIBUTE_NAME);

        AttributeList codeAttribs = attCode.getAttributes();

        /*
         * Combine all LineNumberTable attributes into one, with the
         * combined result saved into the instance. The following code
         * isn't particularly efficient for doing merges, but as far
         * as I know, this situation rarely occurs "in the
         * wild," so there's not much point in optimizing for it.
         */
        LineNumberList lineNumbers = LineNumberList.EMPTY;
        if (keepLines) {
            for (AttLineNumberTable lnt = (AttLineNumberTable)
                     codeAttribs.findFirst(AttLineNumberTable.ATTRIBUTE_NAME);
                 lnt != null;
                 lnt = (AttLineNumberTable) codeAttribs.findNext(lnt)) {
                lineNumbers = LineNumberList.concat(lineNumbers,
                        lnt.getLineNumbers());
            }
        }
        this.lineNumbers = lineNumbers;

        LocalVariableList localVariables = LocalVariableList.EMPTY;
        if (keepLocals) {
            /*
             * Do likewise (and with the same caveat) for
             * LocalVariableTable and LocalVariableTypeTable attributes.
             * This combines both of these kinds of attribute into a
             * single LocalVariableList.
             */
            for (AttLocalVariableTable lvt = (AttLocalVariableTable)
                     codeAttribs.findFirst(
                             AttLocalVariableTable.ATTRIBUTE_NAME);
                 lvt != null;
                 lvt = (AttLocalVariableTable) codeAttribs.findNext(lvt)) {
                localVariables =
                    LocalVariableList.concat(localVariables,
                            lvt.getLocalVariables());
            }

            LocalVariableList typeList = LocalVariableList.EMPTY;
            for (AttLocalVariableTypeTable lvtt = (AttLocalVariableTypeTable)
                     codeAttribs.findFirst(
                             AttLocalVariableTypeTable.ATTRIBUTE_NAME);
                 lvtt != null;
                 lvtt =
                     (AttLocalVariableTypeTable) codeAttribs.findNext(lvtt)) {
                typeList =
                    LocalVariableList.concat(typeList,
                            lvtt.getLocalVariables());
            }

            if (typeList.size() != 0) {
                localVariables =
                    LocalVariableList.mergeDescriptorsAndSignatures(
                            localVariables, typeList);
            }
        }
        this.localVariables = localVariables;
    
Methods Summary
public booleangetAccSuper()
Gets whether the class that this method is part of is defined with ACC_SUPER.

return
the ACC_SUPER value

        return accSuper;
    
public intgetAccessFlags()
{@inheritDoc}

        return method.getAccessFlags();
    
public com.android.dx.cf.iface.AttributeListgetAttributes()
{@inheritDoc}

        return method.getAttributes();
    
public ByteCatchListgetCatches()
Gets the exception table.

return
non-null; the exception table

        return attCode.getCatches();
    
public BytecodeArraygetCode()
Gets the bytecode array.

return
non-null; the bytecode array

        return attCode.getCode();
    
public com.android.dx.rop.cst.CstTypegetDefiningClass()
{@inheritDoc}

        return method.getDefiningClass();
    
public com.android.dx.rop.cst.CstUtf8getDescriptor()
{@inheritDoc}

        return method.getDescriptor();
    
public com.android.dx.rop.type.PrototypegetEffectiveDescriptor()
{@inheritDoc}

        return method.getEffectiveDescriptor();
    
public LineNumberListgetLineNumbers()
Gets the line number list.

return
non-null; the line number list

        return lineNumbers;
    
public LocalVariableListgetLocalVariables()
Gets the local variable list.

return
non-null; the local variable list

        return localVariables;
    
public intgetMaxLocals()
Gets the number of locals.

return
>= 0; the number of locals

        return attCode.getMaxLocals();
    
public intgetMaxStack()
Gets the maximum stack size.

return
>= 0; the maximum stack size

        return attCode.getMaxStack();
    
public com.android.dx.rop.cst.CstUtf8getName()
{@inheritDoc}

        return method.getName();
    
public com.android.dx.rop.cst.CstNatgetNat()
{@inheritDoc}

        return method.getNat();
    
public com.android.dx.rop.code.SourcePositionmakeSourcePosistion(int offset)
Returns a {@link SourcePosition} instance corresponding to the given bytecode offset.

param
offset >= 0; the bytecode offset
return
non-null; an appropriate instance

        return new SourcePosition(sourceFile, offset,
                                  lineNumbers.pcToLine(offset));