Search in sources :

Example 1 with FieldList

use of com.taobao.android.dx.cf.iface.FieldList in project atlas by alibaba.

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.taobao.android.dx.rop.cst.CstBaseMethodRef) Constant(com.taobao.android.dx.rop.cst.Constant) CstType(com.taobao.android.dx.rop.cst.CstType) CstFieldRef(com.taobao.android.dx.rop.cst.CstFieldRef) MethodList(com.taobao.android.dx.cf.iface.MethodList) FieldList(com.taobao.android.dx.cf.iface.FieldList)

Example 2 with FieldList

use of com.taobao.android.dx.cf.iface.FieldList in project atlas by alibaba.

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.taobao.android.dx.cf.iface.Field) EncodedField(com.taobao.android.dx.dex.file.EncodedField) Annotations(com.taobao.android.dx.rop.annotation.Annotations) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) CstType(com.taobao.android.dx.rop.cst.CstType) CstFieldRef(com.taobao.android.dx.rop.cst.CstFieldRef) EncodedField(com.taobao.android.dx.dex.file.EncodedField) CstString(com.taobao.android.dx.rop.cst.CstString) FieldList(com.taobao.android.dx.cf.iface.FieldList)

Aggregations

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