com.android.dx.rop.cst.CstEnumRef Java Examples

The following examples show how to use com.android.dx.rop.cst.CstEnumRef. 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: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        protoIds.intern(((CstProtoRef) cst).getPrototype());
    } else if (cst instanceof CstMethodHandle) {
        methodHandles.intern((CstMethodHandle) cst);
    }
}
 
Example #2
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstEnumRef) {
        return fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else if (cst instanceof CstMethodHandle) {
        return methodHandles.get(cst);
    } else if (cst instanceof CstCallSiteRef) {
        return callSiteIds.get(cst);
    } else {
        return null;
    }
}
 
Example #3
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        protoIds.intern(((CstProtoRef) cst).getPrototype());
    } else if (cst instanceof CstMethodHandle) {
        methodHandles.intern((CstMethodHandle) cst);
    }
}
 
Example #4
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstEnumRef) {
        return fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else if (cst instanceof CstMethodHandle) {
        return methodHandles.get(cst);
    } else if (cst instanceof CstCallSiteRef) {
        return callSiteIds.get(cst);
    } else {
        return null;
    }
}
 
Example #5
Source File: AnnotationId.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Convert a value of an element to a {@code Constant}.
 * <p><strong>Warning:</strong> Array or TypeId value is not supported yet.
 *
 * @param value an annotation element value.
 * @return a Constant
 */
static Constant toConstant(Object value) {
    Class clazz = value.getClass();
    if (clazz.isEnum()) {
        CstString descriptor = new CstString(TypeId.get(clazz).getName());
        CstString name = new CstString(((Enum) value).name());
        CstNat cstNat = new CstNat(name, descriptor);
        return new CstEnumRef(cstNat);
    } else if (clazz.isArray()) {
        throw new UnsupportedOperationException("Array is not supported yet");
    } else if (value instanceof TypeId) {
        throw new UnsupportedOperationException("TypeId is not supported yet");
    } else {
        return Constants.getConstant(value);
    }
}
 
Example #6
Source File: DexFile.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst == null) {
        throw new NullPointerException("cst == null");
    }
}
 
Example #7
Source File: DexFile.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst == null) {
        throw new NullPointerException("cst == null");
    }
}
 
Example #8
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 #9
Source File: ValueEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value type for the given constant.
 *
 * @param cst {@code non-null;} the constant
 * @return the value type; one of the {@code VALUE_*} constants
 * defined by this class
 */
private static int constantToValueType(Constant cst) {
    /*
     * TODO: Constant should probable have an associated enum, so this
     * can be a switch().
     */
    if (cst instanceof CstByte) {
        return VALUE_BYTE;
    } else if (cst instanceof CstShort) {
        return VALUE_SHORT;
    } else if (cst instanceof CstChar) {
        return VALUE_CHAR;
    } else if (cst instanceof CstInteger) {
        return VALUE_INT;
    } else if (cst instanceof CstLong) {
        return VALUE_LONG;
    } else if (cst instanceof CstFloat) {
        return VALUE_FLOAT;
    } else if (cst instanceof CstDouble) {
        return VALUE_DOUBLE;
    } else if (cst instanceof CstProtoRef) {
        return VALUE_METHOD_TYPE;
    } else if (cst instanceof CstMethodHandle) {
       return VALUE_METHOD_HANDLE;
    } else if (cst instanceof CstString) {
        return VALUE_STRING;
    } else if (cst instanceof CstType) {
        return VALUE_TYPE;
    } else if (cst instanceof CstFieldRef) {
        return VALUE_FIELD;
    } else if (cst instanceof CstMethodRef) {
        return VALUE_METHOD;
    } else if (cst instanceof CstEnumRef) {
        return VALUE_ENUM;
    } else if (cst instanceof CstArray) {
        return VALUE_ARRAY;
    } else if (cst instanceof CstAnnotation) {
        return VALUE_ANNOTATION;
    } else if (cst instanceof CstKnownNull) {
        return VALUE_NULL;
    } else if (cst instanceof CstBoolean) {
        return VALUE_BOOLEAN;
    } else {
        throw new RuntimeException("Shouldn't happen");
    }
}
 
Example #10
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 #11
Source File: ValueEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value type for the given constant.
 *
 * @param cst {@code non-null;} the constant
 * @return the value type; one of the {@code VALUE_*} constants
 * defined by this class
 */
private static int constantToValueType(Constant cst) {
    /*
     * TODO: Constant should probable have an associated enum, so this
     * can be a switch().
     */
    if (cst instanceof CstByte) {
        return VALUE_BYTE;
    } else if (cst instanceof CstShort) {
        return VALUE_SHORT;
    } else if (cst instanceof CstChar) {
        return VALUE_CHAR;
    } else if (cst instanceof CstInteger) {
        return VALUE_INT;
    } else if (cst instanceof CstLong) {
        return VALUE_LONG;
    } else if (cst instanceof CstFloat) {
        return VALUE_FLOAT;
    } else if (cst instanceof CstDouble) {
        return VALUE_DOUBLE;
    } else if (cst instanceof CstProtoRef) {
        return VALUE_METHOD_TYPE;
    } else if (cst instanceof CstMethodHandle) {
       return VALUE_METHOD_HANDLE;
    } else if (cst instanceof CstString) {
        return VALUE_STRING;
    } else if (cst instanceof CstType) {
        return VALUE_TYPE;
    } else if (cst instanceof CstFieldRef) {
        return VALUE_FIELD;
    } else if (cst instanceof CstMethodRef) {
        return VALUE_METHOD;
    } else if (cst instanceof CstEnumRef) {
        return VALUE_ENUM;
    } else if (cst instanceof CstArray) {
        return VALUE_ARRAY;
    } else if (cst instanceof CstAnnotation) {
        return VALUE_ANNOTATION;
    } else if (cst instanceof CstKnownNull) {
        return VALUE_NULL;
    } else if (cst instanceof CstBoolean) {
        return VALUE_BOOLEAN;
    } else {
        throw new RuntimeException("Shouldn't happen");
    }
}
 
Example #12
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 #13
Source File: ValueEncoder.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value type for the given constant.
 *
 * @param cst {@code non-null;} the constant
 * @return the value type; one of the {@code VALUE_*} constants
 * defined by this class
 */
private static int constantToValueType(Constant cst) {
    /*
     * TODO: Constant should probable have an associated enum, so this
     * can be a switch().
     */
    if (cst instanceof CstByte) {
        return VALUE_BYTE;
    } else if (cst instanceof CstShort) {
        return VALUE_SHORT;
    } else if (cst instanceof CstChar) {
        return VALUE_CHAR;
    } else if (cst instanceof CstInteger) {
        return VALUE_INT;
    } else if (cst instanceof CstLong) {
        return VALUE_LONG;
    } else if (cst instanceof CstFloat) {
        return VALUE_FLOAT;
    } else if (cst instanceof CstDouble) {
        return VALUE_DOUBLE;
    } else if (cst instanceof CstString) {
        return VALUE_STRING;
    } else if (cst instanceof CstType) {
        return VALUE_TYPE;
    } else if (cst instanceof CstFieldRef) {
        return VALUE_FIELD;
    } else if (cst instanceof CstMethodRef) {
        return VALUE_METHOD;
    } else if (cst instanceof CstEnumRef) {
        return VALUE_ENUM;
    } else if (cst instanceof CstArray) {
        return VALUE_ARRAY;
    } else if (cst instanceof CstAnnotation) {
        return VALUE_ANNOTATION;
    } else if (cst instanceof CstKnownNull) {
        return VALUE_NULL;
    } else if (cst instanceof CstBoolean) {
        return VALUE_BOOLEAN;
    } else {
        throw new RuntimeException("Shouldn't happen");
    }
}
 
Example #14
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 #15
Source File: ValueEncoder.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value type for the given constant.
 *
 * @param cst {@code non-null;} the constant
 * @return the value type; one of the {@code VALUE_*} constants
 * defined by this class
 */
private static int constantToValueType(Constant cst) {
    /*
     * TODO: Constant should probable have an associated enum, so this
     * can be a switch().
     */
    if (cst instanceof CstByte) {
        return VALUE_BYTE;
    } else if (cst instanceof CstShort) {
        return VALUE_SHORT;
    } else if (cst instanceof CstChar) {
        return VALUE_CHAR;
    } else if (cst instanceof CstInteger) {
        return VALUE_INT;
    } else if (cst instanceof CstLong) {
        return VALUE_LONG;
    } else if (cst instanceof CstFloat) {
        return VALUE_FLOAT;
    } else if (cst instanceof CstDouble) {
        return VALUE_DOUBLE;
    } else if (cst instanceof CstString) {
        return VALUE_STRING;
    } else if (cst instanceof CstType) {
        return VALUE_TYPE;
    } else if (cst instanceof CstFieldRef) {
        return VALUE_FIELD;
    } else if (cst instanceof CstMethodRef) {
        return VALUE_METHOD;
    } else if (cst instanceof CstEnumRef) {
        return VALUE_ENUM;
    } else if (cst instanceof CstArray) {
        return VALUE_ARRAY;
    } else if (cst instanceof CstAnnotation) {
        return VALUE_ANNOTATION;
    } else if (cst instanceof CstKnownNull) {
        return VALUE_NULL;
    } else if (cst instanceof CstBoolean) {
        return VALUE_BOOLEAN;
    } else {
        throw new RuntimeException("Shouldn't happen");
    }
}