public class ConstantPoolEditor
extends java.lang.Object
If you're building a class from scratch, it is more efficient to reuse a single instance of this editor for all constants that you add.
Constructor and Description |
---|
ConstantPoolEditor(ProgramClass targetClass)
Creates a new ConstantPoolEditor.
|
ConstantPoolEditor(ProgramClass targetClass,
ClassPool programClassPool,
ClassPool libraryClassPool)
Creates a new ConstantPoolEditor that automatically initializes class references and class
member references in new constants.
|
Modifier and Type | Method and Description |
---|---|
int |
addClassConstant(Clazz referencedClass)
Finds or creates a ClassConstant constant pool entry for the given class.
|
int |
addClassConstant(int nameIndex,
Clazz referencedClass)
Finds or creates a ClassConstant constant pool entry with the given name UTF-8 constant pool
index.
|
int |
addClassConstant(java.lang.String name,
Clazz referencedClass)
Finds or creates a ClassConstant constant pool entry with the given name.
|
int |
addConstant(Constant constant)
Adds a given constant pool entry to the end of the constant pool.
|
int |
addDoubleConstant(double value)
Finds or creates a DoubleConstant constant pool entry with the given value.
|
int |
addDynamicConstant(int bootstrapMethodIndex,
int nameAndTypeIndex,
Clazz[] referencedClasses)
Finds or creates a DynamicConstant constant pool entry with the given class constant pool entry
index and name and type constant pool entry index.
|
int |
addFieldrefConstant(Clazz referencedClass,
Field referencedField)
Finds or creates a FieldrefConstant constant pool entry for the given class and field.
|
int |
addFieldrefConstant(int classIndex,
int nameAndTypeIndex,
Clazz referencedClass,
Field referencedField)
Finds or creates a FieldrefConstant constant pool entry with the given class constant pool
entry index and name and type constant pool entry index.
|
int |
addFieldrefConstant(int classIndex,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Field referencedField)
Finds or creates a FieldrefConstant constant pool entry with the given class constant pool
entry index, field name, and descriptor.
|
int |
addFieldrefConstant(java.lang.String className,
int nameAndTypeIndex,
Clazz referencedClass,
Field referencedField)
Finds or creates a FieldrefConstant constant pool entry with the given class name, field name,
and descriptor.
|
int |
addFieldrefConstant(java.lang.String className,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Field referencedField)
Finds or creates a FieldrefConstant constant pool entry with the given class name, field name,
and descriptor.
|
int |
addFloatConstant(float value)
Finds or creates a FloatConstant constant pool entry with the given value.
|
int |
addIntegerConstant(int value)
Finds or creates a IntegerConstant constant pool entry with the given value.
|
int |
addInterfaceMethodrefConstant(Clazz referencedClass,
Method referencedMethod)
Finds or creates a InterfaceMethodrefConstant constant pool entry for the given class and
method.
|
int |
addInterfaceMethodrefConstant(int classIndex,
int nameAndTypeIndex,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a InterfaceMethodrefConstant constant pool entry with the given class constant
pool entry index and name and type constant pool entry index.
|
int |
addInterfaceMethodrefConstant(int classIndex,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a InterfaceMethodrefConstant constant pool entry with the given class constant
pool entry index, method name, and descriptor.
|
int |
addInterfaceMethodrefConstant(java.lang.String className,
int nameAndTypeIndex,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a InterfaceMethodrefConstant constant pool entry with the given class name,
method name, and descriptor.
|
int |
addInterfaceMethodrefConstant(java.lang.String className,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a InterfaceMethodrefConstant constant pool entry with the given class name,
method name, and descriptor.
|
int |
addInvokeDynamicConstant(int bootstrapMethodIndex,
int nameAndTypeIndex,
Clazz[] referencedClasses)
Finds or creates an InvokeDynamicConstant constant pool entry with the given class constant
pool entry index and name and type constant pool entry index.
|
int |
addInvokeDynamicConstant(int bootstrapMethodIndex,
java.lang.String name,
java.lang.String descriptor,
Clazz[] referencedClasses)
Finds or creates a InvokeDynamicConstant constant pool entry with the given bootstrap method
constant pool entry index, method name, and descriptor.
|
int |
addLongConstant(long value)
Finds or creates a LongConstant constant pool entry with the given value.
|
int |
addMethodHandleConstant(int referenceKind,
int referenceIndex)
Finds or creates a MethodHandleConstant constant pool entry of the specified kind and with the
given field ref, interface method ref, or method ref constant pool entry index.
|
int |
addMethodrefConstant(Clazz referencedClass,
Method referencedMethod)
Finds or creates a MethodrefConstant constant pool entry for the given class and method.
|
int |
addMethodrefConstant(int classIndex,
int nameAndTypeIndex,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a MethodrefConstant constant pool entry with the given class constant pool
entry index and name and type constant pool entry index.
|
int |
addMethodrefConstant(int classIndex,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a MethodrefConstant constant pool entry with the given class constant pool
entry index, method name, and descriptor.
|
int |
addMethodrefConstant(java.lang.String className,
int nameAndTypeIndex,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a MethodrefConstant constant pool entry with the given class name, method
name, and descriptor.
|
int |
addMethodrefConstant(java.lang.String className,
java.lang.String name,
java.lang.String descriptor,
Clazz referencedClass,
Method referencedMethod)
Finds or creates a MethodrefConstant constant pool entry with the given class name, method
name, and descriptor.
|
int |
addMethodTypeConstant(int descriptorIndex,
Clazz[] referencedClasses)
Finds or creates a MethodTypeConstant constant pool entry with the given descriptor UTF-8
constant pool index.
|
int |
addMethodTypeConstant(java.lang.String descriptor,
Clazz[] referencedClasses)
Finds or creates a MethodTypeConstant constant pool entry with the given descriptor.
|
int |
addModuleConstant(int nameIndex)
Finds or creates a ModuleConstant constant pool entry with the given name constant pool index.
|
int |
addModuleConstant(java.lang.String name)
Finds or creates a ModuleConstant constant pool entry with the given name.
|
int |
addNameAndTypeConstant(int nameIndex,
int descriptorIndex)
Finds or creates a NameAndTypeConstant constant pool entry with the given name and descriptor
UTF-8 constant pool indices.
|
int |
addNameAndTypeConstant(java.lang.String name,
java.lang.String descriptor)
Finds or creates a NameAndTypeConstant constant pool entry with the given name and descriptor.
|
int |
addPackageConstant(int nameIndex)
Finds or creates a PackageConstant constant pool entry with the given name constant pool index.
|
int |
addPackageConstant(java.lang.String name)
Finds or creates a PackageConstant constant pool entry with the given name.
|
int |
addPrimitiveArrayConstant(java.lang.Object values)
Finds or creates a PrimitiveArrayConstant constant pool entry with the given values.
|
int |
addStringConstant(int utf8index,
Clazz referencedClass,
Member referencedMember,
int resourceFileId,
ResourceFile resourceFile)
Finds or creates a StringConstant constant pool entry with the given UTF-8 constant index.
|
int |
addStringConstant(java.lang.String string)
Finds or creates a StringConstant constant pool entry with the given value.
|
int |
addStringConstant(java.lang.String string,
Clazz referencedClass,
Member referencedMember)
Finds or creates a StringConstant constant pool entry with the given value, with optional
referenced class/member.
|
int |
addStringConstant(java.lang.String string,
Clazz referencedClass,
Member referencedMember,
int resourceFileId,
ResourceFile resourceFile)
Finds or creates a StringConstant constant pool entry with the given value.
|
int |
addStringConstant(java.lang.String string,
ResourceFile referencedResourceFile)
Finds or creates a StringConstant constant pool entry with the given value.
|
int |
addUtf8Constant(java.lang.String string)
Finds or creates a Utf8Constant constant pool entry for the given string.
|
int |
findOrAddConstant(Constant constant)
Finds or adds a given constant pool entry.
|
ProgramClass |
getTargetClass()
Returns the target class in which constants are edited.
|
public ConstantPoolEditor(ProgramClass targetClass)
targetClass
- the target class in which constants are to be edited.public ConstantPoolEditor(ProgramClass targetClass, ClassPool programClassPool, ClassPool libraryClassPool)
targetClass
- the target class in which constants are to be edited.programClassPool
- the program class pool from which new constants can be initialized.libraryClassPool
- the library class pool from which new constants can be initialized.public ProgramClass getTargetClass()
public int addIntegerConstant(int value)
public int addLongConstant(long value)
public int addFloatConstant(float value)
public int addDoubleConstant(double value)
public int addPrimitiveArrayConstant(java.lang.Object values)
public int addStringConstant(java.lang.String string, Clazz referencedClass, Member referencedMember)
referencedClass
- The class that this string references.referencedMember
- The member that this string references.public int addStringConstant(java.lang.String string)
public int addStringConstant(java.lang.String string, ResourceFile referencedResourceFile)
public int addStringConstant(java.lang.String string, Clazz referencedClass, Member referencedMember, int resourceFileId, ResourceFile resourceFile)
public int addStringConstant(int utf8index, Clazz referencedClass, Member referencedMember, int resourceFileId, ResourceFile resourceFile)
public int addInvokeDynamicConstant(int bootstrapMethodIndex, java.lang.String name, java.lang.String descriptor, Clazz[] referencedClasses)
public int addDynamicConstant(int bootstrapMethodIndex, int nameAndTypeIndex, Clazz[] referencedClasses)
public int addInvokeDynamicConstant(int bootstrapMethodIndex, int nameAndTypeIndex, Clazz[] referencedClasses)
public int addMethodHandleConstant(int referenceKind, int referenceIndex)
public int addModuleConstant(java.lang.String name)
public int addModuleConstant(int nameIndex)
public int addPackageConstant(java.lang.String name)
public int addPackageConstant(int nameIndex)
public int addFieldrefConstant(Clazz referencedClass, Field referencedField)
public int addFieldrefConstant(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
public int addFieldrefConstant(java.lang.String className, int nameAndTypeIndex, Clazz referencedClass, Field referencedField)
public int addFieldrefConstant(int classIndex, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
public int addFieldrefConstant(int classIndex, int nameAndTypeIndex, Clazz referencedClass, Field referencedField)
public int addInterfaceMethodrefConstant(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
public int addInterfaceMethodrefConstant(java.lang.String className, int nameAndTypeIndex, Clazz referencedClass, Method referencedMethod)
public int addInterfaceMethodrefConstant(Clazz referencedClass, Method referencedMethod)
public int addInterfaceMethodrefConstant(int classIndex, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
public int addInterfaceMethodrefConstant(int classIndex, int nameAndTypeIndex, Clazz referencedClass, Method referencedMethod)
public int addMethodrefConstant(Clazz referencedClass, Method referencedMethod)
public int addMethodrefConstant(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
public int addMethodrefConstant(java.lang.String className, int nameAndTypeIndex, Clazz referencedClass, Method referencedMethod)
public int addMethodrefConstant(int classIndex, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
public int addMethodrefConstant(int classIndex, int nameAndTypeIndex, Clazz referencedClass, Method referencedMethod)
public int addClassConstant(Clazz referencedClass)
public int addClassConstant(java.lang.String name, Clazz referencedClass)
public int addClassConstant(int nameIndex, Clazz referencedClass)
public int addMethodTypeConstant(java.lang.String descriptor, Clazz[] referencedClasses)
public int addMethodTypeConstant(int descriptorIndex, Clazz[] referencedClasses)
public int addNameAndTypeConstant(java.lang.String name, java.lang.String descriptor)
public int addNameAndTypeConstant(int nameIndex, int descriptorIndex)
public int addUtf8Constant(java.lang.String string)
public int findOrAddConstant(Constant constant)
public int addConstant(Constant constant)
findOrAddConstant(Constant)