AttributeInfopublic class AttributeInfo extends Object Encapsulates an attribute of a class, field, or method of a
Java class file. |
Fields Summary |
---|
public static final int | ATTR_CODEThe possible types of attributes this AttributeInfo can represent | public static final int | ATTR_CONST | public static final int | ATTR_DEPRECATED | public static final int | ATTR_EXCEPTIONS | public static final int | ATTR_INNERCLASS | public static final int | ATTR_LINENUMBER | public static final int | ATTR_LOCALVAR | public static final int | ATTR_SOURCEFILE | public static final int | ATTR_SYNTHETIC | private int | attributeNameIndexindex into the constant pool table containing the name
of this class | private int | attributeLengthlength of this attribute in bytes | private Attribute | infothe attribute itself | private int | attrTypethe type of attribute this is | private ConstantPoolInfo[] | constantPoolreference to the class's constant pool |
Constructors Summary |
---|
public AttributeInfo(DataInputStream iStream, ConstantPoolInfo[] constantPool)Constructor. Creates an AttributeInfo object by reading
in the information about the attribute and the attribute.
//read the name index and the attribute length
attributeNameIndex = iStream.readUnsignedShort ();
attributeLength = iStream.readInt ();
//get the name of the attribute out of the constant pool
ConstantUtf8Info utf8Info = (ConstantUtf8Info)
constantPool[attributeNameIndex];
String s = utf8Info.toString ();
//branch based on the type of attribute
//and create the appropriate attribute object
//and store the attribute type
if (s.equals ("ConstantValue"))
{
info = new ConstantValueAttribute (iStream, attributeNameIndex,
attributeLength);
attrType = ATTR_CONST;
}
else
if (s.equals ("Synthetic"))
{
info = new SyntheticAttribute (iStream, attributeNameIndex,
attributeLength);
attrType = ATTR_SYNTHETIC;
}
else
if (s.equals ("Deprecated"))
{
info = new DeprecatedAttribute (iStream, attributeNameIndex,
attributeLength);
attrType = ATTR_DEPRECATED;
}
else
if (s.equals ("Code"))
{
info = new CodeAttribute (iStream, constantPool,
attributeNameIndex, attributeLength);
attrType = ATTR_CODE;
}
else
if (s.equals ("Exceptions"))
{
info = new ExceptionsAttribute (iStream, attributeNameIndex,
attributeLength);
attrType = ATTR_EXCEPTIONS;
}
else
if (s.equals ("InnerClasses"))
{
info = new InnerClassesAttribute (iStream, attributeNameIndex,
attributeLength);
attrType = ATTR_INNERCLASS;
}
else
if (s.equals ("LineNumberTable"))
{
info = new LineNumberTableAttribute (iStream,
attributeNameIndex,
attributeLength);
attrType = ATTR_LINENUMBER;
}
else
if (s.equals ("SourceFile"))
{
info = new SourceFileAttribute (iStream, constantPool,
attributeNameIndex,
attributeLength);
attrType = ATTR_SOURCEFILE;
}
else
if (s.equals ("LocalVariableTable"))
{
info = new LocalVariableTableAttribute (iStream,
attributeNameIndex, attributeLength);
attrType = ATTR_LOCALVAR;
}
else
for (int lcv = 0; lcv < attributeLength; ++lcv)
iStream.readByte ();
this.constantPool = constantPool;
|
Methods Summary |
---|
public Attribute | getInfo()Retrieves the info that this AttributeInfo represents.
return info;
| public int | getType()Retrieves the type of this AttributeInfo.
return attrType;
| public java.lang.String | toString()Returns the attribute in an easy to read format as a String.
if (info == null)
return ("AttributeInfo:\n\t\t" + "Unrecognized attribute");
else
return ("AttributeInfo:\n\t\t" + info.toString (constantPool));
|
|