public class JavaModule extends Object implements NamedElement.WithOptionalName, AnnotationSource
java.lang.Module
. On platforms that do not support the module API, modules are represented by null
.Modifier and Type | Class and Description |
---|---|
protected static interface |
JavaModule.Dispatcher
A dispatcher for accessing the
java.lang.Module API if it is available on the current VM. |
NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeName
AnnotationSource.Empty, AnnotationSource.Explicit
Modifier and Type | Field and Description |
---|---|
static JavaModule |
UNSUPPORTED
Canonical representation of a Java module on a JVM that does not support the module API.
|
EMPTY_NAME, NO_NAME
Modifier | Constructor and Description |
---|---|
protected |
JavaModule(AnnotatedElement module)
Creates a new Java module representation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(JavaModule module)
Checks if this module can read the exported packages of the supplied module.
|
boolean |
equals(Object other) |
String |
getActualName()
Returns the name of this element as it is found in the source code.
|
ClassLoader |
getClassLoader()
Returns the class loader of this module.
|
AnnotationList |
getDeclaredAnnotations()
Returns a list of annotations that are declared by this instance.
|
InputStream |
getResourceAsStream(String name)
Returns a resource stream for this module for a resource of the given name or
null if such a resource does not exist. |
int |
hashCode() |
boolean |
isExported(PackageDescription packageDescription,
JavaModule module)
Returns
true if this module exports the supplied package to this module. |
boolean |
isNamed()
Returns
true if this element has an explicit name. |
boolean |
isOpened(PackageDescription packageDescription,
JavaModule module)
Returns
true if this module opens the supplied package to this module. |
static boolean |
isSupported()
Checks if the current VM supports the
java.lang.Module API. |
void |
modify(Instrumentation instrumentation,
Set<JavaModule> reads,
Map<String,Set<JavaModule>> exports,
Map<String,Set<JavaModule>> opens,
Set<Class<?>> uses,
Map<Class<?>,List<Class<?>>> provides)
Modifies this module's properties.
|
static JavaModule |
of(Object module)
Represents the supplied
java.lang.Module as an instance of this class and validates that the
supplied instance really represents a Java Module . |
static JavaModule |
ofType(Class<?> type)
Returns a representation of the supplied type's
java.lang.Module or null if the current VM does not support modules. |
String |
toString() |
Object |
unwrap()
Unwraps this instance to a
java.lang.Module . |
public static final JavaModule UNSUPPORTED
protected JavaModule(AnnotatedElement module)
module
- The java.lang.Module
instance this wrapper represents.public static JavaModule ofType(Class<?> type)
java.lang.Module
or null
if the current VM does not support modules.type
- The type for which to describe the module.null
if the current VM does not support modules.public static JavaModule of(Object module)
java.lang.Module
as an instance of this class and validates that the
supplied instance really represents a Java Module
.module
- The module to represent.public static boolean isSupported()
java.lang.Module
API.true
if the current VM supports modules.public boolean isNamed()
true
if this element has an explicit name.isNamed
in interface NamedElement.WithOptionalName
true
if this element has an explicit name.public String getActualName()
getActualName
in interface NamedElement
public InputStream getResourceAsStream(String name)
null
if such a resource does not exist.name
- The name of the resource.null
if it does not exist.public ClassLoader getClassLoader()
public Object unwrap()
java.lang.Module
.java.lang.Module
.public boolean canRead(JavaModule module)
module
- The module to check for its readability by this module.true
if this module can read the supplied module.public boolean isExported(PackageDescription packageDescription, JavaModule module)
true
if this module exports the supplied package to this module.packageDescription
- The package to check formodule
- The target module.true
if this module exports the supplied package to this module.public boolean isOpened(PackageDescription packageDescription, JavaModule module)
true
if this module opens the supplied package to this module.packageDescription
- The package to check for.module
- The target module.true
if this module opens the supplied package to this module.public AnnotationList getDeclaredAnnotations()
getDeclaredAnnotations
in interface AnnotationSource
public void modify(Instrumentation instrumentation, Set<JavaModule> reads, Map<String,Set<JavaModule>> exports, Map<String,Set<JavaModule>> opens, Set<Class<?>> uses, Map<Class<?>,List<Class<?>>> provides)
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.Copyright © 2014–2020. All rights reserved.