Interface ConstantPoolBuilder
- All Superinterfaces:
ConstantPoolPREVIEW,Iterable<PoolEntryPREVIEW>
ConstantPoolBuilder is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
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
ClassBuilderPREVIEW.
The ConstantPoolBuilder also provides access to some of the
state of the ClassBuilder, such as classfile processing options.- Since:
- 22
-
Method Summary
Modifier and TypeMethodDescriptionbsmEntry(MethodHandleEntryPREVIEW methodReference, List<LoadableConstantEntryPREVIEW> arguments) Returns aBootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments.default BootstrapMethodEntryPREVIEWbsmEntry(DirectMethodHandleDesc methodReference, List<ConstantDesc> arguments) Returns aBootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments.booleancanWriteDirect(ConstantPoolPREVIEW constantPool) Returns whether the provided constant pool is index-compatible with this one.Returns AClassEntryPREVIEW describing the class whose internal name is encoded in the provided Utf8Entry.default ClassEntryPREVIEWclassEntry(ClassDesc classDesc) constantDynamicEntry(BootstrapMethodEntryPREVIEW bootstrapMethodEntry, NameAndTypeEntryPREVIEW nameAndType) Returns AConstantDynamicEntryPREVIEW describing a dynamic constant.default ConstantDynamicEntryPREVIEWReturns AConstantDynamicEntryPREVIEW describing a dynamic constant.default ConstantValueEntryPREVIEWReturns AConstantValueEntryPREVIEW describing the provided Integer, Long, Float, Double, or String constant.doubleEntry(double value) Returns ADoubleEntryPREVIEW describing the provided value.fieldRefEntry(ClassEntryPREVIEW owner, NameAndTypeEntryPREVIEW nameAndType) Returns AFieldRefEntryPREVIEW describing a field of a class.default FieldRefEntryPREVIEWfieldRefEntry(ClassDesc owner, String name, ClassDesc type) Returns AFieldRefEntryPREVIEW describing a field of a class.floatEntry(float value) Returns AFloatEntryPREVIEW describing the provided value.intEntry(int value) Returns AnIntegerEntryPREVIEW describing the provided value.interfaceMethodRefEntry(ClassEntryPREVIEW owner, NameAndTypeEntryPREVIEW nameAndType) Returns AInterfaceMethodRefEntryPREVIEW describing a method of a class.default InterfaceMethodRefEntryPREVIEWinterfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AInterfaceMethodRefEntryPREVIEW describing a method of a class.invokeDynamicEntry(BootstrapMethodEntryPREVIEW bootstrapMethodEntry, NameAndTypeEntryPREVIEW nameAndType) Returns AnInvokeDynamicEntryPREVIEW describing a dynamic call site.default InvokeDynamicEntryPREVIEWReturns AnInvokeDynamicEntryPREVIEW describing a dynamic call site.default LoadableConstantEntryPREVIEWReturns ALoadableConstantEntryPREVIEW describing the provided constant.longEntry(long value) methodHandleEntry(int refKind, MemberRefEntryPREVIEW reference) Returns AMethodHandleEntryPREVIEW describing a field accessor or method.default MethodHandleEntryPREVIEWmethodHandleEntry(DirectMethodHandleDesc descriptor) Returns AMethodHandleEntryPREVIEW describing a direct method handle.methodRefEntry(ClassEntryPREVIEW owner, NameAndTypeEntryPREVIEW nameAndType) Returns AMethodRefEntryPREVIEW describing a method of a class.default MethodRefEntryPREVIEWmethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AMethodRefEntryPREVIEW describing a method of a class.methodTypeEntry(Utf8EntryPREVIEW descriptor) Returns AMethodTypeEntryPREVIEW describing a method type.methodTypeEntry(MethodTypeDesc descriptor) Returns AMethodTypeEntryPREVIEW describing a method type.moduleEntry(Utf8EntryPREVIEW moduleName) default ModuleEntryPREVIEWmoduleEntry(ModuleDesc moduleDesc) nameAndTypeEntry(Utf8EntryPREVIEW nameEntry, Utf8EntryPREVIEW typeEntry) Returns ANameAndTypeEntryPREVIEW describing the provided name and type.default NameAndTypeEntryPREVIEWnameAndTypeEntry(String name, ClassDesc type) Returns ANameAndTypeEntryPREVIEW describing the provided name and type.default NameAndTypeEntryPREVIEWnameAndTypeEntry(String name, MethodTypeDesc type) Returns ANameAndTypeEntryPREVIEW describing the provided name and type.static ConstantPoolBuilderPREVIEWof()Returns a new constant pool builder.static ConstantPoolBuilderPREVIEWof(ClassModelPREVIEW classModel) Returns a new constant pool builder.packageEntry(Utf8EntryPREVIEW nameEntry) Returns APackageEntryPREVIEW describing the class whose internal name is encoded in the provided Utf8Entry.default PackageEntryPREVIEWpackageEntry(PackageDesc packageDesc) stringEntry(Utf8EntryPREVIEW utf8) Returns AStringEntryPREVIEW referencing the provided UTF8 entry.default StringEntryPREVIEWstringEntry(String value) Returns AStringEntryPREVIEW describing the provided value.utf8Entry(MethodTypeDesc desc) Methods declared in interface java.lang.classfile.constantpool.ConstantPoolPREVIEW
bootstrapMethodCount, bootstrapMethodEntry, entryByIndex, entryByIndex, iterator, sizeMethods declared in interface java.lang.Iterable
forEach, spliterator
-
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
-
utf8Entry
-
utf8Entry
-
utf8Entry
Returns AUtf8EntryPREVIEW describing 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
Utf8EntryPREVIEW describing the method descriptor of the provided MethodTypeDesc
-
classEntry
Returns AClassEntryPREVIEW describing 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
ClassEntryPREVIEW describing the class whose internal name is encoded in the provided Utf8Entry
-
classEntry
Returns AClassEntryPREVIEW describing 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
ClassEntryPREVIEW describing the class described by provided ClassDesc - Throws:
IllegalArgumentException- ifclassDescrepresents a primitive type
-
packageEntry
Returns APackageEntryPREVIEW describing 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
PackageEntryPREVIEW describing the class whose internal name is encoded in the provided Utf8Entry
-
packageEntry
Returns APackageEntryPREVIEW describing 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
PackageEntryPREVIEW describing the class described by provided PackageDesc
-
moduleEntry
Returns AModuleEntryPREVIEW describing 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
ModuleEntryPREVIEW describing the module whose name is encoded in the provided Utf8Entry
-
moduleEntry
Returns AModuleEntryPREVIEW describing 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
ModuleEntryPREVIEW describing the module described by provided ModuleDesc
-
nameAndTypeEntry
Returns ANameAndTypeEntryPREVIEW describing 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
NameAndTypeEntryPREVIEW describing the provided name and type
-
nameAndTypeEntry
Returns ANameAndTypeEntryPREVIEW describing 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
NameAndTypeEntryPREVIEW describing the provided name and type
-
nameAndTypeEntry
Returns ANameAndTypeEntryPREVIEW describing 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
NameAndTypeEntryPREVIEW describing the provided name and type
-
fieldRefEntry
Returns AFieldRefEntryPREVIEW describing 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
FieldRefEntryPREVIEW describing a field of a class
-
fieldRefEntry
Returns AFieldRefEntryPREVIEW describing 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
FieldRefEntryPREVIEW describing a field of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
methodRefEntry
Returns AMethodRefEntryPREVIEW describing 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
MethodRefEntryPREVIEW describing a method of a class
-
methodRefEntry
Returns AMethodRefEntryPREVIEW describing 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
MethodRefEntryPREVIEW describing a method of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
interfaceMethodRefEntry
InterfaceMethodRefEntryPREVIEW interfaceMethodRefEntry(ClassEntryPREVIEW owner, NameAndTypeEntryPREVIEW nameAndType) Returns AInterfaceMethodRefEntryPREVIEW describing 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
InterfaceMethodRefEntryPREVIEW describing a method of a class
-
interfaceMethodRefEntry
default InterfaceMethodRefEntryPREVIEW interfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) Returns AInterfaceMethodRefEntryPREVIEW describing 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
InterfaceMethodRefEntryPREVIEW describing a method of a class - Throws:
IllegalArgumentException- ifownerrepresents a primitive type
-
methodTypeEntry
Returns AMethodTypeEntryPREVIEW describing 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
MethodTypeEntryPREVIEW describing a method type
-
methodTypeEntry
Returns AMethodTypeEntryPREVIEW describing 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
MethodTypeEntryPREVIEW describing a method type
-
methodHandleEntry
Returns AMethodHandleEntryPREVIEW describing 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
MethodHandleEntryPREVIEW describing a direct method handle
-
methodHandleEntry
Returns AMethodHandleEntryPREVIEW describing 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 handle (JVMS 4.4.8)reference- the constant pool entry describing the field or method- Returns:
- A
MethodHandleEntryPREVIEW describing a field accessor or method
-
invokeDynamicEntry
Returns AnInvokeDynamicEntryPREVIEW describing 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
InvokeDynamicEntryPREVIEW describing a dynamic call site
-
invokeDynamicEntry
InvokeDynamicEntryPREVIEW invokeDynamicEntry(BootstrapMethodEntryPREVIEW bootstrapMethodEntry, NameAndTypeEntryPREVIEW nameAndType) Returns AnInvokeDynamicEntryPREVIEW describing 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
InvokeDynamicEntryPREVIEW describing a dynamic call site
-
constantDynamicEntry
Returns AConstantDynamicEntryPREVIEW describing 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
ConstantDynamicEntryPREVIEW describing a dynamic constant
-
constantDynamicEntry
ConstantDynamicEntryPREVIEW constantDynamicEntry(BootstrapMethodEntryPREVIEW bootstrapMethodEntry, NameAndTypeEntryPREVIEW nameAndType) Returns AConstantDynamicEntryPREVIEW describing 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
ConstantDynamicEntryPREVIEW describing a dynamic constant
-
intEntry
Returns AnIntegerEntryPREVIEW describing 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
IntegerEntryPREVIEW describing the provided value
-
floatEntry
Returns AFloatEntryPREVIEW describing 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
FloatEntryPREVIEW describing the provided value
-
longEntry
-
doubleEntry
Returns ADoubleEntryPREVIEW describing 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
DoubleEntryPREVIEW describing the provided value
-
stringEntry
Returns AStringEntryPREVIEW referencing 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
StringEntryPREVIEW referencing the provided UTF8 entry
-
stringEntry
Returns AStringEntryPREVIEW describing 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
StringEntryPREVIEW describing the provided value
-
constantValueEntry
Returns AConstantValueEntryPREVIEW describing the provided Integer, Long, Float, Double, or String constant.- Parameters:
c- the constant- Returns:
- A
ConstantValueEntryPREVIEW describing the provided Integer, Long, Float, Double, or String constant - See Also:
-
loadableConstantEntry
Returns ALoadableConstantEntryPREVIEW describing 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
LoadableConstantEntryPREVIEW describing the provided constant
-
bsmEntry
default BootstrapMethodEntryPREVIEW bsmEntry(DirectMethodHandleDesc methodReference, List<ConstantDesc> arguments) Returns aBootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments.- Parameters:
methodReference- the bootstrap methodarguments- the bootstrap arguments- Returns:
- a
BootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments
-
bsmEntry
BootstrapMethodEntryPREVIEW bsmEntry(MethodHandleEntryPREVIEW methodReference, List<LoadableConstantEntryPREVIEW> arguments) Returns aBootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments.- Parameters:
methodReference- the bootstrap methodarguments- the bootstrap arguments- Returns:
- a
BootstrapMethodEntryPREVIEW describing the provided bootstrap method and static arguments
-
ConstantPoolBuilderwhen preview features are enabled.