All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class espresso.classfile.javaclass.ConstantPool

java.lang.Object
   |
   +----espresso.classfile.javaclass.ConstantPool

public final class ConstantPool
extends Object
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.

See Also:
Constant

Variable Index

 o constant_pool
 o constant_pool_count

Constructor Index

 o ConstantPool(Constant[])
 o ConstantPool(DataInputStream)
Read constants from given file stream.

Method Index

 o accept(Visitor)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
 o constantToString(Constant)
Resolve constant to a string representation.
 o constantToString(int, byte)
Retrieve constant at `index' from constant pool and resolve it to a string representation.
 o dump(DataOutputStream)
Dump constant pool to file stream in binary format.
 o getConstant(int)
Get constant from constant pool.
 o getConstant(int, byte)
Get constant from constant pool and check whether it has the expected type.
 o getConstantPool()
 o getConstantString(int, byte)
Get string from constant pool and bypass the indirection of `ConstantClass' and `ConstantString' objects.
 o getLength()
 o readConstant(DataInputStream)
Read one constant from the given file, the type depends on a tag byte.
 o setConstant(int, Constant)
 o setConstantPool(Constant[])
 o toString()

Variables

 o constant_pool_count
 private int constant_pool_count
 o constant_pool
 private Constant constant_pool[]

Constructors

 o ConstantPool
 public ConstantPool(Constant constant_pool[])
Parameters:
constant_pool - Array of constants
 o ConstantPool
 ConstantPool(DataInputStream file) throws IOException, ClassFormatError
Read constants from given file stream.

Parameters:
file - Input stream

Methods

 o 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
 o constantToString
 public String constantToString(Constant c) throws ClassFormatError
Resolve constant to a string representation.

Parameters:
constant - Constant to be printed
Returns:
String representation
 o constantToString
 public String constantToString(int index,
                                byte tag) throws 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
 o dump
 public void dump(DataOutputStream file) throws IOException
Dump constant pool to file stream in binary format.

Parameters:
file - Output file stream
 o getConstant
 public final Constant getConstant(int index)
Get constant from constant pool.

Parameters:
index - Index in constant pool
Returns:
Constant value
See Also:
Constant
 o getConstant
 public final Constant getConstant(int index,
                                   byte tag) throws 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
 o getConstantPool
 public final Constant[] getConstantPool()
Returns:
Array of constants.
See Also:
Constant
 o getConstantString
 public final String getConstantString(int index,
                                       byte tag) throws 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
 o getLength
 public final int getLength()
Returns:
Length of constant pool.
 o readConstant
 private final Constant readConstant(DataInputStream file) throws IOException, ClassFormatError
Read one constant from the given file, the type depends on a tag byte.

Parameters:
file - Input stream
Returns:
Constant object
 o setConstant
 public final void setConstant(int index,
                               Constant constant)
Parameters:
constant - Constant to set
 o setConstantPool
 public final void setConstantPool(Constant constant_pool[])
 o toString
 public final String toString()
Returns:
String representation.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index