Search in sources :

Example 6 with CstNat

use of com.taobao.android.dx.rop.cst.CstNat in project atlas by alibaba.

the class AttributeTranslator method translateEnclosingMethod.

/**
     * Gets the {@code EnclosingMethod} attribute out of a given
     * {@link AttributeList}, if any, translating it to an annotation.
     * If the class really has an enclosing method, this returns an
     * {@code EnclosingMethod} annotation; if not, this returns
     * an {@code EnclosingClass} annotation.
     *
     * @param attribs {@code non-null;} the attributes list to search in
     * @return {@code null-ok;} the converted {@code EnclosingMethod} or
     * {@code EnclosingClass} annotation, if there was an
     * attribute to translate
     */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod) attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);
    if (enclosingMethod == null) {
        return null;
    }
    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();
    if (nat == null) {
        /*
             * Dalvik doesn't use EnclosingMethod annotations unless
             * there really is an enclosing method. Anonymous classes
             * are unambiguously identified by having an InnerClass
             * annotation with an empty name along with an appropriate
             * EnclosingClass.
             */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }
    return AnnotationUtils.makeEnclosingMethod(new CstMethodRef(enclosingClass, nat));
}
Also used : CstNat(com.taobao.android.dx.rop.cst.CstNat) AttEnclosingMethod(com.taobao.android.dx.cf.attrib.AttEnclosingMethod) CstType(com.taobao.android.dx.rop.cst.CstType) CstMethodRef(com.taobao.android.dx.rop.cst.CstMethodRef)

Example 7 with CstNat

use of com.taobao.android.dx.rop.cst.CstNat in project atlas by alibaba.

the class MemberListParser method parse.

/**
     * Does the actual parsing.
     */
private void parse() {
    int attributeContext = getAttributeContext();
    int count = getCount();
    // Skip the count.
    int at = offset + 2;
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    if (observer != null) {
        observer.parsed(bytes, offset, 2, humanName() + "s_count: " + Hex.u2(count));
    }
    for (int i = 0; i < count; i++) {
        try {
            int accessFlags = bytes.getUnsignedShort(at);
            int nameIdx = bytes.getUnsignedShort(at + 2);
            int descIdx = bytes.getUnsignedShort(at + 4);
            CstString name = (CstString) pool.get(nameIdx);
            CstString desc = (CstString) pool.get(descIdx);
            if (observer != null) {
                observer.startParsingMember(bytes, at, name.getString(), desc.getString());
                observer.parsed(bytes, at, 0, "\n" + humanName() + "s[" + i + "]:\n");
                observer.changeIndent(1);
                observer.parsed(bytes, at, 2, "access_flags: " + humanAccessFlags(accessFlags));
                observer.parsed(bytes, at + 2, 2, "name: " + name.toHuman());
                observer.parsed(bytes, at + 4, 2, "descriptor: " + desc.toHuman());
            }
            at += 6;
            AttributeListParser parser = new AttributeListParser(cf, attributeContext, at, attributeFactory);
            parser.setObserver(observer);
            at = parser.getEndOffset();
            StdAttributeList attributes = parser.getList();
            attributes.setImmutable();
            CstNat nat = new CstNat(name, desc);
            Member member = set(i, accessFlags, nat, attributes);
            if (observer != null) {
                observer.changeIndent(-1);
                observer.parsed(bytes, at, 0, "end " + humanName() + "s[" + i + "]\n");
                observer.endParsingMember(bytes, at, name.getString(), desc.getString(), member);
            }
        } catch (ParseException ex) {
            ex.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw ex;
        } catch (RuntimeException ex) {
            ParseException pe = new ParseException(ex);
            pe.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw pe;
        }
    }
    endOffset = at;
}
Also used : StdAttributeList(com.taobao.android.dx.cf.iface.StdAttributeList) CstNat(com.taobao.android.dx.rop.cst.CstNat) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstString(com.taobao.android.dx.rop.cst.CstString) ByteArray(com.taobao.android.dx.util.ByteArray) ParseException(com.taobao.android.dx.cf.iface.ParseException) Member(com.taobao.android.dx.cf.iface.Member)

Aggregations

CstNat (com.taobao.android.dx.rop.cst.CstNat)7 CstString (com.taobao.android.dx.rop.cst.CstString)4 CstType (com.taobao.android.dx.rop.cst.CstType)4 AttEnclosingMethod (com.taobao.android.dx.cf.attrib.AttEnclosingMethod)2 ParseException (com.taobao.android.dx.cf.iface.ParseException)2 Annotation (com.taobao.android.dx.rop.annotation.Annotation)2 AnnotationsList (com.taobao.android.dx.rop.annotation.AnnotationsList)2 ConstantPool (com.taobao.android.dx.rop.cst.ConstantPool)2 CstMethodRef (com.taobao.android.dx.rop.cst.CstMethodRef)2 ByteArray (com.taobao.android.dx.util.ByteArray)2 Attribute (com.taobao.android.dx.cf.iface.Attribute)1 Member (com.taobao.android.dx.cf.iface.Member)1 StdAttributeList (com.taobao.android.dx.cf.iface.StdAttributeList)1 ClassDefItem (com.taobao.android.dx.dex.file.ClassDefItem)1 EncodedMethod (com.taobao.android.dx.dex.file.EncodedMethod)1 Annotations (com.taobao.android.dx.rop.annotation.Annotations)1 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)1 CstAnnotation (com.taobao.android.dx.rop.cst.CstAnnotation)1 CstArray (com.taobao.android.dx.rop.cst.CstArray)1 CstDouble (com.taobao.android.dx.rop.cst.CstDouble)1