Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingLookup
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingLookup
-
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
- ClassInjector
@Enhance public static class ClassInjector.UsingLookup extends ClassInjector.AbstractBase
A class injector that uses a
java.lang.invoke.MethodHandles$Lookup
object for defining a class.Important: This functionality is only available starting from Java 9.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
ClassInjector.UsingLookup.MethodHandles
A dispatcher forjava.lang.invoke.MethodHandles
.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, ClassInjector.UsingJna, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.reflect.Method
DEFINE_CLASS
A reference tojava.lang.invoke.MethodHandles$Lookup#defineClass
ornull
if the method is not available.private java.lang.Object
lookup
Thejava.lang.invoke.MethodHandles$Lookup
to use.private static ClassInjector.UsingLookup.MethodHandles
METHOD_HANDLES
The dispatcher to interacting with instances ofjava.lang.invoke.MethodHandles
.private static ClassInjector.UsingLookup.MethodHandles.Lookup
METHOD_HANDLES_LOOKUP
The dispatcher to interacting withjava.lang.invoke.MethodHandles$Lookup
.private static int
PACKAGE_LOOKUP
Indicates a lookup instance's package lookup mode.-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES, SUPPRESS_ACCESS_CHECKS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
UsingLookup(java.lang.Object lookup)
Creates a new class injector using a lookup instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> T
doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.ClassInjector.UsingLookup
in(java.lang.Class<?> type)
Resolves this injector to use the supplied type's scope.java.util.Map<java.lang.String,java.lang.Class<?>>
injectRaw(java.util.Map<? extends java.lang.String,byte[]> types)
Injects the given types into the represented class loader using a mapping from name to binary representation.boolean
isAlive()
Indicates if this class injector is available on the current VM.static boolean
isAvailable()
Checks if the current VM is capable of defining classes using a method handle lookup.java.lang.Class<?>
lookupType()
Returns the lookup type this injector is based upon.static ClassInjector.UsingLookup
of(java.lang.Object lookup)
Creates class injector that defines a class using a method handle lookup.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject
-
-
-
-
Field Detail
-
METHOD_HANDLES
private static final ClassInjector.UsingLookup.MethodHandles METHOD_HANDLES
The dispatcher to interacting with instances ofjava.lang.invoke.MethodHandles
.
-
METHOD_HANDLES_LOOKUP
private static final ClassInjector.UsingLookup.MethodHandles.Lookup METHOD_HANDLES_LOOKUP
The dispatcher to interacting withjava.lang.invoke.MethodHandles$Lookup
.
-
DEFINE_CLASS
private static final java.lang.reflect.Method DEFINE_CLASS
A reference tojava.lang.invoke.MethodHandles$Lookup#defineClass
ornull
if the method is not available.
-
PACKAGE_LOOKUP
private static final int PACKAGE_LOOKUP
Indicates a lookup instance's package lookup mode.- See Also:
- Constant Field Values
-
lookup
private final java.lang.Object lookup
Thejava.lang.invoke.MethodHandles$Lookup
to use.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
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.
-
of
public static ClassInjector.UsingLookup of(java.lang.Object lookup)
Creates class injector that defines a class using a method handle lookup.- Parameters:
lookup
- Thejava.lang.invoke.MethodHandles$Lookup
instance to use.- Returns:
- An appropriate class injector.
-
lookupType
public java.lang.Class<?> lookupType()
Returns the lookup type this injector is based upon.- Returns:
- The lookup type.
-
in
public ClassInjector.UsingLookup in(java.lang.Class<?> type)
Resolves this injector to use the supplied type's scope.- Parameters:
type
- The type to resolve the access scope for.- Returns:
- An new injector with the specified scope.
-
isAlive
public boolean isAlive()
Indicates if this class injector is available on the current VM.- Returns:
true
if this injector is available on the current VM.
-
injectRaw
public java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Map<? extends java.lang.String,byte[]> types)
Injects the given types into the represented class loader using a mapping from name to binary representation.- Parameters:
types
- The types to load via injection.- Returns:
- The loaded types that were passed as arguments.
-
isAvailable
public static boolean isAvailable()
Checks if the current VM is capable of defining classes using a method handle lookup.- Returns:
true
if the current VM is capable of defining classes using a lookup.
-
-