Search in sources :

Example 1 with FieldIdsSection

use of com.taobao.android.dx.dex.file.FieldIdsSection in project atlas by alibaba.

the class CfTranslator method translate0.

/**
     * 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 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
     * @param optimizerOptions options for the optimizer
     * @return {@code non-null;} the translated class
     */
private static ClassDefItem translate0(DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, OptimizerOptions optimizerOptions, DexFile dexFile) {
    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(cf, cfOptions, dexOptions, optimizerOptions, 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;
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) CstString(com.taobao.android.dx.rop.cst.CstString) CstFieldRef(com.taobao.android.dx.rop.cst.CstFieldRef) CstEnumRef(com.taobao.android.dx.rop.cst.CstEnumRef) FieldIdsSection(com.taobao.android.dx.dex.file.FieldIdsSection) MethodIdsSection(com.taobao.android.dx.dex.file.MethodIdsSection) CstMethodRef(com.taobao.android.dx.rop.cst.CstMethodRef) Annotations(com.taobao.android.dx.rop.annotation.Annotations) ClassDefItem(com.taobao.android.dx.dex.file.ClassDefItem) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstType(com.taobao.android.dx.rop.cst.CstType) CstInterfaceMethodRef(com.taobao.android.dx.rop.cst.CstInterfaceMethodRef)

Example 2 with FieldIdsSection

use of com.taobao.android.dx.dex.file.FieldIdsSection in project atlas by alibaba.

the class CfTranslator method translate0.

/**
 * 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 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(DirectClassFile cf, byte[] bytes, CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {
    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(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;
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) CstString(com.taobao.android.dx.rop.cst.CstString) CstFieldRef(com.taobao.android.dx.rop.cst.CstFieldRef) CstEnumRef(com.taobao.android.dx.rop.cst.CstEnumRef) FieldIdsSection(com.taobao.android.dx.dex.file.FieldIdsSection) MethodIdsSection(com.taobao.android.dx.dex.file.MethodIdsSection) CstMethodRef(com.taobao.android.dx.rop.cst.CstMethodRef) Annotations(com.taobao.android.dx.rop.annotation.Annotations) ClassDefItem(com.taobao.android.dx.dex.file.ClassDefItem) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstType(com.taobao.android.dx.rop.cst.CstType) CstInterfaceMethodRef(com.taobao.android.dx.rop.cst.CstInterfaceMethodRef)

Aggregations

ClassDefItem (com.taobao.android.dx.dex.file.ClassDefItem)2 FieldIdsSection (com.taobao.android.dx.dex.file.FieldIdsSection)2 MethodIdsSection (com.taobao.android.dx.dex.file.MethodIdsSection)2 Annotations (com.taobao.android.dx.rop.annotation.Annotations)2 Constant (com.taobao.android.dx.rop.cst.Constant)2 ConstantPool (com.taobao.android.dx.rop.cst.ConstantPool)2 CstEnumRef (com.taobao.android.dx.rop.cst.CstEnumRef)2 CstFieldRef (com.taobao.android.dx.rop.cst.CstFieldRef)2 CstInterfaceMethodRef (com.taobao.android.dx.rop.cst.CstInterfaceMethodRef)2 CstMethodRef (com.taobao.android.dx.rop.cst.CstMethodRef)2 CstString (com.taobao.android.dx.rop.cst.CstString)2 CstType (com.taobao.android.dx.rop.cst.CstType)2 TypedConstant (com.taobao.android.dx.rop.cst.TypedConstant)2