ConstantValueAttributepublic class ConstantValueAttribute extends Attribute Encapsulates the ConstantValue attribute of a Java class file. |
Fields Summary |
---|
private int | attributeNameIndexindex into the constant pool table containing the name
of this class | private int | attributeLengthlength of this attribute in bytes | private int | constantValueIndexthe constant pool entry at that index gives the constant
value represented by this attribute |
Constructors Summary |
---|
public ConstantValueAttribute(DataInputStream iStream, int attributeNameIndex, int attributeLength)Constructor. Reads the ConstantValue attribute from
the class file.
this.attributeNameIndex = attributeNameIndex;
this.attributeLength = attributeLength;
//read the constantValueIndex from the class file
constantValueIndex = iStream.readUnsignedShort ();
|
Methods Summary |
---|
public java.lang.String | toString(ConstantPoolInfo[] constantPool)Returns the ConstantValue attribute in a nice easy to
read format as a string.
String s = new String ("");
ConstantUtf8Info utf8Info = (ConstantUtf8Info)
constantPool[attributeNameIndex];
s = s + utf8Info.toString () + "\n\t\t\t";
ConstantPoolInfo cpInfo = (ConstantPoolInfo)
constantPool[constantValueIndex];
switch (cpInfo.getTag())
{
case ConstantPoolInfo.CONSTANT_Long :
{
ConstantLongInfo cpInfo2 = (ConstantLongInfo) cpInfo;
s = s + cpInfo2.toString ();
break;
}
case ConstantPoolInfo.CONSTANT_Float :
{
ConstantFloatInfo cpInfo2 = (ConstantFloatInfo) cpInfo;
s = s + cpInfo2.toString ();
break;
}
case ConstantPoolInfo.CONSTANT_Double :
{
ConstantDoubleInfo cpInfo2 = (ConstantDoubleInfo) cpInfo;
s = s + cpInfo2.toString ();
break;
}
case ConstantPoolInfo.CONSTANT_Integer :
{
ConstantIntegerInfo cpInfo2 = (ConstantIntegerInfo) cpInfo;
s = s + cpInfo2.toString ();
break;
}
case ConstantPoolInfo.CONSTANT_String :
{
ConstantStringInfo cpInfo2 = (ConstantStringInfo) cpInfo;
s = s + cpInfo2.toString (constantPool);
break;
}
}
return s;
|
|