All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class espresso.classfile.classgen.ConstantPoolGen

java.lang.Object
   |
   +----espresso.classfile.classgen.ConstantPoolGen

public final class ConstantPoolGen
extends Object
implements Constants
This class is used to consequently build up a constant pool. The user adds constants via `addXXX' methods, `addString', `addClass', etc.. These methods return an index into the constant pool. Finally, `getFinalConstantPool()' returns the constant pool built up. Intermediate versions of the constant pool can be obtained with `getConstantPool()'. A constant pool has capacity for Constants.MAX_SHORT entries. Note that the first (0) is used by the JVM and that Double and Long constants need two slots entries.

See Also:
Constant

Variable Index

 o constants
 o cp
 o index

Constructor Index

 o ConstantPoolGen()
Create empty constant pool.
 o ConstantPoolGen(Constant[])
Initialize with given array of constants.
 o ConstantPoolGen(ConstantPool)
Initialize with given constant pool.

Method Index

 o addClass(String)
Add a new Class reference to the ConstantPool, if it is not already in there.
 o addConstant(Constant)
Add a given constant (without checking for double entries).
 o addDouble(double)
Add a new double constant to the ConstantPool, if it is not already in there.
 o addFieldref(String, String, String)
Add a new Fieldref constant to the ConstantPool, if it is not already in there.
 o addFloat(float)
Add a new Float constant to the ConstantPool, if it is not already in there.
 o addInteger(int)
Add a new Integer constant to the ConstantPool, if it is not already in there.
 o addInterfaceMethodref(String, String, String)
Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there.
 o addLong(long)
Add a new long constant to the ConstantPool, if it is not already in there.
 o addMethodref(String, String, String)
Add a new Methodref constant to the ConstantPool, if it is not already in there.
 o addNameAndType(String, String)
Add a new NameAndType constant to the ConstantPool if it is not already in there.
 o addString(String)
Add a new String constant to the ConstantPool, if it is not already in there.
 o addUnicode(String)
Add a new Unicode constant to the ConstantPool, if it is not already in there.
 o addUtf8(String)
Add a new Utf8 constant to the ConstantPool, if it is not already in there.
 o getConstant(int)
 o getConstantPool()
 o getFinalConstantPool()
 o getSize()
 o lookupClass(String)
Look for ConstantClass in ConstantPool named `str'.
 o lookupConstant(Constant)
Look up constant in ConstantPool.
 o lookupDouble(double)
Look for ConstantDouble in ConstantPool.
 o lookupFieldref(String, String, String)
Look for ConstantFieldref in ConstantPool.
 o lookupFloat(float)
Look for ConstantFloat in ConstantPool.
 o lookupInteger(int)
Look for ConstantInteger in ConstantPool.
 o lookupInterfaceMethodref(String, String, String)
Look for ConstantInterfaceMethodref in ConstantPool.
 o lookupLong(long)
Look for ConstantLong in ConstantPool.
 o lookupMethodref(String, String, String)
Look for ConstantMethodref in ConstantPool.
 o lookupNameAndType(String, String)
Look for ConstantNameAndType in ConstantPool.
 o lookupString(String)
Look for ConstantString in ConstantPool containing String `str'.
 o lookupUnicode(String)
Look for ConstantUnicode in ConstantPool.
 o lookupUtf8(String)
Look for ConstantUtf8 in ConstantPool.

Variables

 o constants
 private Constant constants[]
 o cp
 private ConstantPool cp
 o index
 private int index

Constructors

 o ConstantPoolGen
 public ConstantPoolGen(Constant c[])
Initialize with given array of constants.

Parameters:
c - array of given constants, new ones will be appended
 o ConstantPoolGen
 public ConstantPoolGen(ConstantPool cp)
Initialize with given constant pool.

 o ConstantPoolGen
 public ConstantPoolGen()
Create empty constant pool.

Methods

 o lookupString
 public final int lookupString(String str)
Look for ConstantString in ConstantPool containing String `str'.

Parameters:
str - String to search for
Returns:
index on success, -1 otherwise
 o addString
 public final int addString(String str)
Add a new String constant to the ConstantPool, if it is not already in there.

Parameters:
str - String to add
Returns:
index of entry
 o lookupClass
 public final int lookupClass(String str)
Look for ConstantClass in ConstantPool named `str'.

Parameters:
str - String to search for
Returns:
index on success, -1 otherwise
 o addClass
 public final int addClass(String str)
Add a new Class reference to the ConstantPool, if it is not already in there.

Parameters:
str - Class to add
Returns:
index of entry
 o lookupInteger
 public final int lookupInteger(int n)
Look for ConstantInteger in ConstantPool.

Parameters:
n - integer number to look for
Returns:
index on success, -1 otherwise
 o addInteger
 public final int addInteger(int n)
Add a new Integer constant to the ConstantPool, if it is not already in there.

Parameters:
n - integer number to add
Returns:
index of entry
 o lookupFloat
 public final int lookupFloat(float n)
Look for ConstantFloat in ConstantPool.

Parameters:
n - Float number to look for
Returns:
index on success, -1 otherwise
 o addFloat
 public final int addFloat(float n)
Add a new Float constant to the ConstantPool, if it is not already in there.

Parameters:
n - Float number to add
Returns:
index of entry
 o lookupUnicode
 public final int lookupUnicode(String n)
Look for ConstantUnicode in ConstantPool.

Parameters:
n - Unicode string to look for
Returns:
index on success, -1 otherwise
 o addUnicode
 public final int addUnicode(String n)
Add a new Unicode constant to the ConstantPool, if it is not already in there.

Parameters:
n - Unicode string to add
Returns:
index of entry
 o lookupUtf8
 public final int lookupUtf8(String n)
Look for ConstantUtf8 in ConstantPool.

Parameters:
n - Utf8 string to look for
Returns:
index on success, -1 otherwise
 o addUtf8
 public final int addUtf8(String n)
Add a new Utf8 constant to the ConstantPool, if it is not already in there.

Parameters:
n - Utf8 string to add
Returns:
index of entry
 o lookupLong
 public final int lookupLong(long n)
Look for ConstantLong in ConstantPool.

Parameters:
n - Long number to look for
Returns:
index on success, -1 otherwise
 o addLong
 public final int addLong(long n)
Add a new long constant to the ConstantPool, if it is not already in there.

Parameters:
n - Long number to add
Returns:
index of entry
 o lookupDouble
 public final int lookupDouble(double n)
Look for ConstantDouble in ConstantPool.

Parameters:
n - Double number to look for
Returns:
index on success, -1 otherwise
 o addDouble
 public final int addDouble(double n)
Add a new double constant to the ConstantPool, if it is not already in there.

Parameters:
n - Double number to add
Returns:
index of entry
 o lookupNameAndType
 public final int lookupNameAndType(String name,
                                    String signature)
Look for ConstantNameAndType in ConstantPool.

Parameters:
name - of variable/method
signature - of variable/method
Returns:
index on success, -1 otherwise
 o addNameAndType
 public final int addNameAndType(String name,
                                 String signature)
Add a new NameAndType constant to the ConstantPool if it is not already in there.

Parameters:
n - NameAndType string to add
Returns:
index of entry
 o lookupMethodref
 public final int lookupMethodref(String class_name,
                                  String method_name,
                                  String signature)
Look for ConstantMethodref in ConstantPool.

Parameters:
class_name - Where to find method
method_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise
 o addMethodref
 public final int addMethodref(String class_name,
                               String method_name,
                               String signature)
Add a new Methodref constant to the ConstantPool, if it is not already in there.

Parameters:
n - Methodref string to add
Returns:
index of entry
 o lookupInterfaceMethodref
 public final int lookupInterfaceMethodref(String class_name,
                                           String method_name,
                                           String signature)
Look for ConstantInterfaceMethodref in ConstantPool.

Parameters:
class_name - Where to find method
method_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise
 o addInterfaceMethodref
 public final int addInterfaceMethodref(String class_name,
                                        String method_name,
                                        String signature)
Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there.

Parameters:
n - InterfaceMethodref string to add
Returns:
index of entry
 o lookupFieldref
 public final int lookupFieldref(String class_name,
                                 String field_name,
                                 String signature)
Look for ConstantFieldref in ConstantPool.

Parameters:
class_name - Where to find method
field_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise
 o addFieldref
 public final int addFieldref(String class_name,
                              String field_name,
                              String signature)
Add a new Fieldref constant to the ConstantPool, if it is not already in there.

Parameters:
n - Fieldref string to add
Returns:
index of entry
 o addConstant
 public final int addConstant(Constant c)
Add a given constant (without checking for double entries).

Parameters:
c - Constant to add
Returns:
index of entry
 o lookupConstant
 public final int lookupConstant(Constant c)
Look up constant in ConstantPool.

Parameters:
c - constant to look up
Returns:
index on success, -1 otherwise
 o getConstant
 public Constant getConstant(int i)
Parameters:
i - index in constant pool
Returns:
constant pool entry at index i
 o getConstantPool
 public ConstantPool getConstantPool()
Returns:
intermediate constant pool
 o getSize
 public int getSize()
Returns:
current size of constant pool
 o getFinalConstantPool
 public ConstantPool getFinalConstantPool()
Returns:
constant pool with proper length

All Packages  Class Hierarchy  This Package  Previous  Next  Index