- All Superinterfaces:
ClassFileElement,ConstantPool,Iterable<PoolEntry>,WritableElement<ConstantPool>
- All Known Implementing Classes:
SplitConstantPool,TemporaryConstantPool
public sealed interface ConstantPoolBuilder
extends ConstantPool, WritableElement<ConstantPool>
permits SplitConstantPool, TemporaryConstantPool
Builder for the constant pool of a classfile. Provides read and write access
to the constant pool that is being built. Writing is append-only and idempotent
(entry-bearing methods will return an existing entry if there is one).
A ConstantPoolBuilder is associated with a
ClassBuilder.
The ConstantPoolBuilder also provides access to some of the
state of the ClassBuilder, such as classfile processing options.- Since:
- 22
-
Method Summary
Modifier and TypeMethodDescriptiondefault AnnotationConstantValueEntryReturns AnAnnotationConstantValueEntrydescribing the provided constant.default BootstrapMethodEntrybsmEntry(DirectMethodHandleDesc methodReference, List<ConstantDesc> arguments) Returns aBootstrapMethodEntrydescribing the provided bootstrap method and static arguments.bsmEntry(MethodHandleEntry methodReference, List<LoadableConstantEntry> arguments) Returns aBootstrapMethodEntrydescribing the provided bootstrap method and static arguments.booleancanWriteDirect(ConstantPool constantPool) Returns whether the provided constant pool is index-compatible with this one.default ClassEntryclassEntry(ClassDesc classDesc) Returns AClassEntrydescribing the class described by provided ClassDesc.classEntry(Utf8Entry ne) Returns AClassEntrydescribing the class whose internal name is encoded in the provided Utf8Entry.default ConstantDynamicEntryReturns AConstantDynamicEntrydescribing a dynamic constant.constantDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType) Returns AConstantDynamicEntrydescribing a dynamic constant.default ConstantValueEntryReturns AConstantValueEntrydescripbing the provided Integer, Long, Float, Double, or String constant.doubleEntry(double value) Returns ADoubleEntrydescribing the provided value.default FieldRefEntryfieldRefEntry(ClassDesc owner, String name, ClassDesc type) Returns AFieldRefEntrydescribing a field of a class.fieldRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType) Returns AFieldRefEntrydescribing a field of a class.floatEntry(float value) Returns AFloatEntrydescribing the provided value.intEntry(int value) Returns AnIntegerEntrydescribing the provided value.default InterfaceMethodRefEntryinterfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AInterfaceMethodRefEntrydescribing a method of a class.interfaceMethodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType) Returns AInterfaceMethodRefEntrydescribing a method of a class.default InvokeDynamicEntryReturns AnInvokeDynamicEntrydescribing a dynamic call site.invokeDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType) Returns AnInvokeDynamicEntrydescribing a dynamic call site.default LoadableConstantEntryReturns ALoadableConstantEntrydescribing the provided constant.longEntry(long value) Returns ALongEntrydescribing the provided value.methodHandleEntry(int refKind, MemberRefEntry reference) Returns AMethodHandleEntrydescribing a field accessor or method.default MethodHandleEntrymethodHandleEntry(DirectMethodHandleDesc descriptor) Returns AMethodHandleEntrydescribing a direct method handle.default MethodRefEntrymethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AMethodRefEntrydescribing a method of a class.methodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType) Returns AMethodRefEntrydescribing a method of a class.methodTypeEntry(MethodTypeDesc descriptor) Returns AMethodTypeEntrydescribing a method type.methodTypeEntry(Utf8Entry descriptor) Returns AMethodTypeEntrydescribing a method type.default ModuleEntrymoduleEntry(ModuleDesc moduleDesc) Returns AModuleEntrydescribing the module described by provided ModuleDesc.moduleEntry(Utf8Entry moduleName) Returns AModuleEntrydescribing the module whose name is encoded in the provided Utf8Entry.default NameAndTypeEntrynameAndTypeEntry(String name, ClassDesc type) Returns ANameAndTypeEntrydescribing the provided name and type.default NameAndTypeEntrynameAndTypeEntry(String name, MethodTypeDesc type) Returns ANameAndTypeEntrydescribing the provided name and type.nameAndTypeEntry(Utf8Entry nameEntry, Utf8Entry typeEntry) Returns ANameAndTypeEntrydescribing the provided name and type.static ConstantPoolBuilderof()Returns a new constant pool builder.static ConstantPoolBuilderof(ClassModel classModel) Returns a new constant pool builder.default PackageEntrypackageEntry(PackageDesc packageDesc) Returns APackageEntrydescribing the class described by provided PackageDesc.packageEntry(Utf8Entry nameEntry) Returns APackageEntrydescribing the class whose internal name is encoded in the provided Utf8Entry.default StringEntrystringEntry(String value) Returns AStringEntrydescribing the provided value.stringEntry(Utf8Entry utf8) Returns AStringEntryreferencing the provided UTF8 entry.default Utf8Entrydefault Utf8Entryutf8Entry(MethodTypeDesc desc) Returns AUtf8Entrydescribing the method descriptor of the provided MethodTypeDesc.booleanWrites associated bootstrap method entries to the specified writerMethods inherited from interface org.glavo.classfile.constantpool.ConstantPool
bootstrapMethodCount, bootstrapMethodEntry, entryByIndex, iterator, sizeMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.glavo.classfile.WritableElement
writeTo
-
Method Details
-
of
Returns a new constant pool builder. The new constant pool builder will be pre-populated with the contents of the constant pool associated with the class reader.- Parameters:
classModel- the class to copy from- Returns:
- a new constant pool builder
-
of
Returns a new constant pool builder. The new constant pool builder will be empty.- Returns:
- a new constant pool builder
-
canWriteDirect
Returns whether the provided constant pool is index-compatible with this one. This may be because they are the same constant pool, or because this constant pool was copied from the other.- Parameters:
constantPool- the other constant pool- Returns:
- whether the provided constant pool is index-compatible with this one
-
writeBootstrapMethods
Writes associated bootstrap method entries to the specified writer- Parameters:
buf- the writer- Returns:
- false when no bootstrap method entry has been written
-
utf8Entry
-
utf8Entry
-
utf8Entry
Returns AUtf8Entrydescribing the method descriptor of the provided MethodTypeDesc. If a UTF8 entry in the pool already describes this field descriptor, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
desc- the symbolic descriptor for the method type- Returns:
- A
Utf8Entrydescribing the method descriptor of the provided MethodTypeDesc
-
classEntry
Returns AClassEntrydescribing the class whose internal name is encoded in the provided Utf8Entry. If a Class entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
ne- the constant pool entry describing the internal name of the class- Returns:
- A
ClassEntrydescribing the class whose internal name is encoded in the provided Utf8Entry
-
classEntry
Returns AClassEntrydescribing the class described by provided ClassDesc. If a Class entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
classDesc- the symbolic descriptor for the class- Returns:
- A
ClassEntrydescribing the class described by provided ClassDesc - Throws:
IllegalArgumentException- ifclassDescrepresents a primitive type
-
packageEntry
Returns APackageEntrydescribing the class whose internal name is encoded in the provided Utf8Entry. If a Package entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
nameEntry- the constant pool entry describing the internal name of the package- Returns:
- A
PackageEntrydescribing the class whose internal name is encoded in the provided Utf8Entry
-
packageEntry
Returns APackageEntrydescribing the class described by provided PackageDesc. If a Package entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
packageDesc- the symbolic descriptor for the class- Returns:
- A
PackageEntrydescribing the class described by provided PackageDesc
-
moduleEntry
Returns AModuleEntrydescribing the module whose name is encoded in the provided Utf8Entry. If a module entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
moduleName- the constant pool entry describing the module name- Returns:
- A
ModuleEntrydescribing the module whose name is encoded in the provided Utf8Entry
-
moduleEntry
Returns AModuleEntrydescribing the module described by provided ModuleDesc. If a module entry in the pool already describes this class, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
moduleDesc- the symbolic descriptor for the class- Returns:
- A
ModuleEntrydescribing the module described by provided ModuleDesc
-
nameAndTypeEntry
Returns ANameAndTypeEntrydescribing the provided name and type. If a NameAndType entry in the pool already describes this name and type, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
nameEntry- the member nametypeEntry- the member field or method descriptor- Returns:
- A
NameAndTypeEntrydescribing the provided name and type
-
nameAndTypeEntry
Returns ANameAndTypeEntrydescribing the provided name and type. If a NameAndType entry in the pool already describes this name and type, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
name- the member nametype- the symbolic descriptor for a field type- Returns:
- A
NameAndTypeEntrydescribing the provided name and type
-
nameAndTypeEntry
Returns ANameAndTypeEntrydescribing the provided name and type. If a NameAndType entry in the pool already describes this name and type, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
name- the member nametype- the symbolic descriptor for a method type- Returns:
- A
NameAndTypeEntrydescribing the provided name and type
-
fieldRefEntry
Returns AFieldRefEntrydescribing a field of a class. If a FieldRef entry in the pool already describes this field, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the field is a member ofnameAndType- the name and type of the field- Returns:
- A
FieldRefEntrydescribing a field of a class
-
fieldRefEntry
Returns AFieldRefEntrydescribing a field of a class. If a FieldRef entry in the pool already describes this field, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the field is a member ofname- the name of the fieldtype- the type of the field- Returns:
- A
FieldRefEntrydescribing a field of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
methodRefEntry
Returns AMethodRefEntrydescribing a method of a class. If a MethodRefEntry entry in the pool already describes this method, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the method is a member ofnameAndType- the name and type of the method- Returns:
- A
MethodRefEntrydescribing a method of a class
-
methodRefEntry
Returns AMethodRefEntrydescribing a method of a class. If a MethodRefEntry entry in the pool already describes this method, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the method is a member ofname- the name of the methodtype- the type of the method- Returns:
- A
MethodRefEntrydescribing a method of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
interfaceMethodRefEntry
Returns AInterfaceMethodRefEntrydescribing a method of a class. If a InterfaceMethodRefEntry entry in the pool already describes this method, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the method is a member ofnameAndType- the name and type of the method- Returns:
- A
InterfaceMethodRefEntrydescribing a method of a class
-
interfaceMethodRefEntry
default InterfaceMethodRefEntry interfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AInterfaceMethodRefEntrydescribing a method of a class. If a InterfaceMethodRefEntry entry in the pool already describes this method, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
owner- the class the method is a member ofname- the name of the methodtype- the type of the method- Returns:
- A
InterfaceMethodRefEntrydescribing a method of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
methodTypeEntry
Returns AMethodTypeEntrydescribing a method type. If a MethodType entry in the pool already describes this method type, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
descriptor- the symbolic descriptor of the method type- Returns:
- A
MethodTypeEntrydescribing a method type
-
methodTypeEntry
Returns AMethodTypeEntrydescribing a method type. If a MethodType entry in the pool already describes this method type, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
descriptor- the constant pool entry for the method type descriptor- Returns:
- A
MethodTypeEntrydescribing a method type
-
methodHandleEntry
Returns AMethodHandleEntrydescribing a direct method handle. If a MethodHandle entry in the pool already describes this method handle, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
descriptor- the symbolic descriptor of the method handle- Returns:
- A
MethodHandleEntrydescribing a direct method handle
-
methodHandleEntry
Returns AMethodHandleEntrydescribing a field accessor or method. If a MethodHandle entry in the pool already describes this method handle, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
refKind- the reference kind of the method handlereference- the constant pool entry describing the field or method- Returns:
- A
MethodHandleEntrydescribing a field accessor or method
-
invokeDynamicEntry
Returns AnInvokeDynamicEntrydescribing a dynamic call site. If an InvokeDynamic entry in the pool already describes this site, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
dcsd- the symbolic descriptor of the method handle- Returns:
- An
InvokeDynamicEntrydescribing a dynamic call site
-
invokeDynamicEntry
InvokeDynamicEntry invokeDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType) Returns AnInvokeDynamicEntrydescribing a dynamic call site. If an InvokeDynamic entry in the pool already describes this site, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
bootstrapMethodEntry- the entry in the bootstrap method tablenameAndType- the invocation name and type- Returns:
- An
InvokeDynamicEntrydescribing a dynamic call site
-
constantDynamicEntry
Returns AConstantDynamicEntrydescribing a dynamic constant. If a ConstantDynamic entry in the pool already describes this site, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
dcd- the symbolic descriptor of the constant- Returns:
- A
ConstantDynamicEntrydescribing a dynamic constant
-
constantDynamicEntry
ConstantDynamicEntry constantDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType) Returns AConstantDynamicEntrydescribing a dynamic constant. If a ConstantDynamic entry in the pool already describes this site, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
bootstrapMethodEntry- the entry in the bootstrap method tablenameAndType- the invocation name and type- Returns:
- A
ConstantDynamicEntrydescribing a dynamic constant
-
intEntry
Returns AnIntegerEntrydescribing the provided value. If an integer entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
value- the value- Returns:
- An
IntegerEntrydescribing the provided value
-
floatEntry
Returns AFloatEntrydescribing the provided value. If a float entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
value- the value- Returns:
- A
FloatEntrydescribing the provided value
-
longEntry
Returns ALongEntrydescribing the provided value. If a long entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
value- the value- Returns:
- A
LongEntrydescribing the provided value
-
doubleEntry
Returns ADoubleEntrydescribing the provided value. If a double entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
value- the value- Returns:
- A
DoubleEntrydescribing the provided value
-
stringEntry
Returns AStringEntryreferencing the provided UTF8 entry. If a String entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
utf8- the UTF8 entry describing the string- Returns:
- A
StringEntryreferencing the provided UTF8 entry
-
stringEntry
Returns AStringEntrydescribing the provided value. If a string entry in the pool already describes this value, it is returned; otherwise, a new entry is added and the new entry is returned.- Parameters:
value- the value- Returns:
- A
StringEntrydescribing the provided value
-
constantValueEntry
Returns AConstantValueEntrydescripbing the provided Integer, Long, Float, Double, or String constant.- Parameters:
c- the constant- Returns:
- A
ConstantValueEntrydescripbing the provided Integer, Long, Float, Double, or String constant
-
loadableConstantEntry
Returns ALoadableConstantEntrydescribing the provided constant. The constant should be an Integer, String, Long, Float, Double, ClassDesc (for a Class constant), MethodTypeDesc (for a MethodType constant), DirectMethodHandleDesc (for a MethodHandle constant), or a DynamicConstantDesc (for a dynamic constant.)- Parameters:
c- the constant- Returns:
- A
LoadableConstantEntrydescribing the provided constant
-
annotationConstantValueEntry
Returns AnAnnotationConstantValueEntrydescribing the provided constant. The constant should be an Integer, String, Long, Float, Double, ClassDesc (for a Class constant), or MethodTypeDesc (for a MethodType constant.)- Parameters:
c- the constant- Returns:
- An
AnnotationConstantValueEntrydescribing the provided constant
-
bsmEntry
default BootstrapMethodEntry bsmEntry(DirectMethodHandleDesc methodReference, List<ConstantDesc> arguments) Returns aBootstrapMethodEntrydescribing the provided bootstrap method and static arguments.- Parameters:
methodReference- the bootstrap methodarguments- the bootstrap arguments- Returns:
- a
BootstrapMethodEntrydescribing the provided bootstrap method and static arguments
-
bsmEntry
BootstrapMethodEntry bsmEntry(MethodHandleEntry methodReference, List<LoadableConstantEntry> arguments) Returns aBootstrapMethodEntrydescribing the provided bootstrap method and static arguments.- Parameters:
methodReference- the bootstrap methodarguments- the bootstrap arguments- Returns:
- a
BootstrapMethodEntrydescribing the provided bootstrap method and static arguments
-