com.android.dx.cf.iface.ClassFile Java Examples

The following examples show how to use com.android.dx.cf.iface.ClassFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConcreteMethod.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} the method to be based on
 * @param classFile {@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)
 */
public ConcreteMethod(Method method, ClassFile classFile,
        boolean keepLines, boolean keepLocals) {
    this.method = method;
    this.classFile = classFile;

    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 lnl = LineNumberList.EMPTY;
    if (keepLines) {
        for (AttLineNumberTable lnt = (AttLineNumberTable)
                 codeAttribs.findFirst(AttLineNumberTable.ATTRIBUTE_NAME);
             lnt != null;
             lnt = (AttLineNumberTable) codeAttribs.findNext(lnt)) {
            lnl = LineNumberList.concat(lnl, lnt.getLineNumbers());
        }
    }
    this.lineNumbers = lnl;

    LocalVariableList lvl = 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)) {

            lvl = LocalVariableList.concat(lvl, 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) {

            lvl = LocalVariableList.mergeDescriptorsAndSignatures(lvl, typeList);
        }
    }
    this.localVariables = lvl;
}
 
Example #2
Source File: ConcreteMethod.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} the method to be based on
 * @param classFile {@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)
 */
public ConcreteMethod(Method method, ClassFile classFile,
        boolean keepLines, boolean keepLocals) {
    this.method = method;
    this.classFile = classFile;

    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 lnl = LineNumberList.EMPTY;
    if (keepLines) {
        for (AttLineNumberTable lnt = (AttLineNumberTable)
                 codeAttribs.findFirst(AttLineNumberTable.ATTRIBUTE_NAME);
             lnt != null;
             lnt = (AttLineNumberTable) codeAttribs.findNext(lnt)) {
            lnl = LineNumberList.concat(lnl, lnt.getLineNumbers());
        }
    }
    this.lineNumbers = lnl;

    LocalVariableList lvl = 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)) {

            lvl = LocalVariableList.concat(lvl, 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) {

            lvl = LocalVariableList.mergeDescriptorsAndSignatures(lvl, typeList);
        }
    }
    this.localVariables = lvl;
}
 
Example #3
Source File: ConcreteMethod.java    From J2ME-Loader with Apache License 2.0 2 votes vote down vote up
/**
 * 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)
 */
public ConcreteMethod(Method method, ClassFile cf, boolean keepLines, boolean keepLocals) {
    this(method, cf.getSourceFile(), keepLines, keepLocals);
}
 
Example #4
Source File: ConcreteMethod.java    From buck with Apache License 2.0 2 votes vote down vote up
/**
 * 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)
 */
public ConcreteMethod(Method method, ClassFile cf, boolean keepLines, boolean keepLocals) {
    this(method, cf.getAccessFlags(), cf.getSourceFile(), keepLines, keepLocals);
}