Package net.bytebuddy.utility
Class JavaModule
java.lang.Object
net.bytebuddy.utility.JavaModule
- All Implemented Interfaces:
AnnotationSource
,NamedElement
,NamedElement.WithOptionalName
Type-safe representation of a
java.lang.Module
. On platforms that do not support the module API, modules are represented by null
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface
A proxy for interacting withjava.lang.Module
.protected static interface
A proxy for resolving aClass
'sjava.lang.Module
.Nested classes/interfaces inherited from interface net.bytebuddy.description.annotation.AnnotationSource
AnnotationSource.Empty, AnnotationSource.Explicit
Nested classes/interfaces inherited from interface net.bytebuddy.description.NamedElement
NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeName
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AnnotatedElement
Thejava.lang.Module
instance this wrapper represents.protected static final JavaModule.Module
A dispatcher to interact withjava.lang.Module
.protected static final JavaModule.Resolver
A dispatcher to resolve aClass
'sjava.lang.Module
.static final JavaModule
Canonical representation of a Java module on a JVM that does not support the module API.Fields inherited from interface net.bytebuddy.description.NamedElement
EMPTY_NAME, NO_NAME
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JavaModule
(AnnotatedElement module) Creates a new Java module representation. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRead
(JavaModule module) Checks if this module can read the exported packages of the supplied module.private static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.boolean
Returns the display name of this element as it is found in the source code.Returns the class loader of this module.Returns a list of annotations that are declared by this instance.Returns the packages of this module.getResourceAsStream
(String name) Returns a resource stream for this module for a resource of the given name ornull
if such a resource does not exist.int
hashCode()
boolean
isExported
(PackageDescription packageDescription, JavaModule module) Returnstrue
if this module exports the supplied package to this module.boolean
isNamed()
Returnstrue
if this element has an explicit name.boolean
isOpened
(PackageDescription packageDescription, JavaModule module) Returnstrue
if this module opens the supplied package to this module.static boolean
Checks if the current VM supports thejava.lang.Module
API.static JavaModule
Represents the suppliedjava.lang.Module
as an instance of this class and validates that the supplied instance really represents a JavaModule
.static JavaModule
Returns a representation of the supplied type'sjava.lang.Module
ornull
if the current VM does not support modules.toString()
unwrap()
Unwraps this instance to ajava.lang.Module
.
-
Field Details
-
UNSUPPORTED
Canonical representation of a Java module on a JVM that does not support the module API. -
RESOLVER
A dispatcher to resolve aClass
'sjava.lang.Module
. -
MODULE
A dispatcher to interact withjava.lang.Module
. -
module
Thejava.lang.Module
instance this wrapper represents.
-
-
Constructor Details
-
JavaModule
Creates a new Java module representation.- Parameters:
module
- Thejava.lang.Module
instance this wrapper represents.
-
-
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.
-
ofType
Returns a representation of the supplied type'sjava.lang.Module
ornull
if the current VM does not support modules.- Parameters:
type
- The type for which to describe the module.- Returns:
- A representation of the type's module or
null
if the current VM does not support modules.
-
of
Represents the suppliedjava.lang.Module
as an instance of this class and validates that the supplied instance really represents a JavaModule
.- Parameters:
module
- The module to represent.- Returns:
- A representation of the supplied Java module.
-
isSupported
public static boolean isSupported()Checks if the current VM supports thejava.lang.Module
API.- Returns:
true
if the current VM supports modules.
-
isNamed
public boolean isNamed()Returnstrue
if this element has an explicit name.- Specified by:
isNamed
in interfaceNamedElement.WithOptionalName
- Returns:
true
if this element has an explicit name.
-
getActualName
Returns the display name of this element as it is found in the source code. If no such name exists, an empty string is returned.- Specified by:
getActualName
in interfaceNamedElement
- Returns:
- The name of this element as given in a Java program's source code.
-
getPackages
Returns the packages of this module.- Returns:
- A set of the names of the packages that are defined by this module.
-
getResourceAsStream
Returns a resource stream for this module for a resource of the given name ornull
if such a resource does not exist.- Parameters:
name
- The name of the resource.- Returns:
- An input stream for the resource or
null
if it does not exist. - Throws:
IOException
- If an I/O exception occurs.
-
getClassLoader
Returns the class loader of this module.- Returns:
- The class loader of the represented module.
-
unwrap
Unwraps this instance to ajava.lang.Module
.- Returns:
- The represented
java.lang.Module
.
-
canRead
Checks if this module can read the exported packages of the supplied module.- Parameters:
module
- The module to check for its readability by this module.- Returns:
true
if this module can read the supplied module.
-
isExported
Returnstrue
if this module exports the supplied package to this module.- Parameters:
packageDescription
- The package to check formodule
- The target module.- Returns:
true
if this module exports the supplied package to this module.
-
isOpened
Returnstrue
if this module opens the supplied package to this module.- Parameters:
packageDescription
- The package to check for.module
- The target module.- Returns:
true
if this module opens the supplied package to this module.
-
getDeclaredAnnotations
Returns a list of annotations that are declared by this instance.- Specified by:
getDeclaredAnnotations
in interfaceAnnotationSource
- Returns:
- A list of declared annotations.
-
hashCode
public int hashCode() -
equals
-
toString
-