Class ConstantPool
java.lang.Object
org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool
public class ConstantPool
extends java.lang.Object
The constant pool of a Java class. The constant pool is a collection of
constants used in a Java class file. It stores strings, constant values,
class names, method names, field names etc.
- See Also:
- The Java Virtual Machine Specification
-
Constructor Summary
Constructors Constructor Description ConstantPool()Initialise the constant pool. -
Method Summary
Modifier and Type Method Description intaddEntry(ConstantPoolEntry entry)Add an entry to the constant pool.intgetClassEntry(java.lang.String className)Get the index of a given CONSTANT_CLASS entry in the constant pool.intgetConstantEntry(java.lang.Object constantValue)Get the index of a given constant value entry in the constant pool.ConstantPoolEntrygetEntry(int index)Get an constant pool entry at a particular index.intgetFieldRefEntry(java.lang.String fieldClassName, java.lang.String fieldName, java.lang.String fieldType)Get the index of a given CONSTANT_FIELDREF entry in the constant pool.intgetInterfaceMethodRefEntry(java.lang.String interfaceMethodClassName, java.lang.String interfaceMethodName, java.lang.String interfaceMethodType)Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the constant pool.intgetMethodRefEntry(java.lang.String methodClassName, java.lang.String methodName, java.lang.String methodType)Get the index of a given CONSTANT_METHODREF entry in the constant pool.intgetNameAndTypeEntry(java.lang.String name, java.lang.String type)Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant pool.intgetUTF8Entry(java.lang.String value)Get the index of a given UTF8 constant pool entry.voidread(java.io.DataInputStream classStream)Read the constant pool from a class input stream.voidresolve()Resolve the entries in the constant pool.intsize()Get the size of the constant pool.java.lang.StringtoString()Dump the constant pool to a string.
-
Constructor Details
-
ConstantPool
public ConstantPool()Initialise the constant pool.
-
-
Method Details
-
read
public void read(java.io.DataInputStream classStream) throws java.io.IOExceptionRead the constant pool from a class input stream.- Parameters:
classStream- the DataInputStream of a class file.- Throws:
java.io.IOException- if there is a problem reading the constant pool from the stream
-
size
public int size()Get the size of the constant pool.- Returns:
- the size of the constant pool
-
addEntry
Add an entry to the constant pool.- Parameters:
entry- the new entry to be added to the constant pool.- Returns:
- the index into the constant pool at which the entry is stored.
-
resolve
public void resolve()Resolve the entries in the constant pool. Resolution of the constant pool involves transforming indexes to other constant pool entries into the actual data for that entry. -
getEntry
Get an constant pool entry at a particular index.- Parameters:
index- the index into the constant pool.- Returns:
- the constant pool entry at that index.
-
getUTF8Entry
public int getUTF8Entry(java.lang.String value)Get the index of a given UTF8 constant pool entry.- Parameters:
value- the string value of the UTF8 entry.- Returns:
- the index at which the given string occurs in the constant pool or -1 if the value does not occur.
-
getClassEntry
public int getClassEntry(java.lang.String className)Get the index of a given CONSTANT_CLASS entry in the constant pool.- Parameters:
className- the name of the class for which the class entry index is required.- Returns:
- the index at which the given class entry occurs in the constant pool or -1 if the value does not occur.
-
getConstantEntry
public int getConstantEntry(java.lang.Object constantValue)Get the index of a given constant value entry in the constant pool.- Parameters:
constantValue- the constant value for which the index is required.- Returns:
- the index at which the given value entry occurs in the constant pool or -1 if the value does not occur.
-
getMethodRefEntry
public int getMethodRefEntry(java.lang.String methodClassName, java.lang.String methodName, java.lang.String methodType)Get the index of a given CONSTANT_METHODREF entry in the constant pool.- Parameters:
methodClassName- the name of the class which contains the method being referenced.methodName- the name of the method being referenced.methodType- the type descriptor of the method being referenced.- Returns:
- the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.
-
getInterfaceMethodRefEntry
public int getInterfaceMethodRefEntry(java.lang.String interfaceMethodClassName, java.lang.String interfaceMethodName, java.lang.String interfaceMethodType)Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the constant pool.- Parameters:
interfaceMethodClassName- the name of the interface which contains the method being referenced.interfaceMethodName- the name of the method being referenced.interfaceMethodType- the type descriptor of the method being referenced.- Returns:
- the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.
-
getFieldRefEntry
public int getFieldRefEntry(java.lang.String fieldClassName, java.lang.String fieldName, java.lang.String fieldType)Get the index of a given CONSTANT_FIELDREF entry in the constant pool.- Parameters:
fieldClassName- the name of the class which contains the field being referenced.fieldName- the name of the field being referenced.fieldType- the type descriptor of the field being referenced.- Returns:
- the index at which the given field ref entry occurs in the constant pool or -1 if the value does not occur.
-
getNameAndTypeEntry
public int getNameAndTypeEntry(java.lang.String name, java.lang.String type)Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant pool.- Parameters:
name- the nametype- the type- Returns:
- the index at which the given NameAndType entry occurs in the constant pool or -1 if the value does not occur.
-
toString
public java.lang.String toString()Dump the constant pool to a string.- Overrides:
toStringin classjava.lang.Object- Returns:
- the constant pool entries as strings
-