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.Module
A proxy for interacting with
java.lang.Module . |
protected static interface |
JavaModule.Resolver
A proxy for resolving a
Class 's java.lang.Module . |
NamedElement.WithDescriptor, NamedElement.WithGenericName, NamedElement.WithOptionalName, NamedElement.WithRuntimeName
AnnotationSource.Empty, AnnotationSource.Explicit
Modifier and Type | Field and Description |
---|---|
protected static JavaModule.Module |
MODULE
A dispatcher to interact with
java.lang.Module . |
protected static JavaModule.Resolver |
RESOLVER
A dispatcher to resolve a
Class 's java.lang.Module . |
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 display 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.
|
Set<String> |
getPackages()
Returns the packages of this module.
|
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. |
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 . |
@AlwaysNull public static final JavaModule UNSUPPORTED
protected static final JavaModule.Resolver RESOLVER
Class
's java.lang.Module
.protected static final JavaModule.Module MODULE
java.lang.Module
.protected JavaModule(AnnotatedElement module)
module
- The java.lang.Module
instance this wrapper represents.@MaybeNull 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 Set<String> getPackages()
@MaybeNull public InputStream getResourceAsStream(String name) throws IOException
null
if such a resource does not exist.name
- The name of the resource.null
if it does not exist.IOException
- If an I/O exception occurs.@MaybeNull 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(@MaybeNull 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(@MaybeNull 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 boolean equals(@MaybeNull Object other)
Copyright © 2014–2025. All rights reserved.