ConstantValuepublic final class ConstantValue extends Attribute This class is derived from Attribute and represents a constant
value, i.e., a default value for initializing a class field.
This class is instantiated by the Attribute.readAttribute() method. |
Fields Summary |
---|
private int | constantvalue_index |
Constructors Summary |
---|
public ConstantValue(ConstantValue c)Initialize from another object. Note that both objects use the same
references (shallow copy). Use clone() for a physical copy.
this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(),
c.getConstantPool());
| ConstantValue(int name_index, int length, DataInputStream file, ConstantPool constant_pool)Construct object from file stream.
this(name_index, length, (int)file.readUnsignedShort(), constant_pool);
| public ConstantValue(int name_index, int length, int constantvalue_index, ConstantPool constant_pool)
super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool);
this.constantvalue_index = constantvalue_index;
|
Methods Summary |
---|
public void | accept(com.sun.org.apache.bcel.internal.classfile.Visitor v)Called by objects that are traversing the nodes of the tree implicitely
defined by the contents of a Java class. I.e., the hierarchy of methods,
fields, attributes, etc. spawns a tree of objects.
v.visitConstantValue(this);
| public com.sun.org.apache.bcel.internal.classfile.Attribute | copy(com.sun.org.apache.bcel.internal.classfile.ConstantPool constant_pool)
ConstantValue c = (ConstantValue)clone();
c.constant_pool = constant_pool;
return c;
| public final void | dump(java.io.DataOutputStream file)Dump constant value attribute to file stream on binary format.
super.dump(file);
file.writeShort(constantvalue_index);
| public final int | getConstantValueIndex() return constantvalue_index;
| public final void | setConstantValueIndex(int constantvalue_index)
this.constantvalue_index = constantvalue_index;
| public final java.lang.String | toString()
Constant c = constant_pool.getConstant(constantvalue_index);
String buf;
int i;
// Print constant to string depending on its type
switch(c.getTag()) {
case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break;
case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break;
case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break;
case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break;
case Constants.CONSTANT_String:
i = ((ConstantString)c).getStringIndex();
c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8);
buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\"";
break;
default:
throw new IllegalStateException("Type of ConstValue invalid: " + c);
}
return buf;
|
|