Package net.bytebuddy.utility
Class JavaConstant.MethodHandle
java.lang.Object
net.bytebuddy.utility.JavaConstant.MethodHandle
- All Implemented Interfaces:
ConstantValue
,JavaConstant
- Enclosing interface:
JavaConstant
Represents a
java.lang.invoke.MethodHandle
object. Note that constant MethodHandle
s cannot
be represented within the constant pool of a Java class and can therefore not be represented as an instance of
this representation order.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
A representation of a method handle's type.protected static interface
A dispatcher to interact withjava.lang.invoke.MethodHandleInfo
.protected static interface
A dispatcher to interact withjava.lang.invoke.MethodHandles
.protected static interface
A dispatcher to interact withjava.lang.invoke.MethodType
.Nested classes/interfaces inherited from interface net.bytebuddy.utility.JavaConstant
JavaConstant.Dynamic, JavaConstant.MethodHandle, JavaConstant.Simple<T>, JavaConstant.Visitor<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JavaConstant.MethodHandle.HandleType
The handle type that is represented by this instance.protected static final JavaConstant.MethodHandle.MethodHandleInfo
A dispatcher to interact withjava.lang.invoke.MethodHandleInfo
.protected static final JavaConstant.MethodHandle.MethodHandles
A dispatcher to interact withjava.lang.invoke.MethodHandles
.protected static final JavaConstant.MethodHandle.MethodHandles.Lookup
A dispatcher to interact withjava.lang.invoke.MethodHandles$Lookup
.protected static final JavaConstant.MethodHandle.MethodType
A dispatcher to interact withjava.lang.invoke.MethodType
.private final String
The name that is represented by this instance.private final TypeDescription
The owner type that is represented by this instance.private final List
<? extends TypeDescription> The parameter types that is represented by this instance.private final TypeDescription
The return type that is represented by this instance. -
Constructor Summary
ConstructorsConstructorDescriptionMethodHandle
(JavaConstant.MethodHandle.HandleType handleType, TypeDescription ownerType, String name, TypeDescription returnType, List<? extends TypeDescription> parameterTypes) Creates a method handle representation. -
Method Summary
Modifier and TypeMethodDescription<T> T
accept
(JavaConstant.Visitor<T> visitor) Applies the supplied visitor to this constant type with its respective callback.private static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.boolean
Returns the method descriptor of this method handle representation.Returns the handle type represented by this instance.getName()
Returns the name represented by this instance.Returns the owner type of this instance.Returns the parameter types represented by this instance.Returns the return type represented by this instance.Returns a description of the type of this constant.int
hashCode()
static Class
<?> lookupType
(Object callerClassLookup) Returns the lookup type of the providedjava.lang.invoke.MethodHandles$Lookup
instance.static JavaConstant.MethodHandle
of
(Constructor<?> constructor) Creates a method handle representation of the given constructor.static JavaConstant.MethodHandle
Creates a method handle representation of the given method.static JavaConstant.MethodHandle
of
(MethodDescription.InDefinedShape methodDescription) Creates a method handle representation of the given method.static JavaConstant.MethodHandle
Resolves an ASMHandle
to aJavaConstant.MethodHandle
.static JavaConstant.MethodHandle
Returns a method handle for a setter of the given field.static JavaConstant.MethodHandle
ofGetter
(FieldDescription.InDefinedShape fieldDescription) Returns a method handle for a setter of the given field.static JavaConstant.MethodHandle
Creates a method handles representation of a loaded method handle which is analyzed using a publicMethodHandles.Lookup
object.static JavaConstant.MethodHandle
Creates a method handles representation of a loaded method handle which is analyzed using the given lookup context.static JavaConstant.MethodHandle
Returns a method handle for a getter of the given field.static JavaConstant.MethodHandle
ofSetter
(FieldDescription.InDefinedShape fieldDescription) Returns a method handle for a getter of the given field.static JavaConstant.MethodHandle
Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.static JavaConstant.MethodHandle
ofSpecial
(MethodDescription.InDefinedShape methodDescription, TypeDescription typeDescription) Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.Returns this constant as a Javajava.lang.constant.ConstantDesc
if the current VM is of at least version 12.Returns a stack manipulation loading this value.toString()
-
Field Details
-
METHOD_HANDLE_INFO
A dispatcher to interact withjava.lang.invoke.MethodHandleInfo
. -
METHOD_TYPE
A dispatcher to interact withjava.lang.invoke.MethodType
. -
METHOD_HANDLES
A dispatcher to interact withjava.lang.invoke.MethodHandles
. -
METHOD_HANDLES_LOOKUP
A dispatcher to interact withjava.lang.invoke.MethodHandles$Lookup
. -
handleType
The handle type that is represented by this instance. -
ownerType
The owner type that is represented by this instance. -
name
The name that is represented by this instance. -
returnType
The return type that is represented by this instance. -
parameterTypes
The parameter types that is represented by this instance.
-
-
Constructor Details
-
MethodHandle
public MethodHandle(JavaConstant.MethodHandle.HandleType handleType, TypeDescription ownerType, String name, TypeDescription returnType, List<? extends TypeDescription> parameterTypes) Creates a method handle representation.- Parameters:
handleType
- The handle type that is represented by this instance.ownerType
- The owner type that is represented by this instance.name
- The name that is represented by this instance.returnType
- The return type that is represented by this instance.parameterTypes
- The parameter types that is represented by this instance.
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
ofAsm
Resolves an ASMHandle
to aJavaConstant.MethodHandle
.- Parameters:
typePool
- The type pool to use for resolving type descriptions.handle
- TheHandle
to resolve.- Returns:
- An appropriate
JavaConstant.MethodHandle
.
-
ofLoaded
Creates a method handles representation of a loaded method handle which is analyzed using a publicMethodHandles.Lookup
object. A method handle can only be analyzed on virtual machines that support the corresponding API (Java 7+). For virtual machines before Java 8+, a method handle instance can only be analyzed by taking advantage of private APIs what might require a access context.- Parameters:
methodHandle
- The loaded method handle to represent.- Returns:
- A representation of the loaded method handle
-
ofLoaded
Creates a method handles representation of a loaded method handle which is analyzed using the given lookup context. A method handle can only be analyzed on virtual machines that support the corresponding API (Java 7+). For virtual machines before Java 8+, a method handle instance can only be analyzed by taking advantage of private APIs what might require a access context.- Parameters:
methodHandle
- The loaded method handle to represent.lookup
- The lookup object to use for analyzing the method handle.- Returns:
- A representation of the loaded method handle
-
of
Creates a method handle representation of the given method.- Parameters:
method
- The method ro represent.- Returns:
- A method handle representing the given method.
-
of
Creates a method handle representation of the given constructor.- Parameters:
constructor
- The constructor ro represent.- Returns:
- A method handle representing the given constructor.
-
of
Creates a method handle representation of the given method.- Parameters:
methodDescription
- The method ro represent.- Returns:
- A method handle representing the given method.
-
ofSpecial
Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.- Parameters:
method
- The method ro represent.type
- The type on which the method is to be invoked on as a special method invocation.- Returns:
- A method handle representing the given method as special method invocation.
-
ofSpecial
public static JavaConstant.MethodHandle ofSpecial(MethodDescription.InDefinedShape methodDescription, TypeDescription typeDescription) Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method.- Parameters:
methodDescription
- The method ro represent.typeDescription
- The type on which the method is to be invoked on as a special method invocation.- Returns:
- A method handle representing the given method as special method invocation.
-
ofGetter
Returns a method handle for a setter of the given field.- Parameters:
field
- The field to represent.- Returns:
- A method handle for a setter of the given field.
-
ofGetter
Returns a method handle for a setter of the given field.- Parameters:
fieldDescription
- The field to represent.- Returns:
- A method handle for a setter of the given field.
-
ofSetter
Returns a method handle for a getter of the given field.- Parameters:
field
- The field to represent.- Returns:
- A method handle for a getter of the given field.
-
ofSetter
Returns a method handle for a getter of the given field.- Parameters:
fieldDescription
- The field to represent.- Returns:
- A method handle for a getter of the given field.
-
lookupType
Returns the lookup type of the providedjava.lang.invoke.MethodHandles$Lookup
instance.- Parameters:
callerClassLookup
- An instance ofjava.lang.invoke.MethodHandles$Lookup
.- Returns:
- The instance's lookup type.
-
toDescription
Returns this constant as a Javajava.lang.constant.ConstantDesc
if the current VM is of at least version 12. If the current VM is of an older version and does not support the type, an exception is thrown.- Specified by:
toDescription
in interfaceJavaConstant
- Returns:
- This constant as a Java
java.lang.constant.ConstantDesc
.
-
accept
Applies the supplied visitor to this constant type with its respective callback.- Specified by:
accept
in interfaceJavaConstant
- Type Parameters:
T
- The type of the value that is returned by the visitor.- Parameters:
visitor
- The visitor to dispatch.- Returns:
- The value that is returned by the supplied visitor.
-
getTypeDescription
Returns a description of the type of this constant.- Specified by:
getTypeDescription
in interfaceConstantValue
- Returns:
- A description of the type of this constant.
-
toStackManipulation
Returns a stack manipulation loading this value.- Specified by:
toStackManipulation
in interfaceConstantValue
- Returns:
- A stack manipulation loading this value.
-
getHandleType
Returns the handle type represented by this instance.- Returns:
- The handle type represented by this instance.
-
getOwnerType
Returns the owner type of this instance.- Returns:
- The owner type of this instance.
-
getName
Returns the name represented by this instance.- Returns:
- The name represented by this instance.
-
getReturnType
Returns the return type represented by this instance.- Returns:
- The return type represented by this instance.
-
getParameterTypes
Returns the parameter types represented by this instance.- Returns:
- The parameter types represented by this instance.
-
getDescriptor
Returns the method descriptor of this method handle representation.- Returns:
- The method descriptor of this method handle representation.
-
hashCode
public int hashCode() -
equals
-
toString
-