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 interfaceJavaModule.ModuleA proxy for interacting withjava.lang.Module.protected static interfaceJavaModule.ResolverA 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
Fields Modifier and Type Field Description private java.lang.reflect.AnnotatedElementmoduleThejava.lang.Moduleinstance this wrapper represents.protected static JavaModule.ModuleMODULEA dispatcher to interact withjava.lang.Module.protected static JavaModule.ResolverRESOLVERA dispatcher to resolve aClass'sjava.lang.Module.static JavaModuleUNSUPPORTEDCanonical 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 protectedJavaModule(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 booleancanRead(JavaModule module)Checks if this module can read the exported packages of the supplied module.private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.booleanequals(java.lang.Object other)java.lang.StringgetActualName()Returns the display name of this element as it is found in the source code.java.lang.ClassLoadergetClassLoader()Returns the class loader of this module.AnnotationListgetDeclaredAnnotations()Returns a list of annotations that are declared by this instance.java.util.Set<java.lang.String>getPackages()Returns the packages of this module.java.io.InputStreamgetResourceAsStream(java.lang.String name)Returns a resource stream for this module for a resource of the given name ornullif such a resource does not exist.inthashCode()booleanisExported(PackageDescription packageDescription, JavaModule module)Returnstrueif this module exports the supplied package to this module.booleanisNamed()Returnstrueif this element has an explicit name.booleanisOpened(PackageDescription packageDescription, JavaModule module)Returnstrueif this module opens the supplied package to this module.static booleanisSupported()Checks if the current VM supports thejava.lang.ModuleAPI.static JavaModuleof(java.lang.Object module)Represents the suppliedjava.lang.Moduleas an instance of this class and validates that the supplied instance really represents a JavaModule.static JavaModuleofType(java.lang.Class<?> type)Returns a representation of the supplied type'sjava.lang.Moduleornullif the current VM does not support modules.ModuleDescriptiontoDescription()Returns a description of the module if the current module is a named module.java.lang.StringtoString()java.lang.Objectunwrap()Unwraps this instance to ajava.lang.Module.
-
-
-
Field Detail
-
UNSUPPORTED
@AlwaysNull public static final JavaModule UNSUPPORTED
Canonical representation of a Java module on a JVM that does not support the module API.
-
RESOLVER
protected static final JavaModule.Resolver RESOLVER
A dispatcher to resolve aClass'sjava.lang.Module.
-
MODULE
protected static final JavaModule.Module MODULE
A dispatcher to interact withjava.lang.Module.
-
module
private final java.lang.reflect.AnnotatedElement module
Thejava.lang.Moduleinstance this wrapper represents.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat 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
@MaybeNull public static JavaModule ofType(java.lang.Class<?> type)
Returns a representation of the supplied type'sjava.lang.Moduleornullif 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
nullif the current VM does not support modules.
-
of
public static JavaModule of(java.lang.Object module)
Represents the suppliedjava.lang.Moduleas 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.ModuleAPI.- Returns:
trueif the current VM supports modules.
-
isNamed
public boolean isNamed()
Returnstrueif this element has an explicit name.- Specified by:
isNamedin interfaceNamedElement.WithOptionalName- Returns:
trueif this element has an explicit name.
-
getActualName
public java.lang.String 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:
getActualNamein interfaceNamedElement- Returns:
- The name of this element as given in a Java program's source code.
-
getPackages
public java.util.Set<java.lang.String> getPackages()
Returns the packages of this module.- Returns:
- A set of the names of the packages that are defined by this module.
-
getResourceAsStream
@MaybeNull public java.io.InputStream getResourceAsStream(java.lang.String name) throws java.io.IOException
Returns a resource stream for this module for a resource of the given name ornullif such a resource does not exist.- Parameters:
name- The name of the resource.- Returns:
- An input stream for the resource or
nullif it does not exist. - Throws:
java.io.IOException- If an I/O exception occurs.
-
getClassLoader
@MaybeNull 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:
trueif this module can read the supplied module.
-
isExported
public boolean isExported(@MaybeNull PackageDescription packageDescription, JavaModule module)
Returnstrueif this module exports the supplied package to this module.- Parameters:
packageDescription- The package to check formodule- The target module.- Returns:
trueif this module exports the supplied package to this module.
-
isOpened
public boolean isOpened(@MaybeNull PackageDescription packageDescription, JavaModule module)
Returnstrueif this module opens the supplied package to this module.- Parameters:
packageDescription- The package to check for.module- The target module.- Returns:
trueif 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:
getDeclaredAnnotationsin interfaceAnnotationSource- Returns:
- A list of declared annotations.
-
toDescription
public ModuleDescription toDescription()
Returns a description of the module if the current module is a named module. Otherwise, an exception is thrown.- Returns:
- A description of the current module.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@MaybeNull java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-