jellyj.classfile.javaclass
Class ConstantPool


public final class ConstantPool
implements Constants

This class represents the constant pool, i.e. a table of constants. It may contain null references, due to the JVM specification that skips an entry after an 8-byte constant (double, long) entry.

Author:
JellyJ Design Group
See Also: Constant

Constructor Summary
 ConstantPool(Constant[] constant_pool)
           
 (package private) ConstantPool(DataInputStream file)
          Read constants from given file stream.

Method Summary
 voidaccept(Visitor v)
          Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
 StringconstantToString(Constant c)
          Resolve constant to a string representation.
 StringconstantToString(int index, byte tag)
          Retrieve constant at `index' from constant pool and resolve it to a string representation.
 voiddump(DataOutputStream file)
          Dump constant pool to file stream in binary format.
 final ConstantgetConstant(int index)
          Get constant from constant pool.
 final ConstantgetConstant(int index, byte tag)
          Get constant from constant pool and check whether it has the expected type.
 final Constant[]getConstantPool()
           
 final StringgetConstantString(int index, byte tag)
          Get string from constant pool and bypass the indirection of `ConstantClass' and `ConstantString' objects.
 final intgetLength()
           
 final voidsetConstant(int index, Constant constant)
           
 final voidsetConstantPool(Constant[] constant_pool)
           
 final StringtoString()
           

Constructor Detail

ConstantPool

public ConstantPool(Constant[] constant_pool)
Parameters:
constant_pool - Array of constants

ConstantPool

ConstantPool(DataInputStream file)
throws java.io.IOException,
java.lang.ClassFormatError
Read constants from given file stream.
Parameters:
file - Input stream
throw IOException, ClassFormatError
Method Detail

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.
Parameters:
v - Visitor object

constantToString

public String constantToString(Constant c)
throws java.lang.ClassFormatError
Resolve constant to a string representation.
Parameters:
constant - Constant to be printed
Returns: String representation

constantToString

public String constantToString(int index, byte tag)
throws java.lang.ClassFormatError
Retrieve constant at `index' from constant pool and resolve it to a string representation.
Parameters:
index - of constant in constant pool
tag - expected type
Returns: String representation

dump

public void dump(DataOutputStream file)
throws java.io.IOException
Dump constant pool to file stream in binary format.
Parameters:
file - Output file stream
throw IOException

getConstant

public final Constant getConstant(int index)
Get constant from constant pool.
Parameters:
index - Index in constant pool
Returns: Constant value
See Also:
Constant

getConstant

public final Constant getConstant(int index, byte tag)
throws java.lang.ClassFormatError
Get constant from constant pool and check whether it has the expected type.
Parameters:
index - Index in constant pool
tag - Tag of expected constant, i.e. its type
Returns: Constant value
See Also:
Constant
throw ClassFormatError

getConstantPool

public final Constant[] getConstantPool()
Returns: Array of constants.
See Also:
Constant

getConstantString

public final String getConstantString(int index, byte tag)
throws java.lang.ClassFormatError
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.
Parameters:
index - Index in constant pool
tag - Tag of expected constant, either ConstantClass or ConstantString
Returns: Contents of string reference
See Also:
ConstantClass, ConstantString
throw ClassFormatError

getLength

public final int getLength()
Returns: Length of constant pool.

setConstant

public final void setConstant(int index, Constant constant)
Parameters:
constant - Constant to set

setConstantPool

public final void setConstantPool(Constant[] constant_pool)
Parameters:
constant_pool

toString

public final String toString()
Returns: String representation.

Association Links

to Class jellyj.classfile.javaclass.Constant