Package net.bytebuddy.utility
Class JavaModule
- java.lang.Object
-
- net.bytebuddy.utility.JavaModule
-
- All Implemented Interfaces:
AnnotationSource
,NamedElement
,NamedElement.WithOptionalName
public class JavaModule extends java.lang.Object implements NamedElement.WithOptionalName, AnnotationSource
Type-safe representation of ajava.lang.Module
. On platforms that do not support the module API, modules are represented bynull
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
JavaModule.Dispatcher
A dispatcher for accessing thejava.lang.Module
API if it is available on the current VM.-
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
Fields Modifier and Type Field Description private static JavaModule.Dispatcher
DISPATCHER
The dispatcher to use for accessing Java modules, if available.private java.lang.reflect.AnnotatedElement
module
Thejava.lang.Module
instance this wrapper represents.static JavaModule
UNSUPPORTED
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
Constructors Modifier Constructor Description protected
JavaModule(java.lang.reflect.AnnotatedElement module)
Creates a new Java module representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRead(JavaModule module)
Checks if this module can read the exported packages of the supplied module.boolean
equals(java.lang.Object other)
java.lang.String
getActualName()
Returns the name of this element as it is found in the source code.java.lang.ClassLoader
getClassLoader()
Returns the class loader of this module.AnnotationList
getDeclaredAnnotations()
Returns a list of annotations that are declared by this instance.java.io.InputStream
getResourceAsStream(java.lang.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
isSupported()
Checks if the current VM supports thejava.lang.Module
API.void
modify(java.lang.instrument.Instrumentation instrumentation, java.util.Set<JavaModule> reads, java.util.Map<java.lang.String,java.util.Set<JavaModule>> exports, java.util.Map<java.lang.String,java.util.Set<JavaModule>> opens, java.util.Set<java.lang.Class<?>> uses, java.util.Map<java.lang.Class<?>,java.util.List<java.lang.Class<?>>> provides)
Modifies this module's properties.static JavaModule
of(java.lang.Object module)
Represents the suppliedjava.lang.Module
as an instance of this class and validates that the supplied instance really represents a JavaModule
.static JavaModule
ofType(java.lang.Class<?> type)
Returns a representation of the supplied type'sjava.lang.Module
ornull
if the current VM does not support modules.java.lang.String
toString()
java.lang.Object
unwrap()
Unwraps this instance to ajava.lang.Module
.
-
-
-
Field Detail
-
UNSUPPORTED
public static final JavaModule UNSUPPORTED
Canonical representation of a Java module on a JVM that does not support the module API.
-
DISPATCHER
private static final JavaModule.Dispatcher DISPATCHER
The dispatcher to use for accessing Java modules, if available.
-
module
private final java.lang.reflect.AnnotatedElement module
Thejava.lang.Module
instance this wrapper represents.
-
-
Method Detail
-
ofType
public static JavaModule ofType(java.lang.Class<?> type)
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
public static JavaModule of(java.lang.Object module)
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
public java.lang.String getActualName()
Returns the 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.
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
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.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns the class loader of this module.- Returns:
- The class loader of the represented module.
-
unwrap
public java.lang.Object unwrap()
Unwraps this instance to ajava.lang.Module
.- Returns:
- The represented
java.lang.Module
.
-
canRead
public boolean canRead(JavaModule module)
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
public boolean isExported(PackageDescription packageDescription, JavaModule module)
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
public boolean isOpened(PackageDescription packageDescription, JavaModule module)
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
public AnnotationList getDeclaredAnnotations()
Returns a list of annotations that are declared by this instance.- Specified by:
getDeclaredAnnotations
in interfaceAnnotationSource
- Returns:
- A list of declared annotations.
-
modify
public void modify(java.lang.instrument.Instrumentation instrumentation, java.util.Set<JavaModule> reads, java.util.Map<java.lang.String,java.util.Set<JavaModule>> exports, java.util.Map<java.lang.String,java.util.Set<JavaModule>> opens, java.util.Set<java.lang.Class<?>> uses, java.util.Map<java.lang.Class<?>,java.util.List<java.lang.Class<?>>> provides)
Modifies this module's properties.- Parameters:
instrumentation
- The instrumentation instace to use for applying the modification.reads
- A set of additional modules this module should read.exports
- A map of packages to export to a set of modules.opens
- A map of packages to open to a set of modules.uses
- A set of provider interfaces to use by this module.provides
- A map of provider interfaces to provide by this module mapped to the provider implementations.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-