Search in sources :

Example 1 with FieldList

use of com.android.dx.cf.iface.FieldList in project buck by facebook.

the class CfTranslator method processFields.

/**
     * Processes the fields of the given class.
     *
     * @param cf {@code non-null;} class being translated
     * @param out {@code non-null;} output class
     * @param dexFile {@code non-null;} dex output
     */
private static void processFields(DirectClassFile cf, ClassDefItem out, DexFile dexFile) {
    CstType thisClass = cf.getThisClass();
    FieldList fields = cf.getFields();
    int sz = fields.size();
    for (int i = 0; i < sz; i++) {
        Field one = fields.get(i);
        try {
            CstFieldRef field = new CstFieldRef(thisClass, one.getNat());
            int accessFlags = one.getAccessFlags();
            if (AccessFlags.isStatic(accessFlags)) {
                TypedConstant constVal = one.getConstantValue();
                EncodedField fi = new EncodedField(field, accessFlags);
                if (constVal != null) {
                    constVal = coerceConstant(constVal, field.getType());
                }
                out.addStaticField(fi, constVal);
            } else {
                EncodedField fi = new EncodedField(field, accessFlags);
                out.addInstanceField(fi);
            }
            Annotations annotations = AttributeTranslator.getAnnotations(one.getAttributes());
            if (annotations.size() != 0) {
                out.addFieldAnnotations(field, annotations, dexFile);
            }
            dexFile.getFieldIds().intern(field);
        } catch (RuntimeException ex) {
            String msg = "...while processing " + one.getName().toHuman() + " " + one.getDescriptor().toHuman();
            throw ExceptionWithContext.withContext(ex, msg);
        }
    }
}
Also used : Field(com.android.dx.cf.iface.Field) EncodedField(com.android.dx.dex.file.EncodedField) Annotations(com.android.dx.rop.annotation.Annotations) TypedConstant(com.android.dx.rop.cst.TypedConstant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) EncodedField(com.android.dx.dex.file.EncodedField) CstString(com.android.dx.rop.cst.CstString) FieldList(com.android.dx.cf.iface.FieldList)

Example 2 with FieldList

use of com.android.dx.cf.iface.FieldList in project RocooFix by dodola.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }
    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
        checkDescriptor(fields.get(i).getDescriptor().getString());
    }
    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
        checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
Also used : CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) MethodList(com.android.dx.cf.iface.MethodList) FieldList(com.android.dx.cf.iface.FieldList)

Example 3 with FieldList

use of com.android.dx.cf.iface.FieldList in project AndroidLife by CaMnter.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }
    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
        checkDescriptor(fields.get(i).getDescriptor().getString());
    }
    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
        checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
Also used : CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) MethodList(com.android.dx.cf.iface.MethodList) FieldList(com.android.dx.cf.iface.FieldList)

Example 4 with FieldList

use of com.android.dx.cf.iface.FieldList in project J2ME-Loader by nikita36078.

the class CfTranslator method processFields.

/**
 * Processes the fields of the given class.
 *
 * @param cf {@code non-null;} class being translated
 * @param out {@code non-null;} output class
 * @param dexFile {@code non-null;} dex output
 */
private static void processFields(DirectClassFile cf, ClassDefItem out, DexFile dexFile) {
    CstType thisClass = cf.getThisClass();
    FieldList fields = cf.getFields();
    int sz = fields.size();
    for (int i = 0; i < sz; i++) {
        Field one = fields.get(i);
        try {
            CstFieldRef field = new CstFieldRef(thisClass, one.getNat());
            int accessFlags = one.getAccessFlags();
            if (AccessFlags.isStatic(accessFlags)) {
                TypedConstant constVal = one.getConstantValue();
                EncodedField fi = new EncodedField(field, accessFlags);
                if (constVal != null) {
                    constVal = coerceConstant(constVal, field.getType());
                }
                out.addStaticField(fi, constVal);
            } else {
                EncodedField fi = new EncodedField(field, accessFlags);
                out.addInstanceField(fi);
            }
            Annotations annotations = AttributeTranslator.getAnnotations(one.getAttributes());
            if (annotations.size() != 0) {
                out.addFieldAnnotations(field, annotations, dexFile);
            }
            dexFile.getFieldIds().intern(field);
        } catch (RuntimeException ex) {
            String msg = "...while processing " + one.getName().toHuman() + " " + one.getDescriptor().toHuman();
            throw ExceptionWithContext.withContext(ex, msg);
        }
    }
}
Also used : Field(com.android.dx.cf.iface.Field) EncodedField(com.android.dx.dex.file.EncodedField) Annotations(com.android.dx.rop.annotation.Annotations) TypedConstant(com.android.dx.rop.cst.TypedConstant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) EncodedField(com.android.dx.dex.file.EncodedField) CstString(com.android.dx.rop.cst.CstString) FieldList(com.android.dx.cf.iface.FieldList)

Aggregations

FieldList (com.android.dx.cf.iface.FieldList)4 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)4 CstType (com.android.dx.rop.cst.CstType)4 Field (com.android.dx.cf.iface.Field)2 MethodList (com.android.dx.cf.iface.MethodList)2 EncodedField (com.android.dx.dex.file.EncodedField)2 Annotations (com.android.dx.rop.annotation.Annotations)2 Constant (com.android.dx.rop.cst.Constant)2 CstBaseMethodRef (com.android.dx.rop.cst.CstBaseMethodRef)2 CstString (com.android.dx.rop.cst.CstString)2 TypedConstant (com.android.dx.rop.cst.TypedConstant)2