Java Code Examples for com.android.dx.rop.code.AccessFlags#ACC_SUPER

The following examples show how to use com.android.dx.rop.code.AccessFlags#ACC_SUPER . 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: AccessInfo.java    From Box with Apache License 2.0 4 votes vote down vote up
public String makeString() {
	StringBuilder code = new StringBuilder();
	if (isPublic()) {
		code.append("public ");
	}
	if (isPrivate()) {
		code.append("private ");
	}
	if (isProtected()) {
		code.append("protected ");
	}
	if (isStatic()) {
		code.append("static ");
	}
	if (isFinal()) {
		code.append("final ");
	}
	if (isAbstract()) {
		code.append("abstract ");
	}
	if (isNative()) {
		code.append("native ");
	}
	switch (type) {
		case METHOD:
			if (isSynchronized()) {
				code.append("synchronized ");
			}
			if (isBridge()) {
				code.append("/* bridge */ ");
			}
			if (Consts.DEBUG && isVarArgs()) {
				code.append("/* varargs */ ");
			}
			break;

		case FIELD:
			if (isVolatile()) {
				code.append("volatile ");
			}
			if (isTransient()) {
				code.append("transient ");
			}
			break;

		case CLASS:
			if ((accFlags & AccessFlags.ACC_STRICT) != 0) {
				code.append("strict ");
			}
			if (Consts.DEBUG) {
				if ((accFlags & AccessFlags.ACC_SUPER) != 0) {
					code.append("/* super */ ");
				}
				if ((accFlags & AccessFlags.ACC_ENUM) != 0) {
					code.append("/* enum */ ");
				}
			}
			break;
	}
	if (isSynthetic()) {
		code.append("/* synthetic */ ");
	}
	return code.toString();
}
 
Example 2
Source File: CfTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context {@code non-null;} the state global to this invocation.
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
        CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    MethodHandlesSection methodHandlesSection = dexFile.getMethodHandles();
    CallSiteIdsSection callSiteIds = dexFile.getCallSiteIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        } else if (constant instanceof CstMethodHandle) {
            methodHandlesSection.intern((CstMethodHandle) constant);
        } else if (constant instanceof CstInvokeDynamic) {
            CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) constant;
            int index = cstInvokeDynamic.getBootstrapMethodIndex();
            BootstrapMethodsList.Item bootstrapMethod = cf.getBootstrapMethods().get(index);
            CstCallSite callSite =
                    CstCallSite.make(bootstrapMethod.getBootstrapMethodHandle(),
                                     cstInvokeDynamic.getNat(),
                                     bootstrapMethod.getBootstrapMethodArguments());
            cstInvokeDynamic.setDeclaringClass(cf.getThisClass());
            cstInvokeDynamic.setCallSite(callSite);
            for (CstCallSiteRef ref : cstInvokeDynamic.getReferences()) {
                callSiteIds.intern(ref);
            }
        }
    }

    return out;
}
 
Example 3
Source File: AccessInfo.java    From Box with Apache License 2.0 4 votes vote down vote up
public String makeString() {
	StringBuilder code = new StringBuilder();
	if (isPublic()) {
		code.append("public ");
	}
	if (isPrivate()) {
		code.append("private ");
	}
	if (isProtected()) {
		code.append("protected ");
	}
	if (isStatic()) {
		code.append("static ");
	}
	if (isFinal()) {
		code.append("final ");
	}
	if (isAbstract()) {
		code.append("abstract ");
	}
	if (isNative()) {
		code.append("native ");
	}
	switch (type) {
		case METHOD:
			if (isSynchronized()) {
				code.append("synchronized ");
			}
			if (isBridge()) {
				code.append("/* bridge */ ");
			}
			if (Consts.DEBUG && isVarArgs()) {
				code.append("/* varargs */ ");
			}
			break;

		case FIELD:
			if (isVolatile()) {
				code.append("volatile ");
			}
			if (isTransient()) {
				code.append("transient ");
			}
			break;

		case CLASS:
			if ((accFlags & AccessFlags.ACC_STRICT) != 0) {
				code.append("strict ");
			}
			if (Consts.DEBUG) {
				if ((accFlags & AccessFlags.ACC_SUPER) != 0) {
					code.append("/* super */ ");
				}
				if ((accFlags & AccessFlags.ACC_ENUM) != 0) {
					code.append("/* enum */ ");
				}
			}
			break;
	}
	if (isSynthetic()) {
		code.append("/* synthetic */ ");
	}
	return code.toString();
}
 
Example 4
Source File: CfTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context {@code non-null;} the state global to this invocation.
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
        CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    MethodHandlesSection methodHandlesSection = dexFile.getMethodHandles();
    CallSiteIdsSection callSiteIds = dexFile.getCallSiteIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        } else if (constant instanceof CstMethodHandle) {
            methodHandlesSection.intern((CstMethodHandle) constant);
        } else if (constant instanceof CstInvokeDynamic) {
            CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) constant;
            int index = cstInvokeDynamic.getBootstrapMethodIndex();
            BootstrapMethodsList.Item bootstrapMethod = cf.getBootstrapMethods().get(index);
            CstCallSite callSite =
                    CstCallSite.make(bootstrapMethod.getBootstrapMethodHandle(),
                                     cstInvokeDynamic.getNat(),
                                     bootstrapMethod.getBootstrapMethodArguments());
            cstInvokeDynamic.setDeclaringClass(cf.getThisClass());
            cstInvokeDynamic.setCallSite(callSite);
            for (CstCallSiteRef ref : cstInvokeDynamic.getReferences()) {
                callSiteIds.intern(ref);
            }
        }
    }

    return out;
}
 
Example 5
Source File: CfTranslator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context {@code non-null;} the state global to this invocation.
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
        CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        }
    }

    return out;
}
 
Example 6
Source File: CfTranslator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
                                       CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        }
    }

    return out;
}
 
Example 7
Source File: ConcreteMethod.java    From buck with Apache License 2.0 4 votes vote down vote up
public ConcreteMethod(Method method, int accessFlags, 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;
}