javassist.bytecode

Class ConstPool

public final class ConstPool extends Object

Constant pool table.
Field Summary
static intCONST_Class
CONSTANT_Class
static intCONST_Double
CONSTANT_Double
static intCONST_Fieldref
CONSTANT_Fieldref
static intCONST_Float
CONSTANT_Float
static intCONST_Integer
CONSTANT_Integer
static intCONST_InterfaceMethodref
CONSTANT_InterfaceMethodref
static intCONST_Long
CONSTANT_Long
static intCONST_Methodref
CONSTANT_Methodref
static intCONST_NameAndType
CONSTANT_NameAndType
static intCONST_String
CONSTANT_String
static intCONST_Utf8
CONSTANT_Utf8
static CtClassTHIS
Represents the class using this constant pool table.
Constructor Summary
ConstPool(String thisclass)
Constructs a constant pool table.
ConstPool(DataInputStream in)
Constructs a constant pool table from the given byte stream.
Method Summary
intaddClassInfo(CtClass c)
Adds a new CONSTANT_Class_info structure.
intaddClassInfo(String qname)
Adds a new CONSTANT_Class_info structure.
intaddDoubleInfo(double d)
Adds a new CONSTANT_Double_info structure.
intaddFieldrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_Fieldref_info structure.
intaddFieldrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_Fieldref_info structure.
intaddFloatInfo(float f)
Adds a new CONSTANT_Float_info structure.
intaddIntegerInfo(int i)
Adds a new CONSTANT_Integer_info structure.
intaddInterfaceMethodrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_InterfaceMethodref_info structure.
intaddInterfaceMethodrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_InterfaceMethodref_info structure.
intaddLongInfo(long l)
Adds a new CONSTANT_Long_info structure.
intaddMethodrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_Methodref_info structure.
intaddMethodrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_Methodref_info structure.
intaddNameAndTypeInfo(String name, String type)
Adds a new CONSTANT_NameAndType_info structure.
intaddNameAndTypeInfo(int name, int type)
Adds a new CONSTANT_NameAndType_info structure.
intaddStringInfo(String str)
Adds a new CONSTANT_String_info structure.
intaddUtf8Info(String utf8)
Adds a new CONSTANT_Utf8_info structure.
intcopy(int n, ConstPool dest, Map classnames)
Copies the n-th item in this ConstPool object into the destination ConstPool object.
StringgetClassInfo(int index)
Reads CONSTANT_Class_info structure at the given index.
StringgetClassName()
Returns the name of the class using this constant pool table.
SetgetClassNames()
Get all the class names.
doublegetDoubleInfo(int index)
Reads CONSTANT_Double_info structure at the given index.
intgetFieldrefClass(int index)
Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
StringgetFieldrefClassName(int index)
Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.
StringgetFieldrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
intgetFieldrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_Fieldref_info structure at the given index.
StringgetFieldrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
floatgetFloatInfo(int index)
Reads CONSTANT_Float_info structure at the given index.
intgetIntegerInfo(int index)
Reads CONSTANT_Integer_info structure at the given index.
intgetInterfaceMethodrefClass(int index)
Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
StringgetInterfaceMethodrefClassName(int index)
Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
StringgetInterfaceMethodrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
intgetInterfaceMethodrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.
StringgetInterfaceMethodrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
ObjectgetLdcValue(int index)
Reads CONSTANT_Integer_info, _Float_info, _Long_info, _Double_info, or _String_info structure.
longgetLongInfo(int index)
Reads CONSTANT_Long_info structure at the given index.
intgetMethodrefClass(int index)
Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
StringgetMethodrefClassName(int index)
Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.
StringgetMethodrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
intgetMethodrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_Methodref_info structure at the given index.
StringgetMethodrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.
intgetNameAndTypeDescriptor(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure at the given index.
intgetNameAndTypeName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure at the given index.
intgetSize()
Returns the number of entries in this table.
StringgetStringInfo(int index)
Reads CONSTANT_String_info structure at the given index.
intgetTag(int index)
Returns the tag field of the constant pool table entry at the given index.
intgetThisClassInfo()
Returns the index of CONSTANT_Class_info structure specifying the class using this constant pool table.
StringgetUtf8Info(int index)
Reads CONSTANT_utf8_info structure at the given index.
intisConstructor(String classname, int index)
Determines whether CONSTANT_Methodref_info structure at the given index represents the constructor of the given class.
intisMember(String classname, String membername, int index)
Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index represents the member with the specified name and declaring class.
voidprint()
Prints the contents of the constant pool table.
voidprint(PrintWriter out)
Prints the contents of the constant pool table.
voidrenameClass(String oldName, String newName)
Replaces all occurrences of a class name.
voidrenameClass(Map classnames)
Replaces all occurrences of class names.
voidwrite(DataOutputStream out)
Writes the contents of the constant pool table.

Field Detail

CONST_Class

public static final int CONST_Class
CONSTANT_Class

CONST_Double

public static final int CONST_Double
CONSTANT_Double

CONST_Fieldref

public static final int CONST_Fieldref
CONSTANT_Fieldref

CONST_Float

public static final int CONST_Float
CONSTANT_Float

CONST_Integer

public static final int CONST_Integer
CONSTANT_Integer

CONST_InterfaceMethodref

public static final int CONST_InterfaceMethodref
CONSTANT_InterfaceMethodref

CONST_Long

public static final int CONST_Long
CONSTANT_Long

CONST_Methodref

public static final int CONST_Methodref
CONSTANT_Methodref

CONST_NameAndType

public static final int CONST_NameAndType
CONSTANT_NameAndType

CONST_String

public static final int CONST_String
CONSTANT_String

CONST_Utf8

public static final int CONST_Utf8
CONSTANT_Utf8

THIS

public static final CtClass THIS
Represents the class using this constant pool table.

Constructor Detail

ConstPool

public ConstPool(String thisclass)
Constructs a constant pool table.

Parameters: thisclass the name of the class using this constant pool table

ConstPool

public ConstPool(DataInputStream in)
Constructs a constant pool table from the given byte stream.

Parameters: in byte stream.

Method Detail

addClassInfo

public int addClassInfo(CtClass c)
Adds a new CONSTANT_Class_info structure.

This also adds a CONSTANT_Utf8_info structure for storing the class name.

Returns: the index of the added entry.

addClassInfo

public int addClassInfo(String qname)
Adds a new CONSTANT_Class_info structure.

This also adds a CONSTANT_Utf8_info structure for storing the class name.

Parameters: qname a fully-qualified class name (or the JVM-internal representation of that name).

Returns: the index of the added entry.

addDoubleInfo

public int addDoubleInfo(double d)
Adds a new CONSTANT_Double_info structure.

Returns: the index of the added entry.

addFieldrefInfo

public int addFieldrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_Fieldref_info structure.

This also adds a new CONSTANT_NameAndType_info structure.

Parameters: classInfo class_index name name_index of CONSTANT_NameAndType_info. type descriptor_index of CONSTANT_NameAndType_info.

Returns: the index of the added entry.

addFieldrefInfo

public int addFieldrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_Fieldref_info structure.

Parameters: classInfo class_index nameAndTypeInfo name_and_type_index.

Returns: the index of the added entry.

addFloatInfo

public int addFloatInfo(float f)
Adds a new CONSTANT_Float_info structure.

Returns: the index of the added entry.

addIntegerInfo

public int addIntegerInfo(int i)
Adds a new CONSTANT_Integer_info structure.

Returns: the index of the added entry.

addInterfaceMethodrefInfo

public int addInterfaceMethodrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_InterfaceMethodref_info structure.

This also adds a new CONSTANT_NameAndType_info structure.

Parameters: classInfo class_index name name_index of CONSTANT_NameAndType_info. type descriptor_index of CONSTANT_NameAndType_info.

Returns: the index of the added entry.

addInterfaceMethodrefInfo

public int addInterfaceMethodrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_InterfaceMethodref_info structure.

Parameters: classInfo class_index nameAndTypeInfo name_and_type_index.

Returns: the index of the added entry.

addLongInfo

public int addLongInfo(long l)
Adds a new CONSTANT_Long_info structure.

Returns: the index of the added entry.

addMethodrefInfo

public int addMethodrefInfo(int classInfo, String name, String type)
Adds a new CONSTANT_Methodref_info structure.

This also adds a new CONSTANT_NameAndType_info structure.

Parameters: classInfo class_index name name_index of CONSTANT_NameAndType_info. type descriptor_index of CONSTANT_NameAndType_info.

Returns: the index of the added entry.

addMethodrefInfo

public int addMethodrefInfo(int classInfo, int nameAndTypeInfo)
Adds a new CONSTANT_Methodref_info structure.

Parameters: classInfo class_index nameAndTypeInfo name_and_type_index.

Returns: the index of the added entry.

addNameAndTypeInfo

public int addNameAndTypeInfo(String name, String type)
Adds a new CONSTANT_NameAndType_info structure.

This also adds CONSTANT_Utf8_info structures.

Parameters: name name_index type descriptor_index

Returns: the index of the added entry.

addNameAndTypeInfo

public int addNameAndTypeInfo(int name, int type)
Adds a new CONSTANT_NameAndType_info structure.

Parameters: name name_index type descriptor_index

Returns: the index of the added entry.

addStringInfo

public int addStringInfo(String str)
Adds a new CONSTANT_String_info structure.

This also adds a new CONSTANT_Utf8_info structure.

Returns: the index of the added entry.

addUtf8Info

public int addUtf8Info(String utf8)
Adds a new CONSTANT_Utf8_info structure.

If the given utf8 string has been already recorded in the table, then this method does not add a new entry to avoid adding a duplicated entry. Instead, it returns the index of the entry already recorded.

Returns: the index of the added entry.

copy

public int copy(int n, ConstPool dest, Map classnames)
Copies the n-th item in this ConstPool object into the destination ConstPool object. The class names that the item refers to are renamed according to the given map.

Parameters: n the n-th item dest destination constant pool table classnames the map or null.

Returns: the index of the copied item into the destination ClassPool.

getClassInfo

public String getClassInfo(int index)
Reads CONSTANT_Class_info structure at the given index.

Returns: a fully-qualified class or interface name specified by name_index.

getClassName

public String getClassName()
Returns the name of the class using this constant pool table.

getClassNames

public Set getClassNames()
Get all the class names.

Returns: a set of class names

getDoubleInfo

public double getDoubleInfo(int index)
Reads CONSTANT_Double_info structure at the given index.

Returns: the value specified by this entry.

getFieldrefClass

public int getFieldrefClass(int index)
Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.

getFieldrefClassName

public String getFieldrefClassName(int index)
Reads the class_index field of the CONSTANT_Fieldref_info structure at the given index.

Returns: the name of the class at that class_index.

getFieldrefName

public String getFieldrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_Fieldref_info.

Returns: the name of the field.

getFieldrefNameAndType

public int getFieldrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_Fieldref_info structure at the given index.

getFieldrefType

public String getFieldrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_Fieldref_info.

Returns: the type descriptor of the field.

getFloatInfo

public float getFloatInfo(int index)
Reads CONSTANT_Float_info structure at the given index.

Returns: the value specified by this entry.

getIntegerInfo

public int getIntegerInfo(int index)
Reads CONSTANT_Integer_info structure at the given index.

Returns: the value specified by this entry.

getInterfaceMethodrefClass

public int getInterfaceMethodrefClass(int index)
Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.

getInterfaceMethodrefClassName

public String getInterfaceMethodrefClassName(int index)
Reads the class_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.

Returns: the name of the class at that class_index.

getInterfaceMethodrefName

public String getInterfaceMethodrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_InterfaceMethodref_info.

Returns: the name of the method.

getInterfaceMethodrefNameAndType

public int getInterfaceMethodrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_InterfaceMethodref_info structure at the given index.

getInterfaceMethodrefType

public String getInterfaceMethodrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_InterfaceMethodref_info.

Returns: the descriptor of the method.

getLdcValue

public Object getLdcValue(int index)
Reads CONSTANT_Integer_info, _Float_info, _Long_info, _Double_info, or _String_info structure. These are used with the LDC instruction.

Returns: a String value or a wrapped primitive-type value.

getLongInfo

public long getLongInfo(int index)
Reads CONSTANT_Long_info structure at the given index.

Returns: the value specified by this entry.

getMethodrefClass

public int getMethodrefClass(int index)
Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.

getMethodrefClassName

public String getMethodrefClassName(int index)
Reads the class_index field of the CONSTANT_Methodref_info structure at the given index.

Returns: the name of the class at that class_index.

getMethodrefName

public String getMethodrefName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_Methodref_info.

Returns: the name of the method.

getMethodrefNameAndType

public int getMethodrefNameAndType(int index)
Reads the name_and_type_index field of the CONSTANT_Methodref_info structure at the given index.

getMethodrefType

public String getMethodrefType(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure indirectly specified by the given index.

Parameters: index an index to a CONSTANT_Methodref_info.

Returns: the descriptor of the method.

getNameAndTypeDescriptor

public int getNameAndTypeDescriptor(int index)
Reads the descriptor_index field of the CONSTANT_NameAndType_info structure at the given index.

getNameAndTypeName

public int getNameAndTypeName(int index)
Reads the name_index field of the CONSTANT_NameAndType_info structure at the given index.

getSize

public int getSize()
Returns the number of entries in this table.

getStringInfo

public String getStringInfo(int index)
Reads CONSTANT_String_info structure at the given index.

Returns: the string specified by string_index.

getTag

public int getTag(int index)
Returns the tag field of the constant pool table entry at the given index.

getThisClassInfo

public int getThisClassInfo()
Returns the index of CONSTANT_Class_info structure specifying the class using this constant pool table.

getUtf8Info

public String getUtf8Info(int index)
Reads CONSTANT_utf8_info structure at the given index.

Returns: the string specified by this entry.

isConstructor

public int isConstructor(String classname, int index)
Determines whether CONSTANT_Methodref_info structure at the given index represents the constructor of the given class.

Returns: the descriptor_index specifying the type descriptor of the that constructor. If it is not that constructor, isConstructor() returns 0.

isMember

public int isMember(String classname, String membername, int index)
Determines whether CONSTANT_Methodref_info, CONSTANT_Fieldref_info, or CONSTANT_InterfaceMethodref_info structure at the given index represents the member with the specified name and declaring class.

Parameters: classname the class declaring the member membername the member name index the index into the constant pool table

Returns: the descriptor_index specifying the type descriptor of that member. If it is not that member, isMember() returns 0.

print

public void print()
Prints the contents of the constant pool table.

print

public void print(PrintWriter out)
Prints the contents of the constant pool table.

renameClass

public void renameClass(String oldName, String newName)
Replaces all occurrences of a class name.

Parameters: oldName the replaced name (JVM-internal representation). newName the substituted name (JVM-internal representation).

renameClass

public void renameClass(Map classnames)
Replaces all occurrences of class names.

Parameters: classnames specifies pairs of replaced and substituted name.

write

public void write(DataOutputStream out)
Writes the contents of the constant pool table.
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.