Package net.bytebuddy.utility
Class JavaConstant.MethodHandle
- java.lang.Object
-
- net.bytebuddy.utility.JavaConstant.MethodHandle
-
- All Implemented Interfaces:
JavaConstant
- Enclosing interface:
- JavaConstant
public static class JavaConstant.MethodHandle extends java.lang.Object implements JavaConstant
Represents ajava.lang.invoke.MethodHandle
object. Note that constantMethodHandle
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 Classes Modifier and Type Class Description protected static interface
JavaConstant.MethodHandle.Dispatcher
A dispatcher for analyzing ajava.lang.invoke.MethodHandle
instance.static class
JavaConstant.MethodHandle.HandleType
A representation of a method handle's type.-
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 JavaConstant.MethodHandle.Dispatcher.Initializable
DISPATCHER
A dispatcher for receiving the type information that is represented by ajava.lang.invoke.MethodHandle
instance.private JavaConstant.MethodHandle.HandleType
handleType
The handle type that is represented by this instance.private java.lang.String
name
The name that is represented by this instance.private TypeDescription
ownerType
The owner type that is represented by this instance.private java.util.List<? extends TypeDescription>
parameterTypes
The parameter types that is represented by this instance.private TypeDescription
returnType
The return type that is represented by this instance.
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodHandle(JavaConstant.MethodHandle.HandleType handleType, TypeDescription ownerType, java.lang.String name, TypeDescription returnType, java.util.List<? extends TypeDescription> parameterTypes)
Creates a method handle representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
asConstantPoolValue()
Returns the represented instance as a constant pool value.boolean
equals(java.lang.Object other)
java.lang.String
getDescriptor()
Returns the method descriptor of this method handle representation.JavaConstant.MethodHandle.HandleType
getHandleType()
Returns the handle type represented by this instance.java.lang.String
getName()
Returns the name represented by this instance.TypeDescription
getOwnerType()
Returns the owner type of this instance.TypeList
getParameterTypes()
Returns the parameter types represented by this instance.TypeDescription
getReturnType()
Returns the return type represented by this instance.TypeDescription
getType()
Returns a description of the type of the represented instance or at least a stub.int
hashCode()
static java.lang.Class<?>
lookupType(java.lang.Object callerClassLookup)
Returns the lookup type of the providedjava.lang.invoke.MethodHandles$Lookup
instance.static JavaConstant.MethodHandle
of(java.lang.reflect.Constructor<?> constructor)
Creates a method handle representation of the given constructor.static JavaConstant.MethodHandle
of(java.lang.reflect.Method method)
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
ofGetter(java.lang.reflect.Field field)
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
ofLoaded(java.lang.Object methodHandle)
Creates a method handles representation of a loaded method handle which is analyzed using a publicMethodHandles.Lookup
object.static JavaConstant.MethodHandle
ofLoaded(java.lang.Object methodHandle, java.lang.Object lookup)
Creates a method handles representation of a loaded method handle which is analyzed using the given lookup context.static JavaConstant.MethodHandle
ofSetter(java.lang.reflect.Field field)
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
ofSpecial(java.lang.reflect.Method method, java.lang.Class<?> type)
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.
-
-
-
Field Detail
-
DISPATCHER
private static final JavaConstant.MethodHandle.Dispatcher.Initializable DISPATCHER
A dispatcher for receiving the type information that is represented by ajava.lang.invoke.MethodHandle
instance.
-
handleType
private final JavaConstant.MethodHandle.HandleType handleType
The handle type that is represented by this instance.
-
ownerType
private final TypeDescription ownerType
The owner type that is represented by this instance.
-
name
private final java.lang.String name
The name that is represented by this instance.
-
returnType
private final TypeDescription returnType
The return type that is represented by this instance.
-
parameterTypes
private final java.util.List<? extends TypeDescription> parameterTypes
The parameter types that is represented by this instance.
-
-
Constructor Detail
-
MethodHandle
protected MethodHandle(JavaConstant.MethodHandle.HandleType handleType, TypeDescription ownerType, java.lang.String name, TypeDescription returnType, java.util.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 Detail
-
ofLoaded
public static JavaConstant.MethodHandle ofLoaded(java.lang.Object methodHandle)
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
public static JavaConstant.MethodHandle ofLoaded(java.lang.Object methodHandle, java.lang.Object lookup)
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
public static JavaConstant.MethodHandle of(java.lang.reflect.Method method)
Creates a method handle representation of the given method.- Parameters:
method
- The method ro represent.- Returns:
- A method handle representing the given method.
-
of
public static JavaConstant.MethodHandle of(java.lang.reflect.Constructor<?> constructor)
Creates a method handle representation of the given constructor.- Parameters:
constructor
- The constructor ro represent.- Returns:
- A method handle representing the given constructor.
-
of
public static JavaConstant.MethodHandle of(MethodDescription.InDefinedShape methodDescription)
Creates a method handle representation of the given method.- Parameters:
methodDescription
- The method ro represent.- Returns:
- A method handle representing the given method.
-
ofSpecial
public static JavaConstant.MethodHandle ofSpecial(java.lang.reflect.Method method, java.lang.Class<?> type)
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
public static JavaConstant.MethodHandle ofGetter(java.lang.reflect.Field field)
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
public static JavaConstant.MethodHandle ofGetter(FieldDescription.InDefinedShape fieldDescription)
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
public static JavaConstant.MethodHandle ofSetter(java.lang.reflect.Field field)
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
public static JavaConstant.MethodHandle ofSetter(FieldDescription.InDefinedShape fieldDescription)
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.
-
asConstantPoolValue
public java.lang.Object asConstantPoolValue()
Returns the represented instance as a constant pool value.- Specified by:
asConstantPoolValue
in 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:
getType
in interfaceJavaConstant
- Returns:
- A description of the type of the represented instance or at least a stub.
-
getHandleType
public JavaConstant.MethodHandle.HandleType getHandleType()
Returns the handle type represented by this instance.- Returns:
- The handle type represented by this instance.
-
getOwnerType
public TypeDescription getOwnerType()
Returns the owner type of this instance.- Returns:
- The owner type of this instance.
-
getName
public java.lang.String getName()
Returns the name represented by this instance.- Returns:
- The name represented by this instance.
-
getReturnType
public TypeDescription getReturnType()
Returns the return type represented by this instance.- Returns:
- The return type represented by this instance.
-
getParameterTypes
public TypeList getParameterTypes()
Returns the parameter types represented by this instance.- Returns:
- The parameter types represented by this instance.
-
getDescriptor
public java.lang.String getDescriptor()
Returns the method descriptor of this method handle representation.- Returns:
- The method descriptor of this method handle representation.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
lookupType
public static java.lang.Class<?> lookupType(java.lang.Object callerClassLookup)
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.
-
-