Search in sources :

Example 6 with AttributeList

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

the class DirectClassFile method getSourceFile.

/** {@inheritDoc} */
public CstString getSourceFile() {
    AttributeList attribs = getAttributes();
    Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);
    if (attSf instanceof AttSourceFile) {
        return ((AttSourceFile) attSf).getSourceFile();
    }
    return null;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) StdAttributeList(com.android.dx.cf.iface.StdAttributeList) AttributeList(com.android.dx.cf.iface.AttributeList) AttSourceFile(com.android.dx.cf.attrib.AttSourceFile)

Example 7 with AttributeList

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

the class DirectClassFile method getSourceFile.

/**
 * {@inheritDoc}
 */
public CstString getSourceFile() {
    AttributeList attribs = getAttributes();
    Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);
    if (attSf instanceof AttSourceFile) {
        return ((AttSourceFile) attSf).getSourceFile();
    }
    return null;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) StdAttributeList(com.android.dx.cf.iface.StdAttributeList) AttributeList(com.android.dx.cf.iface.AttributeList) AttSourceFile(com.android.dx.cf.attrib.AttSourceFile)

Example 8 with AttributeList

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

the class AttributeTranslator method getExceptions.

/**
 * Gets the list of thrown exceptions for a given method.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the list of thrown exceptions
 */
public static TypeList getExceptions(Method method) {
    AttributeList attribs = method.getAttributes();
    AttExceptions exceptions = (AttExceptions) attribs.findFirst(AttExceptions.ATTRIBUTE_NAME);
    if (exceptions == null) {
        return StdTypeList.EMPTY;
    }
    return exceptions.getExceptions();
}
Also used : AttExceptions(com.android.dx.cf.attrib.AttExceptions) AttributeList(com.android.dx.cf.iface.AttributeList)

Example 9 with AttributeList

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

the class AttributeTranslator method translateAnnotationDefaults.

/**
 * Gets the {@code AnnotationDefault} attributes out of a
 * given class, if any, reforming them as an
 * {@code AnnotationDefault} annotation.
 *
 * @param cf {@code non-null;} the class in question
 * @return {@code null-ok;} an appropriately-constructed
 * {@code AnnotationDefault} annotation, if there were any
 * annotation defaults in the class, or {@code null} if not
 */
private static Annotation translateAnnotationDefaults(DirectClassFile cf) {
    CstType thisClass = cf.getThisClass();
    MethodList methods = cf.getMethods();
    int sz = methods.size();
    Annotation result = new Annotation(thisClass, AnnotationVisibility.EMBEDDED);
    boolean any = false;
    for (int i = 0; i < sz; i++) {
        Method one = methods.get(i);
        AttributeList attribs = one.getAttributes();
        AttAnnotationDefault oneDefault = (AttAnnotationDefault) attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME);
        if (oneDefault != null) {
            NameValuePair pair = new NameValuePair(one.getNat().getName(), oneDefault.getValue());
            result.add(pair);
            any = true;
        }
    }
    if (!any) {
        return null;
    }
    result.setImmutable();
    return AnnotationUtils.makeAnnotationDefault(result);
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) AttributeList(com.android.dx.cf.iface.AttributeList) CstType(com.android.dx.rop.cst.CstType) MethodList(com.android.dx.cf.iface.MethodList) AttEnclosingMethod(com.android.dx.cf.attrib.AttEnclosingMethod) Method(com.android.dx.cf.iface.Method) Annotation(com.android.dx.rop.annotation.Annotation) AttAnnotationDefault(com.android.dx.cf.attrib.AttAnnotationDefault)

Example 10 with AttributeList

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

the class AttributeTranslator method getClassAnnotations.

/**
 * Gets the annotations out of a given class, similar to {@link
 * #getAnnotations}, also including annotations for translations
 * of class-level attributes {@code EnclosingMethod} and
 * {@code InnerClasses}, if present. Additionally, if the
 * class is an annotation class, then this also includes a
 * representation of all the {@code AnnotationDefault}
 * values.
 *
 * @param cf {@code non-null;} the class in question
 * @param args {@code non-null;} the high-level options
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getClassAnnotations(DirectClassFile cf, CfOptions args) {
    CstType thisClass = cf.getThisClass();
    AttributeList attribs = cf.getAttributes();
    Annotations result = getAnnotations(attribs);
    Annotation enclosingMethod = translateEnclosingMethod(attribs);
    try {
        Annotations innerClassAnnotations = translateInnerClasses(thisClass, attribs, enclosingMethod == null);
        if (innerClassAnnotations != null) {
            result = Annotations.combine(result, innerClassAnnotations);
        }
    } catch (Warning warn) {
        args.warn.println("warning: " + warn.getMessage());
    }
    if (enclosingMethod != null) {
        result = Annotations.combine(result, enclosingMethod);
    }
    if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
        Annotation annotationDefault = translateAnnotationDefaults(cf);
        if (annotationDefault != null) {
            result = Annotations.combine(result, annotationDefault);
        }
    }
    return result;
}
Also used : Warning(com.android.dx.util.Warning) 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) AttributeList(com.android.dx.cf.iface.AttributeList) CstType(com.android.dx.rop.cst.CstType) Annotation(com.android.dx.rop.annotation.Annotation)

Aggregations

AttributeList (com.android.dx.cf.iface.AttributeList)11 AttRuntimeInvisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)4 AttRuntimeVisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)4 Annotation (com.android.dx.rop.annotation.Annotation)4 CstType (com.android.dx.rop.cst.CstType)4 Attribute (com.android.dx.cf.iface.Attribute)3 AttAnnotationDefault (com.android.dx.cf.attrib.AttAnnotationDefault)2 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)2 AttExceptions (com.android.dx.cf.attrib.AttExceptions)2 AttRuntimeInvisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)2 AttRuntimeVisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)2 AttSourceFile (com.android.dx.cf.attrib.AttSourceFile)2 Method (com.android.dx.cf.iface.Method)2 MethodList (com.android.dx.cf.iface.MethodList)2 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)2 Annotations (com.android.dx.rop.annotation.Annotations)2 NameValuePair (com.android.dx.rop.annotation.NameValuePair)2 Warning (com.android.dx.util.Warning)2 BaseAnnotations (com.android.dx.cf.attrib.BaseAnnotations)1 ClassPathOpener (com.android.dx.cf.direct.ClassPathOpener)1