org.apache.bcel.classfile
Class ConstantPool
java.lang.Object
org.apache.bcel.classfile.ConstantPool
- Cloneable, Node, Serializable
public class ConstantPool
extends java.lang.Object
implements Cloneable, Node, Serializable
This class represents the constant pool, i.e., a table of constants, of
a parsed classfile. It may contain null references, due to the JVM
specification that skips an entry after an 8-byte constant (double,
long) entry. Those interested in generating constant pools
programatically should see
ConstantPoolGen.
$Id: ConstantPool.java,v 1.6 2002/07/11 19:39:04 mdahm Exp $
ConstantPool
public ConstantPool(Constant[] constant_pool)
constant_pool
- Array of constants
accept
public void accept(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.
- accept in interface Node
constantToString
public String constantToString(int index,
byte tag)
throws ClassFormatException
Retrieve constant at `index' from constant pool and resolve it to
a string representation.
index
- of constant in constant pooltag
- expected type
copy
public ConstantPool copy()
- deep copy of this constant pool
dump
public void dump(DataOutputStream file)
throws IOException
Dump constant pool to file stream in binary format.
file
- Output file stream
getConstant
public Constant getConstant(int index)
Get constant from constant pool.
index
- Index in constant pool
getConstant
public Constant getConstant(int index,
byte tag)
throws ClassFormatException
Get constant from constant pool and check whether it has the
expected type.
index
- Index in constant pooltag
- Tag of expected constant, i.e., its type
getConstantPool
public Constant[] getConstantPool()
getConstantString
public String getConstantString(int index,
byte tag)
throws ClassFormatException
Get string from constant pool and bypass the indirection of
`ConstantClass' and `ConstantString' objects. I.e. these classes have
an index field that points to another entry of the constant pool of
type `ConstantUtf8' which contains the real data.
index
- Index in constant pooltag
- Tag of expected constant, either ConstantClass or ConstantString
- Contents of string reference
getLength
public int getLength()
setConstant
public void setConstant(int index,
Constant constant)
constant
- Constant to set
setConstantPool
public void setConstantPool(Constant[] constant_pool)
toString
public String toString()