Search in sources :

Example 1 with EncodedField

use of com.taobao.android.dx.dex.file.EncodedField 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

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