Search in sources :

Example 6 with Annotations

use of com.android.dx.rop.annotation.Annotations 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 7 with Annotations

use of com.android.dx.rop.annotation.Annotations in project buck by facebook.

the class StdAttributeFactory method runtimeVisibleAnnotations.

/**
     * Parses a {@code RuntimeVisibleAnnotations} attribute.
     */
private Attribute runtimeVisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }
    AnnotationParser ap = new AnnotationParser(cf, offset, length, observer);
    Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME);
    return new AttRuntimeVisibleAnnotations(annotations, length);
}
Also used : AttRuntimeVisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) AttRuntimeVisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) AttRuntimeVisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) Annotations(com.android.dx.rop.annotation.Annotations) AttRuntimeInvisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) AttRuntimeInvisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)

Example 8 with Annotations

use of com.android.dx.rop.annotation.Annotations in project buck by facebook.

the class StdAttributeFactory method runtimeInvisibleAnnotations.

/**
     * Parses a {@code RuntimeInvisibleAnnotations} attribute.
     */
private Attribute runtimeInvisibleAnnotations(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }
    AnnotationParser ap = new AnnotationParser(cf, offset, length, observer);
    Annotations annotations = ap.parseAnnotationAttribute(AnnotationVisibility.BUILD);
    return new AttRuntimeInvisibleAnnotations(annotations, length);
}
Also used : AttRuntimeVisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) AttRuntimeVisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) Annotations(com.android.dx.rop.annotation.Annotations) AttRuntimeInvisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) AttRuntimeInvisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations) AttRuntimeInvisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)

Example 9 with Annotations

use of com.android.dx.rop.annotation.Annotations in project buck by facebook.

the class AnnotationParser method parseAnnotationsList.

/**
     * Parses a list of annotation lists.
     *
     * @param visibility {@code non-null;} visibility of the parsed annotations
     * @return {@code non-null;} the list of annotation lists read from the attribute
     * data
     */
private AnnotationsList parseAnnotationsList(AnnotationVisibility visibility) throws IOException {
    int count = input.readUnsignedByte();
    if (observer != null) {
        parsed(1, "num_parameters: " + Hex.u1(count));
    }
    AnnotationsList outerList = new AnnotationsList(count);
    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "parameter_annotations[" + i + "]:");
            changeIndent(1);
        }
        Annotations annotations = parseAnnotations(visibility);
        outerList.set(i, annotations);
        if (observer != null) {
            observer.changeIndent(-1);
        }
    }
    outerList.setImmutable();
    return outerList;
}
Also used : Annotations(com.android.dx.rop.annotation.Annotations) AnnotationsList(com.android.dx.rop.annotation.AnnotationsList)

Example 10 with Annotations

use of com.android.dx.rop.annotation.Annotations in project J2ME-Loader by nikita36078.

the class AnnotationParser method parseAnnotations.

/**
 * Parses an annotation list.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotations read from the attribute
 * data
 */
private Annotations parseAnnotations(AnnotationVisibility visibility) throws IOException {
    int count = input.readUnsignedShort();
    if (observer != null) {
        parsed(2, "num_annotations: " + Hex.u2(count));
    }
    Annotations annotations = new Annotations();
    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "annotations[" + i + "]:");
            changeIndent(1);
        }
        Annotation annotation = parseAnnotation(visibility);
        annotations.add(annotation);
        if (observer != null) {
            observer.changeIndent(-1);
        }
    }
    annotations.setImmutable();
    return annotations;
}
Also used : Annotations(com.android.dx.rop.annotation.Annotations) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Aggregations

Annotations (com.android.dx.rop.annotation.Annotations)24 AttRuntimeInvisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)12 AttRuntimeInvisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)12 AttRuntimeVisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)12 AttRuntimeVisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)12 Annotation (com.android.dx.rop.annotation.Annotation)10 CstType (com.android.dx.rop.cst.CstType)10 CstString (com.android.dx.rop.cst.CstString)8 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)6 ClassDefItem (com.android.dx.dex.file.ClassDefItem)4 EncodedMethod (com.android.dx.dex.file.EncodedMethod)4 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)4 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)4 TypedConstant (com.android.dx.rop.cst.TypedConstant)4 StdTypeList (com.android.dx.rop.type.StdTypeList)4 TypeList (com.android.dx.rop.type.TypeList)4 Warning (com.android.dx.util.Warning)4 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2 InnerClassList (com.android.dx.cf.attrib.InnerClassList)2 ConcreteMethod (com.android.dx.cf.code.ConcreteMethod)2