FileDocCategorySizeDatePackage
ConstantValue.javaAPI DocJava SE 6 API6644Tue Jun 10 00:22:18 BST 2008com.sun.org.apache.bcel.internal.classfile

ConstantValue

public 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.
version
$Id: ConstantValue.java,v 1.1.2.1 2005/07/31 23:46:34 jeffsuttor Exp $
author
M. Dahm
see
Attribute

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.

param
name_index Name index in constant pool
param
length Content length in bytes
param
file Input stream
param
constant_pool Array of constants
throw
IOException

    this(name_index, length, (int)file.readUnsignedShort(), constant_pool);
  
public ConstantValue(int name_index, int length, int constantvalue_index, ConstantPool constant_pool)

param
name_index Name index in constant pool
param
length Content length in bytes
param
constantvalue_index Index in constant pool
param
constant_pool Array of constants

    super(Constants.ATTR_CONSTANT_VALUE, name_index, length, constant_pool);
    this.constantvalue_index = constantvalue_index;
  
Methods Summary
public voidaccept(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.

param
v Visitor object

    v.visitConstantValue(this);
  
public com.sun.org.apache.bcel.internal.classfile.Attributecopy(com.sun.org.apache.bcel.internal.classfile.ConstantPool constant_pool)

return
deep copy of this attribute

    ConstantValue c = (ConstantValue)clone();
    c.constant_pool = constant_pool;
    return c;
  
public final voiddump(java.io.DataOutputStream file)
Dump constant value attribute to file stream on binary format.

param
file Output file stream
throws
IOException

    super.dump(file);
    file.writeShort(constantvalue_index);
  
public final intgetConstantValueIndex()

return
Index in constant pool of constant value.

 return constantvalue_index; 
public final voidsetConstantValueIndex(int constantvalue_index)

param
constantvalue_index.

    this.constantvalue_index = constantvalue_index;
  
public final java.lang.StringtoString()

return
String representation of constant value.

    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;