Package net.bytebuddy.utility
Class JavaConstant.Dynamic
- java.lang.Object
-
- net.bytebuddy.utility.JavaConstant.Dynamic
-
- All Implemented Interfaces:
JavaConstant
- Enclosing interface:
- JavaConstant
public static class JavaConstant.Dynamic extends java.lang.Object implements JavaConstant
Represents a dynamically resolved constant pool entry of a class file. This feature is supported for class files in version 11 and newer.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.bytebuddy.utility.JavaConstant
JavaConstant.Dynamic, JavaConstant.MethodHandle, JavaConstant.MethodType
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCONSTANT_BOOTSTRAPSThejava.lang.invoke.ConstantBootstrapsclass's internal name..private TypeDescriptiontypeDescriptionThe represented value constant.private org.objectweb.asm.ConstantDynamicvalueThe represented bootstrap value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDynamic(org.objectweb.asm.ConstantDynamic value, TypeDescription typeDescription)Creates a new dynamic class pool entry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectasConstantPoolValue()Returns the represented instance as a constant pool value.static JavaConstant.Dynamicbootstrap(java.lang.String name, java.lang.reflect.Constructor<?> constructor, java.lang.Object... constant)Binds the supplied bootstrap constructor for the resolution of a dynamic constant.static JavaConstant.Dynamicbootstrap(java.lang.String name, java.lang.reflect.Constructor<?> constructor, java.util.List<?> constants)Binds the supplied bootstrap constructor for the resolution of a dynamic constant.static JavaConstant.Dynamicbootstrap(java.lang.String name, java.lang.reflect.Method method, java.lang.Object... constant)Binds the supplied bootstrap method for the resolution of a dynamic constant.static JavaConstant.Dynamicbootstrap(java.lang.String name, java.lang.reflect.Method method, java.util.List<?> constants)Binds the supplied bootstrap method for the resolution of a dynamic constant.static JavaConstant.Dynamicbootstrap(java.lang.String name, MethodDescription.InDefinedShape bootstrapMethod, java.lang.Object... constant)Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.static JavaConstant.Dynamicbootstrap(java.lang.String name, MethodDescription.InDefinedShape bootstrap, java.util.List<?> constants)Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.booleanequals(java.lang.Object other)TypeDescriptiongetType()Returns a description of the type of the represented instance or at least a stub.inthashCode()static JavaConstantofArrayVarHandle(java.lang.Class<?> type)Resolves a var handle constant for an array.static JavaConstantofArrayVarHandle(TypeDescription typeDescription)Resolves a var handle constant for an array.static JavaConstantofEnumeration(java.lang.Enum<?> enumeration)Returns aEnumvalue constant.static JavaConstantofEnumeration(EnumerationDescription enumerationDescription)Returns aEnumvalue constant.static JavaConstant.DynamicofField(java.lang.reflect.Field field)Returns astatic,finalfield constant.static JavaConstant.DynamicofField(FieldDescription.InDefinedShape fieldDescription)Returns astatic,finalfield constant.static JavaConstant.DynamicofInvocation(java.lang.reflect.Constructor<?> constructor, java.lang.Object... constant)Represents a constant that is resolved by invoking a constructor.static JavaConstant.DynamicofInvocation(java.lang.reflect.Constructor<?> constructor, java.util.List<?> constants)Represents a constant that is resolved by invoking a constructor.static JavaConstant.DynamicofInvocation(java.lang.reflect.Method method, java.lang.Object... constant)Represents a constant that is resolved by invoking astaticfactory method.static JavaConstant.DynamicofInvocation(java.lang.reflect.Method method, java.util.List<?> constants)Represents a constant that is resolved by invoking astaticfactory method.static JavaConstant.DynamicofInvocation(MethodDescription.InDefinedShape methodDescription, java.lang.Object... constant)Represents a constant that is resolved by invoking astaticfactory method or a constructor.static JavaConstant.DynamicofInvocation(MethodDescription.InDefinedShape methodDescription, java.util.List<?> constants)Represents a constant that is resolved by invoking astaticfactory method or a constructor.static JavaConstant.DynamicofNullConstant()Returns a constantnullvalue of typeObject.static JavaConstantofPrimitiveType(java.lang.Class<?> type)Returns aClassconstant for a primitive type.static JavaConstantofPrimitiveType(TypeDescription typeDescription)Returns aClassconstant for a primitive type.static JavaConstantofVarHandle(java.lang.reflect.Field field)Resolves a var handle constant for a field.static JavaConstantofVarHandle(FieldDescription.InDefinedShape fieldDescription)Resolves a var handle constant for a field.JavaConstantwithType(java.lang.Class<?> type)Resolves thisJavaConstant.Dynamicconstant to resolve the returned instance to the supplied type.JavaConstantwithType(TypeDescription typeDescription)Resolves thisJavaConstant.Dynamicconstant to resolve the returned instance to the supplied type.
-
-
-
Field Detail
-
CONSTANT_BOOTSTRAPS
private static final java.lang.String CONSTANT_BOOTSTRAPS
Thejava.lang.invoke.ConstantBootstrapsclass's internal name..- See Also:
- Constant Field Values
-
value
private final org.objectweb.asm.ConstantDynamic value
The represented bootstrap value.
-
typeDescription
private final TypeDescription typeDescription
The represented value constant.
-
-
Constructor Detail
-
Dynamic
protected Dynamic(org.objectweb.asm.ConstantDynamic value, TypeDescription typeDescription)Creates a new dynamic class pool entry.- Parameters:
value- The represented bootstrap value.typeDescription- The represented value constant.
-
-
Method Detail
-
ofNullConstant
public static JavaConstant.Dynamic ofNullConstant()
Returns a constantnullvalue of typeObject.- Returns:
- A dynamically resolved null constant.
-
ofPrimitiveType
public static JavaConstant ofPrimitiveType(java.lang.Class<?> type)
Returns aClassconstant for a primitive type.- Parameters:
type- The primitive type to represent.- Returns:
- A dynamically resolved primitive type constant.
-
ofPrimitiveType
public static JavaConstant ofPrimitiveType(TypeDescription typeDescription)
Returns aClassconstant for a primitive type.- Parameters:
typeDescription- The primitive type to represent.- Returns:
- A dynamically resolved primitive type constant.
-
ofEnumeration
public static JavaConstant ofEnumeration(java.lang.Enum<?> enumeration)
Returns aEnumvalue constant.- Parameters:
enumeration- The enumeration value to represent.- Returns:
- A dynamically resolved enumeration constant.
-
ofEnumeration
public static JavaConstant ofEnumeration(EnumerationDescription enumerationDescription)
Returns aEnumvalue constant.- Parameters:
enumerationDescription- The enumeration value to represent.- Returns:
- A dynamically resolved enumeration constant.
-
ofField
public static JavaConstant.Dynamic ofField(java.lang.reflect.Field field)
Returns astatic,finalfield constant.- Parameters:
field- The field to represent a value of.- Returns:
- A dynamically resolved field value constant.
-
ofField
public static JavaConstant.Dynamic ofField(FieldDescription.InDefinedShape fieldDescription)
Returns astatic,finalfield constant.- Parameters:
fieldDescription- The field to represent a value of.- Returns:
- A dynamically resolved field value constant.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(java.lang.reflect.Method method, java.lang.Object... constant)
Represents a constant that is resolved by invoking astaticfactory method.- Parameters:
method- The method to invoke to create the represented constant value.constant- The method's constant arguments.- Returns:
- A dynamic constant that is resolved by the supplied factory method.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(java.lang.reflect.Method method, java.util.List<?> constants)
Represents a constant that is resolved by invoking astaticfactory method.- Parameters:
method- The method to invoke to create the represented constant value.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that is resolved by the supplied factory method.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(java.lang.reflect.Constructor<?> constructor, java.lang.Object... constant)
Represents a constant that is resolved by invoking a constructor.- Parameters:
constructor- The constructor to invoke to create the represented constant value.constant- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that is resolved by the supplied constuctor.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(java.lang.reflect.Constructor<?> constructor, java.util.List<?> constants)
Represents a constant that is resolved by invoking a constructor.- Parameters:
constructor- The constructor to invoke to create the represented constant value.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that is resolved by the supplied constuctor.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(MethodDescription.InDefinedShape methodDescription, java.lang.Object... constant)
Represents a constant that is resolved by invoking astaticfactory method or a constructor.- Parameters:
methodDescription- The method or constructor to invoke to create the represented constant value.constant- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that is resolved by the supplied factory method or constructor.
-
ofInvocation
public static JavaConstant.Dynamic ofInvocation(MethodDescription.InDefinedShape methodDescription, java.util.List<?> constants)
Represents a constant that is resolved by invoking astaticfactory method or a constructor.- Parameters:
methodDescription- The method or constructor to invoke to create the represented constant value.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that is resolved by the supplied factory method or constructor.
-
ofVarHandle
public static JavaConstant ofVarHandle(java.lang.reflect.Field field)
Resolves a var handle constant for a field.- Parameters:
field- The field to represent a var handle for.- Returns:
- A dynamic constant that represents the created var handle constant.
-
ofVarHandle
public static JavaConstant ofVarHandle(FieldDescription.InDefinedShape fieldDescription)
Resolves a var handle constant for a field.- Parameters:
fieldDescription- The field to represent a var handle for.- Returns:
- A dynamic constant that represents the created var handle constant.
-
ofArrayVarHandle
public static JavaConstant ofArrayVarHandle(java.lang.Class<?> type)
Resolves a var handle constant for an array.- Parameters:
type- The array type for which the var handle is resolved.- Returns:
- A dynamic constant that represents the created var handle constant.
-
ofArrayVarHandle
public static JavaConstant ofArrayVarHandle(TypeDescription typeDescription)
Resolves a var handle constant for an array.- Parameters:
typeDescription- The array type for which the var handle is resolved.- Returns:
- A dynamic constant that represents the created var handle constant.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, java.lang.reflect.Method method, java.lang.Object... constant)
Binds the supplied bootstrap method for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.method- The bootstrap method to invoke.constant- The arguments for the bootstrap method represented as primitive wrapper types,String,TypeDescriptionorJavaConstantvalues or their loaded forms.- Returns:
- A dynamic constant that represents the bootstrapped method's result.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, java.lang.reflect.Method method, java.util.List<?> constants)
Binds the supplied bootstrap method for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.method- The bootstrap method to invoke.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that represents the bootstrapped method's result.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, java.lang.reflect.Constructor<?> constructor, java.lang.Object... constant)
Binds the supplied bootstrap constructor for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.constructor- The bootstrap constructor to invoke.constant- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that represents the bootstrapped constructor's result.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, java.lang.reflect.Constructor<?> constructor, java.util.List<?> constants)
Binds the supplied bootstrap constructor for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.constructor- The bootstrap constructor to invoke.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that represents the bootstrapped constructor's result.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, MethodDescription.InDefinedShape bootstrapMethod, java.lang.Object... constant)
Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.bootstrapMethod- The bootstrap method or constructor to invoke.constant- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that represents the bootstrapped method's or constructor's result.
-
bootstrap
public static JavaConstant.Dynamic bootstrap(java.lang.String name, MethodDescription.InDefinedShape bootstrap, java.util.List<?> constants)
Binds the supplied bootstrap method or constructor for the resolution of a dynamic constant.- Parameters:
name- The name of the bootstrap constant that is provided to the bootstrap method or constructor.bootstrap- The bootstrap method or constructor to invoke.constants- The constant values passed to the bootstrap method. Values can be represented either asTypeDescription, asJavaConstant, asStringor a primitiveint,long,floatordoublerepresented as wrapper type.- Returns:
- A dynamic constant that represents the bootstrapped method's or constructor's result.
-
withType
public JavaConstant withType(java.lang.Class<?> type)
Resolves thisJavaConstant.Dynamicconstant to resolve the returned instance to the supplied type. The type must be a subtype of the bootstrap method's return type. Constructors cannot be resolved to a different type.- Parameters:
type- The type to resolve the bootstrapped value to.- Returns:
- This dynamic constant but resolved to the supplied type.
-
withType
public JavaConstant withType(TypeDescription typeDescription)
Resolves thisJavaConstant.Dynamicconstant to resolve the returned instance to the supplied type. The type must be a subtype of the bootstrap method's return type. Constructors cannot be resolved to a different type.- Parameters:
typeDescription- The type to resolve the bootstrapped value to.- Returns:
- This dynamic constant but resolved to the supplied type.
-
asConstantPoolValue
public java.lang.Object asConstantPoolValue()
Returns the represented instance as a constant pool value.- Specified by:
asConstantPoolValuein interfaceJavaConstant- Returns:
- The constant pool value in a format that can be written by ASM.
-
getType
public TypeDescription getType()
Returns a description of the type of the represented instance or at least a stub.- Specified by:
getTypein interfaceJavaConstant- Returns:
- A description of the type of the represented instance or at least a stub.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
-