AttributeFactorypublic class AttributeFactory extends Object Factory capable of instantiating various {@link Attribute} subclasses
depending on the context and name. |
Fields Summary |
---|
public static final int | CTX_CLASScontext for attributes on class files | public static final int | CTX_FIELDcontext for attributes on fields | public static final int | CTX_METHODcontext for attributes on methods | public static final int | CTX_CODEcontext for attributes on code attributes | public static final int | CTX_COUNTnumber of contexts |
Constructors Summary |
---|
public AttributeFactory()Constructs an instance.
// This space intentionally left blank.
|
Methods Summary |
---|
public final com.android.dx.cf.iface.Attribute | parse(DirectClassFile cf, int context, int offset, com.android.dx.cf.iface.ParseObserver observer)Parses and makes an attribute based on the bytes at the
indicated position in the given array. This method figures out
the name, and then does all the setup to call on to {@link #parse0},
which does the actual construction.
if (cf == null) {
throw new NullPointerException("cf == null");
}
if ((context < 0) || (context >= CTX_COUNT)) {
throw new IllegalArgumentException("bad context");
}
CstString name = null;
try {
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int nameIdx = bytes.getUnsignedShort(offset);
int length = bytes.getInt(offset + 2);
name = (CstString) pool.get(nameIdx);
if (observer != null) {
observer.parsed(bytes, offset, 2,
"name: " + name.toHuman());
observer.parsed(bytes, offset + 2, 4,
"length: " + Hex.u4(length));
}
return parse0(cf, context, name.getString(), offset + 6, length,
observer);
} catch (ParseException ex) {
ex.addContext("...while parsing " +
((name != null) ? (name.toHuman() + " ") : "") +
"attribute at offset " + Hex.u4(offset));
throw ex;
}
| protected com.android.dx.cf.iface.Attribute | parse0(DirectClassFile cf, int context, java.lang.String name, int offset, int length, com.android.dx.cf.iface.ParseObserver observer)Parses attribute content. The base class implements this by constructing
an instance of {@link RawAttribute}. Subclasses are expected to
override this to do something better in most cases.
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
Attribute result = new RawAttribute(name, bytes, offset, length, pool);
if (observer != null) {
observer.parsed(bytes, offset, length, "attribute data");
}
return result;
|
|