Package org.apache.bcel.classfile
Class ConstantPool
java.lang.Object
org.apache.bcel.classfile.ConstantPool
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.
- See Also:
-
Constructor Summary
ConstructorDescriptionConstantPool
(DataInput input) Reads constants from given input stream.ConstantPool
(Constant[] constantPool) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.constantToString
(int index, byte tag) Retrieves constant at `index' from constant pool and resolve it to a string representation.Resolves constant to a string representation.copy()
void
dump
(DataOutputStream file) Dump constant pool to file stream in binary format.getConstant
(int index) Gets constant from constant pool.getConstant
(int index, byte tag) Gets constant from constant pool and check whether it has the expected type.Constant[]
getConstantString
(int index, byte tag) Gets string from constant pool and bypass the indirection of `ConstantClass' and `ConstantString' objects.int
void
setConstant
(int index, Constant constant) void
setConstantPool
(Constant[] constantPool) toString()
-
Constructor Details
-
ConstantPool
- Parameters:
constantPool
- Array of constants
-
ConstantPool
Reads constants from given input stream.- Parameters:
input
- Input stream- Throws:
IOException
ClassFormatException
-
-
Method Details
-
accept
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. -
constantToString
Resolves constant to a string representation.- Parameters:
c
- Constant to be printed- Returns:
- String representation
- Throws:
ClassFormatException
-
constantToString
Retrieves constant at `index' from constant pool and resolve it to a string representation.- Parameters:
index
- of constant in constant pooltag
- expected type- Returns:
- String representation
- Throws:
ClassFormatException
-
dump
Dump constant pool to file stream in binary format.- Parameters:
file
- Output file stream- Throws:
IOException
-
getConstant
Gets constant from constant pool.- Parameters:
index
- Index in constant pool- Returns:
- Constant value
- See Also:
-
getConstant
Gets constant from constant pool and check whether it has the expected type.- Parameters:
index
- Index in constant pooltag
- Tag of expected constant, i.e., its type- Returns:
- Constant value
- Throws:
ClassFormatException
- See Also:
-
getConstantPool
- Returns:
- Array of constants.
- See Also:
-
getConstantString
Gets 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.- Parameters:
index
- Index in constant pooltag
- Tag of expected constant, either ConstantClass or ConstantString- Returns:
- Contents of string reference
- Throws:
ClassFormatException
- See Also:
-
getLength
public int getLength()- Returns:
- Length of constant pool.
-
setConstant
- Parameters:
constant
- Constant to set
-
setConstantPool
- Parameters:
constantPool
-
-
toString
-
copy
- Returns:
- deep copy of this constant pool
-