Search in sources :

Example 1 with Member

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

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.android.dx.cf.iface.StdAttributeList) CstNat(com.android.dx.rop.cst.CstNat) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException) Member(com.android.dx.cf.iface.Member)

Example 2 with Member

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

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.android.dx.cf.iface.StdAttributeList) CstNat(com.android.dx.rop.cst.CstNat) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException) Member(com.android.dx.cf.iface.Member)

Aggregations

Member (com.android.dx.cf.iface.Member)2 ParseException (com.android.dx.cf.iface.ParseException)2 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)2 ConstantPool (com.android.dx.rop.cst.ConstantPool)2 CstNat (com.android.dx.rop.cst.CstNat)2 CstString (com.android.dx.rop.cst.CstString)2 ByteArray (com.android.dx.util.ByteArray)2