Package io.microsphere.invoke
Class MethodHandleUtils
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.invoke.MethodHandleUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMethodHandleUtils.LookupModeThe allowedMethodHandles.Lookupmodes enumeration
-
Field Summary
Fields Modifier and Type Field Description static intALL_MODESA single-bit mask representing all accesses (public, private, protected and package) The value, 0x0f, happens to be the same as the value of the modifier bit.static intMODULEA single-bit mask representingmoduleaccess, which may contribute to the result oflookupModes.static java.lang.invoke.MethodHandleNOT_FOUND_METHOD_HANDLEMethodHandlefor Not-Foundstatic intORIGINALA single-bit mask representingoriginalaccess which may contribute to the result oflookupModes.static intPACKAGEA single-bit mask representingpackageaccess (default access), which may contribute to the result oflookupModes.static intPRIVATEA single-bit mask representingprivateaccess, which may contribute to the result oflookupModes.static intPROTECTEDA single-bit mask representingprotectedaccess, which may contribute to the result oflookupModes.static intPUBLICA single-bit mask representingpublicaccess, which may contribute to the result oflookupModes.static intUNCONDITIONALA single-bit mask representingunconditionalaccess which may contribute to the result oflookupModes.
-
Constructor Summary
Constructors Constructor Description MethodHandleUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.invoke.MethodHandlefind(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)static java.lang.invoke.MethodHandlefindStatic(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)The convenient method to findMethodHandles.Lookup.findStatic(Class, String, MethodType)static java.lang.invoke.MethodHandlefindVirtual(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)The convenient method to findMethodHandles.Lookup.findVirtual(Class, String, MethodType)static java.lang.invoke.MethodHandles.Lookuplookup(java.lang.Class<?> lookupClass)Create an instance ofMethodHandles.Lookupby the specified lookup class withall accesses (public, private, protected and package)static java.lang.invoke.MethodHandles.Lookuplookup(java.lang.Class<?> lookupClass, MethodHandleUtils.LookupMode... lookupModes)Create an instance ofMethodHandles.Lookupby the specified lookup class withall access (public, private, protected and package)
-
-
-
Field Detail
-
PUBLIC
public static final int PUBLIC
A single-bit mask representingpublicaccess, which may contribute to the result oflookupModes. The value,0x01, happens to be the same as the value of thepublicmodifier bit.A
Lookupwith this lookup mode performs cross-module access check with respect to the lookup class and previous lookup class if present.- See Also:
MethodHandles.Lookup.PUBLIC, Constant Field Values
-
PRIVATE
public static final int PRIVATE
A single-bit mask representingprivateaccess, which may contribute to the result oflookupModes. The value,0x02, happens to be the same as the value of theprivatemodifier bit.- See Also:
MethodHandles.Lookup.PRIVATE, Constant Field Values
-
PROTECTED
public static final int PROTECTED
A single-bit mask representingprotectedaccess, which may contribute to the result oflookupModes. The value,0x04, happens to be the same as the value of theprotectedmodifier bit.- See Also:
MethodHandles.Lookup.PROTECTED, Constant Field Values
-
PACKAGE
public static final int PACKAGE
A single-bit mask representingpackageaccess (default access), which may contribute to the result oflookupModes. The value is0x08, which does not correspond meaningfully to any particular modifier bit.- See Also:
MethodHandles.Lookup.PACKAGE, Constant Field Values
-
MODULE
public static final int MODULE
A single-bit mask representingmoduleaccess, which may contribute to the result oflookupModes. The value is0x10, which does not correspond meaningfully to any particular modifier bit. In conjunction with thePUBLICmodifier bit, aLookupwith this lookup mode can access all public types in the module of the lookup class and public types in packages exported by other modules to the module of the lookup class.If this lookup mode is set, the previous lookup class is always
null.- Since:
- 9
- See Also:
MethodHandles.Lookup#MODULE, Constant Field Values
-
UNCONDITIONAL
public static final int UNCONDITIONAL
A single-bit mask representingunconditionalaccess which may contribute to the result oflookupModes. The value is0x20, which does not correspond meaningfully to any particular modifier bit. ALookupwith this lookup mode assumes readability. This lookup mode can access all public members of public types of all modules when the type is in a package that isexported unconditionally.If this lookup mode is set, the previous lookup class is always
null.- Since:
- 9
- See Also:
MethodHandles.publicLookup(),MethodHandles.Lookup#UNCONDITIONAL, Constant Field Values
-
ORIGINAL
public static final int ORIGINAL
A single-bit mask representingoriginalaccess which may contribute to the result oflookupModes. The value is0x40, which does not correspond meaningfully to any particular modifier bit.If this lookup mode is set, the
Lookupobject must be created by the original lookup class by callingMethodHandles.lookup()method or by a bootstrap method invoked by the VM. TheLookupobject with this lookup mode has full privilege access.- Since:
- 16
- See Also:
MethodHandles.Lookup#ORIGINAL, Constant Field Values
-
ALL_MODES
public static final int ALL_MODES
A single-bit mask representing all accesses (public, private, protected and package) The value, 0x0f, happens to be the same as the value of the modifier bit.- See Also:
- Constant Field Values
-
NOT_FOUND_METHOD_HANDLE
public static final java.lang.invoke.MethodHandle NOT_FOUND_METHOD_HANDLE
MethodHandlefor Not-Found
-
-
Method Detail
-
lookup
public static java.lang.invoke.MethodHandles.Lookup lookup(java.lang.Class<?> lookupClass)
Create an instance ofMethodHandles.Lookupby the specified lookup class withall accesses (public, private, protected and package)- Parameters:
lookupClass- the lookup class- Returns:
- non-null
-
lookup
public static java.lang.invoke.MethodHandles.Lookup lookup(java.lang.Class<?> lookupClass, MethodHandleUtils.LookupMode... lookupModes)Create an instance ofMethodHandles.Lookupby the specified lookup class withall access (public, private, protected and package)- Parameters:
lookupClass- the lookup class- Returns:
- non-null
-
findVirtual
public static java.lang.invoke.MethodHandle findVirtual(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)The convenient method to findMethodHandles.Lookup.findVirtual(Class, String, MethodType)- Parameters:
lookupClass- the class to be looked upmethodName- the target method nameparameterTypes- the types of target method parameters- Returns:
MethodHandle
-
findStatic
public static java.lang.invoke.MethodHandle findStatic(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)The convenient method to findMethodHandles.Lookup.findStatic(Class, String, MethodType)- Parameters:
lookupClass- the class to be looked upmethodName- the target method nameparameterTypes- the types of target method parameters- Returns:
MethodHandle
-
find
protected static java.lang.invoke.MethodHandle find(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
-
-