This class is used to 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.
addArrayClass
public int addArrayClass(ArrayType type)
Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
instruction, e.g. to the ConstantPool.
type
- type of array class
addClass
public int addClass(String str)
Add a new Class reference to the ConstantPool, if it is not already in there.
addClass
public int addClass(ObjectType type)
Add a new Class reference to the ConstantPool for a given type.
addConstant
public int addConstant(Constant c,
ConstantPoolGen cp)
Import constant from another ConstantPool and return new index.
addDouble
public int addDouble(double n)
Add a new double constant to the ConstantPool, if it is not already in there.
addFieldref
public 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.
addFloat
public int addFloat(float n)
Add a new Float constant to the ConstantPool, if it is not already in there.
addInteger
public int addInteger(int n)
Add a new Integer constant to the ConstantPool, if it is not already in there.
n
- integer number to add
addInterfaceMethodref
public 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.
addInterfaceMethodref
public int addInterfaceMethodref(MethodGen method)
addLong
public int addLong(long n)
Add a new long constant to the ConstantPool, if it is not already in there.
addMethodref
public 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.
addMethodref
public int addMethodref(MethodGen method)
addNameAndType
public int addNameAndType(String name,
String signature)
Add a new NameAndType constant to the ConstantPool if it is not already
in there.
addString
public int addString(String str)
Add a new String constant to the ConstantPool, if it is not already in there.
addUtf8
public int addUtf8(String n)
Add a new Utf8 constant to the ConstantPool, if it is not already in there.
adjustSize
protected void adjustSize()
Resize internal array of constants.
getConstant
public Constant getConstant(int i)
i
- index in constant pool
- constant pool entry at index i
getConstantPool
public ConstantPool getConstantPool()
- intermediate constant pool
getFinalConstantPool
public ConstantPool getFinalConstantPool()
- constant pool with proper length
getSize
public int getSize()
- current size of constant pool
lookupClass
public int lookupClass(String str)
Look for ConstantClass in ConstantPool named `str'.
str
- String to search for
- index on success, -1 otherwise
lookupDouble
public int lookupDouble(double n)
Look for ConstantDouble in ConstantPool.
n
- Double number to look for
- index on success, -1 otherwise
lookupFieldref
public int lookupFieldref(String class_name,
String field_name,
String signature)
Look for ConstantFieldref in ConstantPool.
class_name
- Where to find methodfield_name
- Guess whatsignature
- return and argument types
- index on success, -1 otherwise
lookupFloat
public int lookupFloat(float n)
Look for ConstantFloat in ConstantPool.
n
- Float number to look for
- index on success, -1 otherwise
lookupInteger
public int lookupInteger(int n)
Look for ConstantInteger in ConstantPool.
n
- integer number to look for
- index on success, -1 otherwise
lookupInterfaceMethodref
public int lookupInterfaceMethodref(String class_name,
String method_name,
String signature)
Look for ConstantInterfaceMethodref in ConstantPool.
class_name
- Where to find methodmethod_name
- Guess whatsignature
- return and argument types
- index on success, -1 otherwise
lookupInterfaceMethodref
public int lookupInterfaceMethodref(MethodGen method)
lookupLong
public int lookupLong(long n)
Look for ConstantLong in ConstantPool.
n
- Long number to look for
- index on success, -1 otherwise
lookupMethodref
public int lookupMethodref(String class_name,
String method_name,
String signature)
Look for ConstantMethodref in ConstantPool.
class_name
- Where to find methodmethod_name
- Guess whatsignature
- return and argument types
- index on success, -1 otherwise
lookupMethodref
public int lookupMethodref(MethodGen method)
lookupNameAndType
public int lookupNameAndType(String name,
String signature)
Look for ConstantNameAndType in ConstantPool.
name
- of variable/methodsignature
- of variable/method
- index on success, -1 otherwise
lookupString
public int lookupString(String str)
Look for ConstantString in ConstantPool containing String `str'.
str
- String to search for
- index on success, -1 otherwise
lookupUtf8
public int lookupUtf8(String n)
Look for ConstantUtf8 in ConstantPool.
n
- Utf8 string to look for
- index on success, -1 otherwise
setConstant
public void setConstant(int i,
Constant c)
Use with care!
i
- index in constant poolc
- new constant pool entry at index i
toString
public String toString()