Class JavaModule

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.reflect.AnnotatedElement module
      The java.lang.Module instance this wrapper represents.
      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.
    • 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.
      private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that is activated if available.
      boolean equals​(java.lang.Object other)  
      java.lang.String getActualName()
      Returns the display 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.util.Set<java.lang.String> getPackages()
      Returns the packages of this module.
      java.io.InputStream getResourceAsStream​(java.lang.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​(java.lang.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​(java.lang.Class<?> type)
      Returns a representation of the supplied type's java.lang.Module or null if the current VM does not support modules.
      java.lang.String toString()  
      java.lang.Object unwrap()
      Unwraps this instance to a java.lang.Module.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 a Class's java.lang.Module.
      • MODULE

        protected static final JavaModule.Module MODULE
        A dispatcher to interact with java.lang.Module.
      • module

        private final java.lang.reflect.AnnotatedElement module
        The java.lang.Module instance this wrapper represents.
    • Constructor Detail

      • JavaModule

        protected JavaModule​(java.lang.reflect.AnnotatedElement module)
        Creates a new Java module representation.
        Parameters:
        module - The java.lang.Module instance this wrapper represents.
    • Method Detail

      • doPrivileged

        @Enhance
        private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
        A proxy for java.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

        @MaybeNull
        public static JavaModule ofType​(java.lang.Class<?> type)
        Returns a representation of the supplied type's java.lang.Module or null 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 supplied java.lang.Module as an instance of this class and validates that the supplied instance really represents a Java Module.
        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 the java.lang.Module API.
        Returns:
        true if the current VM supports modules.
      • isNamed

        public boolean isNamed()
        Returns true if this element has an explicit name.
        Specified by:
        isNamed in interface NamedElement.WithOptionalName
        Returns:
        true if 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:
        getActualName in interface NamedElement
        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 or null 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:
        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 a java.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​(@MaybeNull
                                  PackageDescription packageDescription,
                                  JavaModule module)
        Returns true if this module exports the supplied package to this module.
        Parameters:
        packageDescription - The package to check for
        module - The target module.
        Returns:
        true if this module exports the supplied package to this module.
      • isOpened

        public boolean isOpened​(@MaybeNull
                                PackageDescription packageDescription,
                                JavaModule module)
        Returns true 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(@MaybeNull
                              java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object