public class ConstantPool extends Object
ConstantPool entries are not written out in the order in which they were added to it. Instead, their ordering is changed such that String, Integer and Float constants are written out first. This provides a slight optimization for referencing these constants from a code attribute. It means that Opcode.LDC will more likely be used (one-byte index) than Opcode.LDC_W (two-byte index).
Opcode
Modifier and Type | Method and Description |
---|---|
ConstantInfo |
addConstant(ConstantInfo constant)
Will only insert into the pool if the constant is not already in the
pool.
|
ConstantClassInfo |
addConstantClass(String className)
Get or create a constant from the constant pool representing a class.
|
ConstantClassInfo |
addConstantClass(String className,
int dim)
Get or create a constant from the constant pool representing an array
class.
|
ConstantClassInfo |
addConstantClass(TypeDesc type)
Get or create a constant from the constant pool representing a class.
|
ConstantMethodInfo |
addConstantConstructor(String className,
TypeDesc[] params)
Get or create a constant from the constant pool representing a
constructor in any class.
|
ConstantDoubleInfo |
addConstantDouble(double value)
Get or create a constant double from the constant pool.
|
ConstantFieldInfo |
addConstantField(String className,
String fieldName,
TypeDesc type)
Get or create a constant from the constant pool representing a field in
any class.
|
ConstantFloatInfo |
addConstantFloat(float value)
Get or create a constant float from the constant pool.
|
ConstantIntegerInfo |
addConstantInteger(int value)
Get or create a constant integer from the constant pool.
|
ConstantInterfaceMethodInfo |
addConstantInterfaceMethod(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Get or create a constant from the constant pool representing an
interface method in any interface.
|
ConstantLongInfo |
addConstantLong(long value)
Get or create a constant long from the constant pool.
|
ConstantMethodInfo |
addConstantMethod(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Get or create a constant from the constant pool representing a method
in any class.
|
ConstantNameAndTypeInfo |
addConstantNameAndType(ConstantUTFInfo nameConstant,
ConstantUTFInfo descConstant)
Get or create a constant name and type structure from the constant pool.
|
ConstantNameAndTypeInfo |
addConstantNameAndType(String name,
Descriptor type)
Get or create a constant name and type structure from the constant pool.
|
ConstantStringInfo |
addConstantString(String str)
Get or create a constant string from the constant pool.
|
ConstantUTFInfo |
addConstantUTF(String str)
Get or create a constant UTF string from the constant pool.
|
Set<ConstantInfo> |
getAllConstants()
Returns all the constants in the pool, in no particular order.
|
ConstantInfo |
getConstant(int index)
Returns a constant from the pool by index, or null if not found.
|
int |
getSize()
Returns the number of constants in the pool.
|
static ConstantPool |
readFrom(DataInput din) |
void |
writeTo(DataOutput dout) |
public ConstantInfo getConstant(int index)
ArrayIndexOutOfBoundsException
- if index is out of range.IllegalStateException
- if indexes are not assignedpublic Set<ConstantInfo> getAllConstants()
public int getSize()
public ConstantClassInfo addConstantClass(String className)
public ConstantClassInfo addConstantClass(String className, int dim)
dim
- Number of array dimensions.public ConstantClassInfo addConstantClass(TypeDesc type)
public ConstantFieldInfo addConstantField(String className, String fieldName, TypeDesc type)
public ConstantMethodInfo addConstantMethod(String className, String methodName, TypeDesc ret, TypeDesc[] params)
public ConstantInterfaceMethodInfo addConstantInterfaceMethod(String className, String methodName, TypeDesc ret, TypeDesc[] params)
public ConstantMethodInfo addConstantConstructor(String className, TypeDesc[] params)
public ConstantIntegerInfo addConstantInteger(int value)
public ConstantLongInfo addConstantLong(long value)
public ConstantFloatInfo addConstantFloat(float value)
public ConstantDoubleInfo addConstantDouble(double value)
public ConstantStringInfo addConstantString(String str)
public ConstantUTFInfo addConstantUTF(String str)
public ConstantNameAndTypeInfo addConstantNameAndType(String name, Descriptor type)
public ConstantNameAndTypeInfo addConstantNameAndType(ConstantUTFInfo nameConstant, ConstantUTFInfo descConstant)
public ConstantInfo addConstant(ConstantInfo constant)
public void writeTo(DataOutput dout) throws IOException
IOException
public static ConstantPool readFrom(DataInput din) throws IOException
IOException
Copyright © 2004-2015 Cojen. All Rights Reserved.