Search in sources :

Example 1 with AttAnnotationDefault

use of com.taobao.android.dx.cf.attrib.AttAnnotationDefault in project atlas by alibaba.

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.taobao.android.dx.rop.annotation.NameValuePair) AttributeList(com.taobao.android.dx.cf.iface.AttributeList) CstType(com.taobao.android.dx.rop.cst.CstType) MethodList(com.taobao.android.dx.cf.iface.MethodList) Method(com.taobao.android.dx.cf.iface.Method) AttEnclosingMethod(com.taobao.android.dx.cf.attrib.AttEnclosingMethod) Annotation(com.taobao.android.dx.rop.annotation.Annotation) AttAnnotationDefault(com.taobao.android.dx.cf.attrib.AttAnnotationDefault)

Example 2 with AttAnnotationDefault

use of com.taobao.android.dx.cf.attrib.AttAnnotationDefault in project atlas by alibaba.

the class StdAttributeFactory method annotationDefault.

/**
 * Parses an {@code AnnotationDefault} attribute.
 */
private Attribute annotationDefault(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }
    AnnotationParser ap = new AnnotationParser(cf, offset, length, observer);
    Constant cst = ap.parseValueAttribute();
    return new AttAnnotationDefault(cst, length);
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) AttAnnotationDefault(com.taobao.android.dx.cf.attrib.AttAnnotationDefault)

Aggregations

AttAnnotationDefault (com.taobao.android.dx.cf.attrib.AttAnnotationDefault)2 AttEnclosingMethod (com.taobao.android.dx.cf.attrib.AttEnclosingMethod)1 AttributeList (com.taobao.android.dx.cf.iface.AttributeList)1 Method (com.taobao.android.dx.cf.iface.Method)1 MethodList (com.taobao.android.dx.cf.iface.MethodList)1 Annotation (com.taobao.android.dx.rop.annotation.Annotation)1 NameValuePair (com.taobao.android.dx.rop.annotation.NameValuePair)1 Constant (com.taobao.android.dx.rop.cst.Constant)1 CstType (com.taobao.android.dx.rop.cst.CstType)1 TypedConstant (com.taobao.android.dx.rop.cst.TypedConstant)1