jreversepro.reflect
Class JConstantPool

java.lang.Object
  extended by jreversepro.reflect.JConstantPool
All Implemented Interfaces:
KeyWords

public class JConstantPool
extends java.lang.Object
implements KeyWords

JConstantPool represents the abstraction of the ConstantPool.

Author:
Karthik Kumar

Field Summary
static int PTR_INVALID
          PTR_INVALID of a pointer of a ConstantPool tag means that they are not applicable for that ConstantPool tag.
static java.lang.String STR_INVALID
          STR_INVALID corresponds to an invalid entry in the ConstantPool.
static int TAG_CLASS
          TAG_CLASS corresponds to CONSTANT_CLASS
static int TAG_DOUBLE
          TAG_DOUBLE corresponds to CONSTANT_DOUBLE
static int TAG_FIELDREF
          TAG_FIELDREF corresponds to CONSTANT_FIELDREF
static int TAG_FLOAT
          TAG_FLOAT corresponds to CONSTANT_FLOAT
static int TAG_INTEGER
          TAG_INTEGER corresponds to CONSTANT_INTEGER
static int TAG_INTERFACEREF
          TAG_INTERFACEREF corresponds to CONSTANT_INTERFACEREF
static int TAG_LONG
          TAG_LONG corresponds to CONSTANT_LONG
static int TAG_METHODREF
          TAG_METHODREF corresponds to CONSTANT_METHODREF
static int TAG_NAMETYPE
          TAG_NAMETYPE corresponds to CONSTANT_NAMETYPE
static int TAG_NOTHING
          TAG_NOTHING means that the ConstantPool Entry is invalid.
static int TAG_STRING
          TAG_STRING corresponds to CONSTANT_STRING
static int TAG_UTF8
          TAG_UTF8 corresponds to CONSTANT_UTF8
 
Fields inherited from interface jreversepro.common.KeyWords
ANY, BOOLEAN, BREAK, BYTE, CASE, CHAR, CLASS, CLASS_STRING, CLINIT, CLOSE_BRACKET, COND_AND, COND_NOT, COND_OR, CONTINUE, DEFAULT, DEFAULT_PACKAGE, DOUBLE, EQUALTO, FALSE, FLOAT, FOREIGN_CLASS, FOREIGN_OBJ, GOTO, INIT, INSTANCEOF, INT, INTERFACE, JVM_BOOLEAN, JVM_CHAR, JVM_VOID, LANG_OBJECT, LENGTH, LONG, NEW, NULL, OPEN_BRACKET, OPR_EQ, OPR_GE, OPR_GT, OPR_LE, OPR_LT, OPR_NE, OPR_NOT, REFERENCE, RET_ADDR, RETURN, SHORT, SPACE, STATIC, SUPER, SWITCH, THIS, THISCLASS, THROW, TRUE, VOID
 
Constructor Summary
JConstantPool(int cpMax)
          Constructor.
 
Method Summary
 void addClassEntry(int classIndex)
          Adds a new TAG_CLASS entry to the constantpool.
 void addDoubleEntry(java.lang.String value)
          Adds a new TAG_DOUBLE entry to the constantpool.
 void addFieldRefEntry(int ptr1, int ptr2)
          Adds a new TAG_FIELDREF entry to the constantpool.
 void addFloatEntry(java.lang.String value)
          Adds a new TAG_FLOAT entry to the constantpool.
 void addIntegerEntry(java.lang.String value)
          Adds a new TAG_INTEGER entry to the constantpool.
 void addInterfaceRefEntry(int ptr1, int ptr2)
          Adds a new TAG_INTERFACEREF entry to the constantpool.
 void addLongEntry(java.lang.String value)
          Adds a new TAG_LONG entry to the constantpool.
 void addMethodRefEntry(int ptr1, int ptr2)
          Adds a new TAG_METHODREF entry to the constantpool.
 void addNameTypeEntry(int ptr1, int ptr2)
          Adds a new TAG_NAMETYPE entry to the constantpool.
 void addNullEntry()
          Adds a NULL entry to the ConstantPool.
 void addStringEntry(int stringIndex)
          Adds a new TAG_STRING entry to the constantpool.
 void addUtf8Entry(java.lang.String value)
          Adds a new TAG_UTF8 entry to the constantpool.
 java.lang.String getBasicDataTypeValue(int index)
          Returns the value for the ConstantPool Entries according to their types.
 java.lang.String getClassName(int index)
          Given an index to TAG_CLASS this returns the class name pointed to by it.
 java.lang.String getCpValue(int index)
          Returns the ConstantPool value.
 java.lang.String getDataType(int index)
          Returns the data type of the given ConstantPool Index.
 java.util.List<JConstantPoolEntry> getEntries()
          Returns the constantpool entries.
 java.lang.String getEntryInfo()
          Returns the whole ConstantPool info in a formatter manner.
 java.lang.String getEntryInfo(int cpIndex)
          Returns the name pointed to by this JConstantPoolEntry.
 java.lang.String getFieldName(int index)
          Given an index to TAG_NAMETYPE this returns the name of the member ( field / method )
 java.lang.String getFieldType(int index)
          Given an index to TAG_NAMETYPE this returns the type of the member ( field / method )
 java.lang.String getFirstDirectName(int index)
          Returns the Utf8 value pointed by the first pointer of the index to the ConstantPool.
 JImport getImportedClasses()
          The constantpool is the one and only source that contains the references to external types.
 java.lang.String getLdcString(int index)
          Given an Cp index this returns the proper constant pool value depending on the tag type.
 int getMaxCpEntry()
          Returns the number of ConstantPool Entries.
 java.lang.String getName(JConstantPoolEntry ent)
          Returns the name pointed to by this JConstantPoolEntry.
 int getPtr1(int index)
          Returns the first pointer of the ConstantPool Data.
 int getPtr2(int index)
          Returns the second pointer of the ConstantPool Data.
 java.lang.String getSecondDirectName(int index)
          Returns the Utf8 value pointed by the II pointer of the index to the ConstantPool.
 int getTagByte(int index)
          Returns the tagbyte of the ConstantPool.
 java.lang.String getTagDescriptor(int index)
          Describes the tag in brief.
static java.lang.String getTagName(int tagByte)
          Returns the actual name of the tag .
 java.lang.String getType(JConstantPoolEntry ent)
          Returns the type pointed to by this JConstantPoolEntry.
 java.lang.String getUtf8String(int index)
          Given an index to TAG_UTF8 this returns the string value.
 boolean isTagDouble(int index)
          Returns if the given index to the ConstantPool is TAG_DOUBLE or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STR_INVALID

public static final java.lang.String STR_INVALID
STR_INVALID corresponds to an invalid entry in the ConstantPool.

See Also:
Constant Field Values

PTR_INVALID

public static final int PTR_INVALID
PTR_INVALID of a pointer of a ConstantPool tag means that they are not applicable for that ConstantPool tag.

See Also:
Constant Field Values

TAG_NOTHING

public static final int TAG_NOTHING
TAG_NOTHING means that the ConstantPool Entry is invalid.

See Also:
Constant Field Values

TAG_UTF8

public static final int TAG_UTF8
TAG_UTF8 corresponds to CONSTANT_UTF8

See Also:
Constant Field Values

TAG_INTEGER

public static final int TAG_INTEGER
TAG_INTEGER corresponds to CONSTANT_INTEGER

See Also:
Constant Field Values

TAG_FLOAT

public static final int TAG_FLOAT
TAG_FLOAT corresponds to CONSTANT_FLOAT

See Also:
Constant Field Values

TAG_LONG

public static final int TAG_LONG
TAG_LONG corresponds to CONSTANT_LONG

See Also:
Constant Field Values

TAG_DOUBLE

public static final int TAG_DOUBLE
TAG_DOUBLE corresponds to CONSTANT_DOUBLE

See Also:
Constant Field Values

TAG_CLASS

public static final int TAG_CLASS
TAG_CLASS corresponds to CONSTANT_CLASS

See Also:
Constant Field Values

TAG_STRING

public static final int TAG_STRING
TAG_STRING corresponds to CONSTANT_STRING

See Also:
Constant Field Values

TAG_FIELDREF

public static final int TAG_FIELDREF
TAG_FIELDREF corresponds to CONSTANT_FIELDREF

See Also:
Constant Field Values

TAG_METHODREF

public static final int TAG_METHODREF
TAG_METHODREF corresponds to CONSTANT_METHODREF

See Also:
Constant Field Values

TAG_INTERFACEREF

public static final int TAG_INTERFACEREF
TAG_INTERFACEREF corresponds to CONSTANT_INTERFACEREF

See Also:
Constant Field Values

TAG_NAMETYPE

public static final int TAG_NAMETYPE
TAG_NAMETYPE corresponds to CONSTANT_NAMETYPE

See Also:
Constant Field Values
Constructor Detail

JConstantPool

public JConstantPool(int cpMax)
Constructor.

Parameters:
cpMax - Maximum size of the ConstantPool.
Method Detail

getMaxCpEntry

public int getMaxCpEntry()
Returns the number of ConstantPool Entries.

Returns:
Returns the cp entry count.

getEntries

public java.util.List<JConstantPoolEntry> getEntries()
Returns the constantpool entries. The individual elements are JConstantPoolEntry.

Returns:
Returns list of constantpool entries.

addFieldRefEntry

public void addFieldRefEntry(int ptr1,
                             int ptr2)
Adds a new TAG_FIELDREF entry to the constantpool.

Parameters:
ptr1 - Pointer to TAG_CLASS
ptr2 - Pointer to TAG_NAMETYPE

addMethodRefEntry

public void addMethodRefEntry(int ptr1,
                              int ptr2)
Adds a new TAG_METHODREF entry to the constantpool.

Parameters:
ptr1 - Pointer to TAG_CLASS
ptr2 - Pointer to TAG_NAMETYPE

addInterfaceRefEntry

public void addInterfaceRefEntry(int ptr1,
                                 int ptr2)
Adds a new TAG_INTERFACEREF entry to the constantpool.

Parameters:
ptr1 - Pointer to TAG_CLASS
ptr2 - Pointer to TAG_NAMETYPE

addNameTypeEntry

public void addNameTypeEntry(int ptr1,
                             int ptr2)
Adds a new TAG_NAMETYPE entry to the constantpool.

Parameters:
ptr1 - Pointer to TAG_UTF8
ptr2 - Pointer to TAG_UTF8

addNullEntry

public void addNullEntry()
Adds a NULL entry to the ConstantPool. Mainly useful when we add long/ double.


addUtf8Entry

public void addUtf8Entry(java.lang.String value)
Adds a new TAG_UTF8 entry to the constantpool.

Parameters:
value - Value of the UTF8 String.

addIntegerEntry

public void addIntegerEntry(java.lang.String value)
Adds a new TAG_INTEGER entry to the constantpool.

Parameters:
value - Value of the integer.

addFloatEntry

public void addFloatEntry(java.lang.String value)
Adds a new TAG_FLOAT entry to the constantpool.

Parameters:
value - Value of the float number.

addDoubleEntry

public void addDoubleEntry(java.lang.String value)
Adds a new TAG_DOUBLE entry to the constantpool.

Parameters:
value - Value of the double.

addLongEntry

public void addLongEntry(java.lang.String value)
Adds a new TAG_LONG entry to the constantpool.

Parameters:
value - Value of the Long.

addClassEntry

public void addClassEntry(int classIndex)
Adds a new TAG_CLASS entry to the constantpool.

Parameters:
classIndex - Index to UTF8 string containing class name.

addStringEntry

public void addStringEntry(int stringIndex)
Adds a new TAG_STRING entry to the constantpool.

Parameters:
stringIndex - Index to the UTF8 string containing the stringvalue.

getDataType

public java.lang.String getDataType(int index)
Returns the data type of the given ConstantPool Index.

Parameters:
index - Index to the ConstantPool Entry.
Returns:
long/double/String/integer appropriately

isTagDouble

public boolean isTagDouble(int index)
Returns if the given index to the ConstantPool is TAG_DOUBLE or not.

Parameters:
index - Index to ConstantPool
Returns:
Returns true, if it is a TAG_DOUBLE. false, otherwise.

getPtr1

public int getPtr1(int index)
Returns the first pointer of the ConstantPool Data.

Parameters:
index - Index to ConstantPool
Returns:
Returns the integer.

getPtr2

public int getPtr2(int index)
Returns the second pointer of the ConstantPool Data.

Parameters:
index - Index to ConstantPool
Returns:
Returns the integer.

getTagByte

public int getTagByte(int index)
Returns the tagbyte of the ConstantPool.

Parameters:
index - Index to ConstantPool
Returns:
Returns the tag byte.

getCpValue

public java.lang.String getCpValue(int index)
Returns the ConstantPool value.

Parameters:
index - Index to ConstantPool
Returns:
Returns the value of that cp entry.

getFirstDirectName

public java.lang.String getFirstDirectName(int index)
Returns the Utf8 value pointed by the first pointer of the index to the ConstantPool. Say for example, if entry #6 has ptr1 to be #8 and the utf8 value of #8 is "MyString", this method on given input 6 returns "MyString".

Parameters:
index - Index to ConstantPool
Returns:
Returns a String a Utf8 value.

getSecondDirectName

public java.lang.String getSecondDirectName(int index)
Returns the Utf8 value pointed by the II pointer of the index to the ConstantPool. Say for example, if entry #6 has ptr2 to be #8 and the utf8 value of #8 is "MyString", this method on given input 6 returns "MyString".

Parameters:
index - Index to ConstantPool
Returns:
Returns a String a Utf8 value.

getClassName

public java.lang.String getClassName(int index)
Given an index to TAG_CLASS this returns the class name pointed to by it. If the index is 0 then a class of type ANY is returned.

Parameters:
index - Index to ConstantPool
Returns:
Returns a String - class name

getFieldName

public java.lang.String getFieldName(int index)
Given an index to TAG_NAMETYPE this returns the name of the member ( field / method )

Parameters:
index - Index to ConstantPool
Returns:
Returns name of the member

getFieldType

public java.lang.String getFieldType(int index)
Given an index to TAG_NAMETYPE this returns the type of the member ( field / method )

Parameters:
index - Index to ConstantPool
Returns:
Returns type of the member

getUtf8String

public java.lang.String getUtf8String(int index)
Given an index to TAG_UTF8 this returns the string value.

Parameters:
index - Index to ConstantPool
Returns:
Returns value of that Cp Entry.

getLdcString

public java.lang.String getLdcString(int index)
Given an Cp index this returns the proper constant pool value depending on the tag type. If TAG_INTEGER, returned as such. Else if TAG_STRING all the escape characters are properly quoted and returned.

Parameters:
index - Index to ConstantPool
Returns:
Returns value of that Cp Entry.

getImportedClasses

public JImport getImportedClasses()
The constantpool is the one and only source that contains the references to external types. Hence all the entries are analyzed for all external types referred to by this class and are consolidated into a class called JImport. This JImport can further be used to get the short form of classname etc.

Returns:
Reference to JImport.

getBasicDataTypeValue

public java.lang.String getBasicDataTypeValue(int index)
Returns the value for the ConstantPool Entries according to their types.

Parameters:
index - Index to ConstantPool
Returns:
Returns value of that Cp Entry.

getTagName

public static java.lang.String getTagName(int tagByte)
Returns the actual name of the tag . according to their types.

Parameters:
tagByte - Tag Byte value
Returns:
Returns the string representation of the integer tagByte

getTagDescriptor

public java.lang.String getTagDescriptor(int index)
Describes the tag in brief. If a tag is relative tag like TAG_FIELDREF or TAG_METHODREF then it lists out the related tag information too,

Parameters:
index - Index to the ConstantPool.
Returns:
Returns a string describing the tag entry.

getName

public java.lang.String getName(JConstantPoolEntry ent)
Returns the name pointed to by this JConstantPoolEntry. Usually this tag happens to be one of TAG_FIELDREF, TAG_METHODREF or TAG_INTERFACEREF.

Parameters:
ent - Constant Pool Entry
Returns:
Returns name of the member (field/method/interface) pointed to by the Constant Pool Entry.

getType

public java.lang.String getType(JConstantPoolEntry ent)
Returns the type pointed to by this JConstantPoolEntry. Usually this tag happens to be one of TAG_FIELDREF, TAG_METHODREF or TAG_INTERFACEREF.

Parameters:
ent - Constant Pool Entry
Returns:
Returns type of the member (field/method/interface) pointed to by the Constant Pool Entry.

getEntryInfo

public java.lang.String getEntryInfo()
Returns the whole ConstantPool info in a formatter manner.

Returns:
Returns a string.

getEntryInfo

public java.lang.String getEntryInfo(int cpIndex)
Returns the name pointed to by this JConstantPoolEntry. Usually this tag happens to be one of TAG_FIELDREF, TAG_METHODREF or TAG_INTERFACEREF.

Parameters:
cpIndex - Index to Constant Pool
Returns:
Returns name of the member (field/method/interface) pointed to by the Constant Pool Entry.


Submit Feedback to akkumar@users.sourceforge.net