Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional.depend.constantpool

public Class ConstantPool

extends Object
Class Inheritance
Imports
java.io.DataInputStream, .IOException, java.util.ArrayList, .HashMap, .List, .Map, java.util.stream.Collectors, .IntStream

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

Field Summary

Modifier and TypeField and Description
private final List<ConstantPoolEntry>
entries

The entries in the constant pool.

private final Map<String, Integer>
utf8Indexes

A Hashtable of UTF8 entries - used to get constant pool indexes of the UTF8 values quickly

Constructor Summary

AccessConstructor and Description
public
ConstantPool()

Initialise the constant pool.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the index into the constant pool at which the entry is stored.
addEntry
(ConstantPoolEntry
the new entry to be added to the constant pool.
entry
)

Add an entry to the constant pool.

public int

Returns:

the index at which the given class entry occurs in the constant pool or -1 if the value does not occur.
getClassEntry
(String
the name of the class for which the class entry index is required.
className
)

Get the index of a given CONSTANT_CLASS entry in the constant pool.

public int

Returns:

the index at which the given value entry occurs in the constant pool or -1 if the value does not occur.
getConstantEntry
(Object
the constant value for which the index is required.
constantValue
)

Get the index of a given constant value entry in the constant pool.

public ConstantPoolEntry

Returns:

the constant pool entry at that index.
getEntry
(int
the index into the constant pool.
index
)

Get an constant pool entry at a particular index.

public int

Returns:

the index at which the given field ref entry occurs in the constant pool or -1 if the value does not occur.
getFieldRefEntry
(String
the name of the class which contains the field being referenced.
fieldClassName
,
String
the name of the field being referenced.
fieldName
,
String
the type descriptor of the field being referenced.
fieldType
)

Get the index of a given CONSTANT_FIELDREF entry in the constant pool.

public int

Returns:

the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.
getInterfaceMethodRefEntry
(String
the name of the interface which contains the method being referenced.
interfaceMethodClassName
,
String
the name of the method being referenced.
interfaceMethodName
,
String
the type descriptor of the method being referenced.
interfaceMethodType
)

Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the constant pool.

public int

Returns:

the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.
getMethodRefEntry
(String
the name of the class which contains the method being referenced.
methodClassName
,
String
the name of the method being referenced.
methodName
,
String
the type descriptor of the method being referenced.
methodType
)

Get the index of a given CONSTANT_METHODREF entry in the constant pool.

public int

Returns:

the index at which the given NameAndType entry occurs in the constant pool or -1 if the value does not occur.
getNameAndTypeEntry
(String
the name
name
,
String
the type
type
)

Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant pool.

public int

Returns:

the index at which the given string occurs in the constant pool or -1 if the value does not occur.
getUTF8Entry
(String
the string value of the UTF8 entry.
value
)

Get the index of a given UTF8 constant pool entry.

public void
read(DataInputStream
the DataInputStream of a class file.
classStream
)

Read the constant pool from a class input stream.

public void
resolve()

Resolve the entries in the constant pool.

public int

Returns:

the size of the constant pool
size
()

Get the size of the constant pool.

public String

Returns:

the constant pool entries as strings
toString
()

Overrides java.lang.Object.toString.

Dump the constant pool to a string.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

entriesback to summary
private final List<ConstantPoolEntry> entries

The entries in the constant pool.

utf8Indexesback to summary
private final Map<String, Integer> utf8Indexes

A Hashtable of UTF8 entries - used to get constant pool indexes of the UTF8 values quickly

Constructor Detail

ConstantPoolback to summary
public ConstantPool()

Initialise the constant pool.

Method Detail

addEntryback to summary
public int addEntry(ConstantPoolEntry entry)

Add an entry to the constant pool.

Parameters
entry:ConstantPoolEntry

the new entry to be added to the constant pool.

Returns:int

the index into the constant pool at which the entry is stored.

getClassEntryback to summary
public int getClassEntry(String className)

Get the index of a given CONSTANT_CLASS entry in the constant pool.

Parameters
className:String

the name of the class for which the class entry index is required.

Returns:int

the index at which the given class entry occurs in the constant pool or -1 if the value does not occur.

getConstantEntryback to summary
public int getConstantEntry(Object constantValue)

Get the index of a given constant value entry in the constant pool.

Parameters
constantValue:Object

the constant value for which the index is required.

Returns:int

the index at which the given value entry occurs in the constant pool or -1 if the value does not occur.

getEntryback to summary
public ConstantPoolEntry getEntry(int index)

Get an constant pool entry at a particular index.

Parameters
index:int

the index into the constant pool.

Returns:ConstantPoolEntry

the constant pool entry at that index.

getFieldRefEntryback to summary
public int getFieldRefEntry(String fieldClassName, String fieldName, String fieldType)

Get the index of a given CONSTANT_FIELDREF entry in the constant pool.

Parameters
fieldClassName:String

the name of the class which contains the field being referenced.

fieldName:String

the name of the field being referenced.

fieldType:String

the type descriptor of the field being referenced.

Returns:int

the index at which the given field ref entry occurs in the constant pool or -1 if the value does not occur.

getInterfaceMethodRefEntryback to summary
public int getInterfaceMethodRefEntry(String interfaceMethodClassName, String interfaceMethodName, String interfaceMethodType)

Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the constant pool.

Parameters
interfaceMethodClassName:String

the name of the interface which contains the method being referenced.

interfaceMethodName:String

the name of the method being referenced.

interfaceMethodType:String

the type descriptor of the method being referenced.

Returns:int

the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.

getMethodRefEntryback to summary
public int getMethodRefEntry(String methodClassName, String methodName, String methodType)

Get the index of a given CONSTANT_METHODREF entry in the constant pool.

Parameters
methodClassName:String

the name of the class which contains the method being referenced.

methodName:String

the name of the method being referenced.

methodType:String

the type descriptor of the method being referenced.

Returns:int

the index at which the given method ref entry occurs in the constant pool or -1 if the value does not occur.

getNameAndTypeEntryback to summary
public int getNameAndTypeEntry(String name, String type)

Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant pool.

Parameters
name:String

the name

type:String

the type

Returns:int

the index at which the given NameAndType entry occurs in the constant pool or -1 if the value does not occur.

getUTF8Entryback to summary
public int getUTF8Entry(String value)

Get the index of a given UTF8 constant pool entry.

Parameters
value:String

the string value of the UTF8 entry.

Returns:int

the index at which the given string occurs in the constant pool or -1 if the value does not occur.

readback to summary
public void read(DataInputStream classStream) throws IOException

Read the constant pool from a class input stream.

Parameters
classStream:DataInputStream

the DataInputStream of a class file.

Exceptions
IOException:
if there is a problem reading the constant pool from the stream
resolveback to summary
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.

sizeback to summary
public int size()

Get the size of the constant pool.

Returns:int

the size of the constant pool

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Dump the constant pool to a string.

Returns:String

the constant pool entries as strings

Annotations
@Override