FileDocCategorySizeDatePackage
ConcreteMethod.javaAPI DocAndroid 5.1 API8324Thu Mar 12 22:18:30 GMT 2015com.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 Code} attribute.

Fields Summary
private final com.android.dx.cf.iface.Method
method
{@code non-null;} method being wrapped
private final com.android.dx.rop.cst.CstString
sourceFile
{@code null-ok;} the class's {@code SourceFile} attribute value, if any
private final boolean
accSuper
whether the class that this method is part of is defined with {@code ACC_SUPER}
private final com.android.dx.cf.attrib.AttCode
attCode
{@code non-null;} the code attribute
private final LineNumberList
lineNumbers
{@code non-null;} line number list
private final LocalVariableList
localVariables
{@code 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 {@code non-null;} the method to be based on
param
cf {@code 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, cf.getAccessFlags(), cf.getSourceFile(), keepLines, keepLocals);
    
public ConcreteMethod(com.android.dx.cf.iface.Method method, int accessFlags, com.android.dx.rop.cst.CstString sourceFile, boolean keepLines, boolean keepLocals)

        this.method = method;
        this.accSuper = (accessFlags & AccessFlags.ACC_SUPER) != 0;
        this.sourceFile = sourceFile;

        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 {@code ACC_SUPER}.

return
the {@code 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
{@code non-null;} the exception table

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

return
{@code 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.CstStringgetDescriptor()
{@inheritDoc}

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

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

return
{@code non-null;} the line number list

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

return
{@code non-null;} the local variable list

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

return
{@code >= 0;} the number of locals

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

return
{@code >= 0;} the maximum stack size

        return attCode.getMaxStack();
    
public com.android.dx.rop.cst.CstStringgetName()
{@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 {@code >= 0;} the bytecode offset
return
{@code non-null;} an appropriate instance

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