APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.lang.module

public final Class ModuleDescriptor

extends Object
implements Comparable<ModuleDescriptor>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Annotations
@AOTSafeClassInitializer
Imports
java.io.InputStream, .IOException, .PrintStream, .UncheckedIOException, java.lang.reflect.AccessFlag, java.nio.ByteBuffer, java.nio.file.Path, java.util.ArrayList, .Arrays, .Collection, .Collections, .EnumSet, .HashMap, .HashSet, .List, .Locale, .Map, .Objects, .Optional, .Set, java.util.function.Supplier, java.util.stream.Collectors, .Stream, jdk.internal.module.Checks, .ModuleInfo, jdk.internal.vm.annotation.AOTSafeClassInitializer

A module descriptor.

A module descriptor describes a named module and defines methods to obtain each of its components. The module descriptor for a named module in the Java virtual machine is obtained by invoking the Module's getDescriptor method. Module descriptors can also be created using the ModuleDescriptor.Builder class or by reading the binary form of a module declaration (module-info.class) using the read methods defined here.

A module descriptor describes a normal, open, or automatic module. Normal modules and open modules describe their dependences, exported-packages, the services that they use or provide, and other components. Normal modules may open specific packages. The module descriptor for an open module does not declare any open packages (its opens method returns an empty set) but when instantiated in the Java virtual machine then it is treated as if all packages are open. The module descriptor for an automatic module does not declare any dependences (except for the mandatory dependency on java.base), and does not declare any exported or open packages. Automatic modules receive special treatment during resolution so that they read all other modules in the configuration. When an automatic module is instantiated in the Java virtual machine then it reads every unnamed module and is treated as if all packages are exported and open.

ModuleDescriptor objects are immutable and safe for use by multiple concurrent threads.

Since
9
See Also
java.lang.Module

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ModuleDescriptor.Builder

A builder for building ModuleDescriptor objects.

public static class
ModuleDescriptor.Exports

A package exported by a module, may be qualified or unqualified.

public static enum
ModuleDescriptor.Modifier

A modifier on a module.

public static class
ModuleDescriptor.Opens

A package opened by a module, may be qualified or unqualified.

public static class
ModuleDescriptor.Provides

A service that a module provides one or more implementations of.

public static class
ModuleDescriptor.Requires

A dependence upon a module.

public static class
ModuleDescriptor.Version

A module's version string.

Field Summary

Modifier and TypeField and Description
private final boolean
private final Set<ModuleDescriptor.Exports>
private transient int
private final String
private final Set<ModuleDescriptor.Modifier>
private final String
private final boolean
private final Set<ModuleDescriptor.Opens>
private final Set<String>
private final Set<ModuleDescriptor.Provides>
private final String
private final Set<ModuleDescriptor.Requires>
private final Set<String>
private final ModuleDescriptor.Version

Constructor Summary

AccessConstructor and Description
private
ModuleDescriptor(String name, ModuleDescriptor.Version version, String rawVersionString, Set<ModuleDescriptor.Modifier> modifiers, Set<ModuleDescriptor.Requires> requires, Set<ModuleDescriptor.Exports> exports, Set<ModuleDescriptor.Opens> opens, Set<String> uses, Set<ModuleDescriptor.Provides> provides, Set<String> packages, String mainClass)

private
ModuleDescriptor(String name, ModuleDescriptor.Version version, Set<ModuleDescriptor.Modifier> modifiers, Set<ModuleDescriptor.Requires> requires, Set<ModuleDescriptor.Exports> exports, Set<ModuleDescriptor.Opens> opens, Set<String> uses, Set<ModuleDescriptor.Provides> provides, Set<String> packages, String mainClass, int hashCode, boolean unused)

Creates a module descriptor from its components.

Method Summary

Modifier and TypeMethod and Description
public Set<AccessFlag>

Returns:

A possibly-empty unmodifiable set of module flags
accessFlags
()

Returns the set of the module flags.

private static <T extends Comparable<? super T>> int
compare(T obj1, T obj2)

private static <T extends Comparable<? super T>> int
compare(Set<T> s1, Set<T> s2)

Compares two sets of Comparable objects.

public int

Returns:

A negative integer, zero, or a positive integer if this module descriptor is less than, equal to, or greater than the given module descriptor
compareTo
(ModuleDescriptor
The module descriptor to compare
that
)

Implements java.lang.Comparable.compareTo.

Compares this module descriptor to another.

public boolean

Returns:

true if, and only if, the given object is a module descriptor that is equal to this module descriptor
equals
(Object
the object to which this object is to be compared
ob
)

Overrides java.lang.Object.equals.

Tests this module descriptor for equality with the given object.

public Set<ModuleDescriptor.Exports>

Returns:

A possibly-empty unmodifiable set of exported packages
exports
()

Returns the set of Exports objects representing the exported packages.

public int

Returns:

The hash-code value for this module descriptor
hashCode
()

Overrides java.lang.Object.hashCode.

Computes a hash code for this module descriptor.

public boolean

Returns:

true if this is an automatic module
isAutomatic
()

Returns true if this is an automatic module.

public boolean

Returns:

true if this is an open module
isOpen
()

Returns true if this is an open module.

public Optional<String>

Returns:

The binary name of the module's main class
mainClass
()

Returns the module main class.

public Set<ModuleDescriptor.Modifier>

Returns:

A possibly-empty unmodifiable set of modifiers
modifiers
()

Returns the set of module modifiers.

private static int
modsHashCode(Iterable<? extends Enum<?>> enums)

Generates and returns a hashcode for the enum instances.

private static <E extends Enum<E>> long
modsValue(Set<E> set)

public String

Returns:

The module name
name
()

Returns the module name.

public static ModuleDescriptor.Builder

Returns:

A new builder that builds an automatic module
newAutomaticModule
(String
The module name
name
)

Instantiates a builder to build a module descriptor for an automatic module.

public static ModuleDescriptor.Builder

Returns:

A new builder
newModule
(String
The module name
name
,
Set<ModuleDescriptor.Modifier>
The set of module modifiers
ms
)

Instantiates a builder to build a module descriptor.

public static ModuleDescriptor.Builder

Returns:

A new builder
newModule
(String
The module name
name
)

Instantiates a builder to build a module descriptor for a normal module.

public static ModuleDescriptor.Builder

Returns:

A new builder that builds an open module
newOpenModule
(String
The module name
name
)

Instantiates a builder to build a module descriptor for an open module.

public Set<ModuleDescriptor.Opens>

Returns:

A possibly-empty unmodifiable set of open packages
opens
()

Returns the set of Opens objects representing the open packages.

private static String
public Set<String>

Returns:

A possibly-empty unmodifiable set of the packages in the module
packages
()

Returns the set of all packages in the module.

public Set<ModuleDescriptor.Provides>

Returns:

The possibly-empty unmodifiable set of the services that this module provides
provides
()

Returns the set of Provides objects representing the services that the module provides.

public Optional<String>

Returns:

The string containing the version of the module or an empty Optional if the module does not have a version
rawVersion
()

Returns the string with the possibly-unparseable version of the module.

public static ModuleDescriptor

Returns:

The module descriptor
read
(InputStream
The input stream
in
,
Supplier<Set<String>>
A supplier that can produce the set of packages
packageFinder
)

Reads the binary form of a module declaration from an input stream as a module descriptor.

public static ModuleDescriptor

Returns:

The module descriptor
read
(InputStream
The input stream
in
)

Reads the binary form of a module declaration from an input stream as a module descriptor.

public static ModuleDescriptor

Returns:

The module descriptor
read
(ByteBuffer
The byte buffer
bb
,
Supplier<Set<String>>
A supplier that can produce the set of packages
packageFinder
)

Reads the binary form of a module declaration from a byte buffer as a module descriptor.

public static ModuleDescriptor

Returns:

The module descriptor
read
(ByteBuffer
The byte buffer
bb
)

Reads the binary form of a module declaration from a byte buffer as a module descriptor.

public Set<ModuleDescriptor.Requires>

Returns:

A possibly-empty unmodifiable set of Requires objects
requires
()

Returns the set of Requires objects representing the module dependences.

public String

Returns:

A string containing the module name and, if present, its version
toNameAndVersion
()

Returns a string containing the module name and, if present, its version.

public String

Returns:

A string describing the module
toString
()

Overrides java.lang.Object.toString.

Returns a string describing the module.

private static <M> String
toString(Set<M> mods, String what)

Returns a string containing the given set of modifiers and label.

public Set<String>

Returns:

A possibly-empty unmodifiable set of the binary names of the service types used
uses
()

Returns the set of service dependences.

public Optional<ModuleDescriptor.Version>

Returns:

This module's version, or an empty Optional if the module does not have a version or the version is unparseable
version
()

Returns the module version.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait