bcel API: Class ConstantPoolGen
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.bcel.generic.ConstantPoolGen
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.
Constant
Field Summary | |
protected Constant[] |
constants
|
protected int |
index
|
protected int |
size
|
Constructor Summary | |
ConstantPoolGen()
Create empty constant pool. |
|
ConstantPoolGen(Constant[] cs)
Initialize with given array of constants. |
|
ConstantPoolGen(ConstantPool cp)
Initialize with given constant pool. |
Method Summary | |
int |
addArrayClass(ArrayType type)
Add a reference to an array class (e.g. |
int |
addClass(ObjectType type)
Add a new Class reference to the ConstantPool for a given type. |
int |
addClass(java.lang.String str)
Add a new Class reference to the ConstantPool, if it is not already in there. |
int |
addConstant(Constant c,
ConstantPoolGen cp)
Import constant from another ConstantPool and return new index. |
int |
addDouble(double n)
Add a new double constant to the ConstantPool, if it is not already in there. |
int |
addFieldref(java.lang.String class_name,
java.lang.String field_name,
java.lang.String signature)
Add a new Fieldref constant to the ConstantPool, if it is not already in there. |
int |
addFloat(float n)
Add a new Float constant to the ConstantPool, if it is not already in there. |
int |
addInteger(int n)
Add a new Integer constant to the ConstantPool, if it is not already in there. |
int |
addInterfaceMethodref(MethodGen method)
|
int |
addInterfaceMethodref(java.lang.String class_name,
java.lang.String method_name,
java.lang.String signature)
Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there. |
int |
addLong(long n)
Add a new long constant to the ConstantPool, if it is not already in there. |
int |
addMethodref(MethodGen method)
|
int |
addMethodref(java.lang.String class_name,
java.lang.String method_name,
java.lang.String signature)
Add a new Methodref constant to the ConstantPool, if it is not already in there. |
int |
addNameAndType(java.lang.String name,
java.lang.String signature)
Add a new NameAndType constant to the ConstantPool if it is not already in there. |
int |
addString(java.lang.String str)
Add a new String constant to the ConstantPool, if it is not already in there. |
int |
addUtf8(java.lang.String n)
Add a new Utf8 constant to the ConstantPool, if it is not already in there. |
protected void |
adjustSize()
Resize internal array of constants. |
Constant |
getConstant(int i)
|
ConstantPool |
getConstantPool()
|
ConstantPool |
getFinalConstantPool()
|
int |
getSize()
|
int |
lookupClass(java.lang.String str)
Look for ConstantClass in ConstantPool named `str'. |
int |
lookupDouble(double n)
Look for ConstantDouble in ConstantPool. |
int |
lookupFieldref(java.lang.String class_name,
java.lang.String field_name,
java.lang.String signature)
Look for ConstantFieldref in ConstantPool. |
int |
lookupFloat(float n)
Look for ConstantFloat in ConstantPool. |
int |
lookupInteger(int n)
Look for ConstantInteger in ConstantPool. |
int |
lookupInterfaceMethodref(MethodGen method)
|
int |
lookupInterfaceMethodref(java.lang.String class_name,
java.lang.String method_name,
java.lang.String signature)
Look for ConstantInterfaceMethodref in ConstantPool. |
int |
lookupLong(long n)
Look for ConstantLong in ConstantPool. |
int |
lookupMethodref(MethodGen method)
|
int |
lookupMethodref(java.lang.String class_name,
java.lang.String method_name,
java.lang.String signature)
Look for ConstantMethodref in ConstantPool. |
int |
lookupNameAndType(java.lang.String name,
java.lang.String signature)
Look for ConstantNameAndType in ConstantPool. |
int |
lookupString(java.lang.String str)
Look for ConstantString in ConstantPool containing String `str'. |
int |
lookupUtf8(java.lang.String n)
Look for ConstantUtf8 in ConstantPool. |
void |
setConstant(int i,
Constant c)
Use with care! |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int size
protected Constant[] constants
protected int index
Constructor Detail |
public ConstantPoolGen(Constant[] cs)
c
- array of given constants, new ones will be appendedpublic ConstantPoolGen(ConstantPool cp)
public ConstantPoolGen()
Method Detail |
protected void adjustSize()
public int lookupString(java.lang.String str)
str
- String to search forpublic int addString(java.lang.String str)
str
- String to addpublic int lookupClass(java.lang.String str)
str
- String to search forpublic int addClass(java.lang.String str)
str
- Class to addpublic int addClass(ObjectType type)
str
- Class to addpublic int addArrayClass(ArrayType type)
type
- type of array classpublic int lookupInteger(int n)
n
- integer number to look forpublic int addInteger(int n)
n
- integer number to addpublic int lookupFloat(float n)
n
- Float number to look forpublic int addFloat(float n)
n
- Float number to addpublic int lookupUtf8(java.lang.String n)
n
- Utf8 string to look forpublic int addUtf8(java.lang.String n)
n
- Utf8 string to addpublic int lookupLong(long n)
n
- Long number to look forpublic int addLong(long n)
n
- Long number to addpublic int lookupDouble(double n)
n
- Double number to look forpublic int addDouble(double n)
n
- Double number to addpublic int lookupNameAndType(java.lang.String name, java.lang.String signature)
name
- of variable/methodsignature
- of variable/methodpublic int addNameAndType(java.lang.String name, java.lang.String signature)
n
- NameAndType string to addpublic int lookupMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
class_name
- Where to find methodmethod_name
- Guess whatsignature
- return and argument typespublic int lookupMethodref(MethodGen method)
public int addMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
n
- Methodref string to addpublic int addMethodref(MethodGen method)
public int lookupInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
class_name
- Where to find methodmethod_name
- Guess whatsignature
- return and argument typespublic int lookupInterfaceMethodref(MethodGen method)
public int addInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
n
- InterfaceMethodref string to addpublic int addInterfaceMethodref(MethodGen method)
public int lookupFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)
class_name
- Where to find methodfield_name
- Guess whatsignature
- return and argument typespublic int addFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)
n
- Fieldref string to addpublic Constant getConstant(int i)
i
- index in constant poolpublic void setConstant(int i, Constant c)
i
- index in constant poolc
- new constant pool entry at index ipublic ConstantPool getConstantPool()
public int getSize()
public ConstantPool getFinalConstantPool()
public java.lang.String toString()
toString
in class java.lang.Object
public int addConstant(Constant c, ConstantPoolGen cp)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |