jellyj.classfile.classgen
Class ConstantPoolGen


public final class ConstantPoolGen
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.

Author:
JellyJ Design Group
See Also: Constant

Constructor Summary
ConstantPoolGen(Constant[] c)
          Initialize with given array of constants.
ConstantPoolGen(ConstantPool cp)
          Initialize with given constant pool.
ConstantPoolGen()
          Create empty constant pool.

Method Summary
 final intaddClass(String str)
          Add a new Class reference to the ConstantPool, if it is not already in there.
 final intaddConstant(Constant c)
          Add a given constant (without checking for double entries).
 final intaddDouble(double n)
          Add a new double constant to the ConstantPool, if it is not already in there.
 final intaddFieldref(String class_name, String field_name, String signature)
          Add a new Fieldref constant to the ConstantPool, if it is not already in there.
 final intaddFloat(float n)
          Add a new Float constant to the ConstantPool, if it is not already in there.
 final intaddInteger(int n)
          Add a new Integer constant to the ConstantPool, if it is not already in there.
 final intaddInterfaceMethodref(String class_name, String method_name, String signature)
          Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there.
 final intaddLong(long n)
          Add a new long constant to the ConstantPool, if it is not already in there.
 final intaddMethodref(String class_name, String method_name, String signature)
          Add a new Methodref constant to the ConstantPool, if it is not already in there.
 final intaddNameAndType(String name, String signature)
          Add a new NameAndType constant to the ConstantPool if it is not already in there.
 final intaddString(String str)
          Add a new String constant to the ConstantPool, if it is not already in there.
 final intaddUnicode(String n)
          Add a new Unicode constant to the ConstantPool, if it is not already in there.
 final intaddUtf8(String n)
          Add a new Utf8 constant to the ConstantPool, if it is not already in there.
 ConstantgetConstant(int i)
           
 ConstantPoolgetConstantPool()
           
 ConstantPoolgetFinalConstantPool()
           
 intgetSize()
           
 final intlookupClass(String str)
          Look for ConstantClass in ConstantPool named `str'.
 final intlookupConstant(Constant c)
          Look up constant in ConstantPool.
 final intlookupDouble(double n)
          Look for ConstantDouble in ConstantPool.
 final intlookupFieldref(String class_name, String field_name, String signature)
          Look for ConstantFieldref in ConstantPool.
 final intlookupFloat(float n)
          Look for ConstantFloat in ConstantPool.
 final intlookupInteger(int n)
          Look for ConstantInteger in ConstantPool.
 final intlookupInterfaceMethodref(String class_name, String method_name, String signature)
          Look for ConstantInterfaceMethodref in ConstantPool.
 final intlookupLong(long n)
          Look for ConstantLong in ConstantPool.
 final intlookupMethodref(String class_name, String method_name, String signature)
          Look for ConstantMethodref in ConstantPool.
 final intlookupNameAndType(String name, String signature)
          Look for ConstantNameAndType in ConstantPool.
 final intlookupString(String str)
          Look for ConstantString in ConstantPool containing String `str'.
 final intlookupUnicode(String n)
          Look for ConstantUnicode in ConstantPool.
 final intlookupUtf8(String n)
          Look for ConstantUtf8 in ConstantPool.

Constructor Detail

ConstantPoolGen

public ConstantPoolGen(Constant[] c)
Initialize with given array of constants.
Parameters:
c - array of given constants, new ones will be appended

ConstantPoolGen

public ConstantPoolGen(ConstantPool cp)
Initialize with given constant pool.

ConstantPoolGen

public ConstantPoolGen()
Create empty constant pool.
Method Detail

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

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

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

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

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

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

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

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

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

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

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

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

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

getConstant

public Constant getConstant(int i)
Parameters:
i - index in constant pool
Returns: constant pool entry at index i

getConstantPool

public ConstantPool getConstantPool()
Returns: intermediate constant pool

getFinalConstantPool

public ConstantPool getFinalConstantPool()
Returns: constant pool with proper length

getSize

public int getSize()
Returns: current size of constant pool

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

lookupConstant

public final int lookupConstant(Constant c)
Look up constant in ConstantPool.
Parameters:
c - constant to look up
Returns: index on success, -1 otherwise

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

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

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

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

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

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

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

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

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

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

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

Association Links

to Class jellyj.classfile.javaclass.Constant

to Class jellyj.classfile.javaclass.ConstantPool