AttributeListParserpublic final class AttributeListParser extends Object Parser for lists of attributes. |
Fields Summary |
---|
private final DirectClassFile | cf{@code non-null;} the class file to parse from | private final int | contextattribute parsing context | private final int | offsetoffset in the byte array of the classfile to the start of the list | private final AttributeFactory | attributeFactory{@code non-null;} attribute factory to use | private final com.android.dx.cf.iface.StdAttributeList | list{@code non-null;} list of parsed attributes | private int | endOffset{@code >= -1;} the end offset of this list in the byte array of the
classfile, or {@code -1} if not yet parsed | private com.android.dx.cf.iface.ParseObserver | observer{@code null-ok;} parse observer, if any |
Constructors Summary |
---|
public AttributeListParser(DirectClassFile cf, int context, int offset, AttributeFactory attributeFactory)Constructs an instance.
if (cf == null) {
throw new NullPointerException("cf == null");
}
if (attributeFactory == null) {
throw new NullPointerException("attributeFactory == null");
}
int size = cf.getBytes().getUnsignedShort(offset);
this.cf = cf;
this.context = context;
this.offset = offset;
this.attributeFactory = attributeFactory;
this.list = new StdAttributeList(size);
this.endOffset = -1;
|
Methods Summary |
---|
public int | getEndOffset()Gets the end offset of this constant pool in the {@code byte[]}
which it came from.
parseIfNecessary();
return endOffset;
| public com.android.dx.cf.iface.StdAttributeList | getList()Gets the parsed list.
parseIfNecessary();
return list;
| private void | parse()Does the actual parsing.
int sz = list.size();
int at = offset + 2; // Skip the count.
ByteArray bytes = cf.getBytes();
if (observer != null) {
observer.parsed(bytes, offset, 2,
"attributes_count: " + Hex.u2(sz));
}
for (int i = 0; i < sz; i++) {
try {
if (observer != null) {
observer.parsed(bytes, at, 0,
"\nattributes[" + i + "]:\n");
observer.changeIndent(1);
}
Attribute attrib =
attributeFactory.parse(cf, context, at, observer);
at += attrib.byteLength();
list.set(i, attrib);
if (observer != null) {
observer.changeIndent(-1);
observer.parsed(bytes, at, 0,
"end attributes[" + i + "]\n");
}
} catch (ParseException ex) {
ex.addContext("...while parsing attributes[" + i + "]");
throw ex;
} catch (RuntimeException ex) {
ParseException pe = new ParseException(ex);
pe.addContext("...while parsing attributes[" + i + "]");
throw pe;
}
}
endOffset = at;
| private void | parseIfNecessary()Runs {@link #parse} if it has not yet been run successfully.
if (endOffset < 0) {
parse();
}
| public void | setObserver(com.android.dx.cf.iface.ParseObserver observer)Sets the parse observer for this instance.
this.observer = observer;
|
|