- java.lang.Object
- 
- java.lang.module.ModuleDescriptor
 
- 
- All Implemented Interfaces:
- Comparable<ModuleDescriptor>
 
 public class ModuleDescriptor extends Object implements Comparable<ModuleDescriptor> 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'sgetDescriptormethod. Module descriptors can also be created using theModuleDescriptor.Builderclass or by reading the binary form of a module declaration (module-info.class) using thereadmethods 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 theyuseorprovide, and other components. Normal modules mayopenspecific packages. The module descriptor for an open modules does not declare any open packages (itsopensmethod 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 onjava.base), and does not declare any exported or open packages. Automatic module 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.ModuleDescriptorobjects are immutable and safe for use by multiple concurrent threads.- Since:
- 9
- See Also:
- Module
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classModuleDescriptor.BuilderA builder for buildingModuleDescriptorobjects.static classModuleDescriptor.ExportsA package exported by a module, may be qualified or unqualified.static classModuleDescriptor.ModifierA modifier on a module.static classModuleDescriptor.OpensA package opened by a module, may be qualified or unqualified.static classModuleDescriptor.ProvidesA service that a module provides one or more implementations of.static classModuleDescriptor.RequiresA dependence upon a modulestatic classModuleDescriptor.VersionA module's version string.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ModuleDescriptor that)Compares this module descriptor to another.booleanequals(Object ob)Tests this module descriptor for equality with the given object.Set<ModuleDescriptor.Exports>exports()Returns the set ofExportsobjects representing the exported packages.inthashCode()Computes a hash code for this module descriptor.booleanisAutomatic()Returnstrueif this is an automatic module.booleanisOpen()Returnstrueif this is an open module.Optional<String>mainClass()Returns the module main class.Set<ModuleDescriptor.Modifier>modifiers()Returns the set of module modifiers.Stringname()Returns the module name.static ModuleDescriptor.BuildernewAutomaticModule(String name)Instantiates a builder to build a module descriptor for an automatic module.static ModuleDescriptor.BuildernewModule(String name)Instantiates a builder to build a module descriptor for a normal module.static ModuleDescriptor.BuildernewModule(String name, Set<ModuleDescriptor.Modifier> ms)Instantiates a builder to build a module descriptor.static ModuleDescriptor.BuildernewOpenModule(String name)Instantiates a builder to build a module descriptor for an open module.Set<ModuleDescriptor.Opens>opens()Returns the set ofOpensobjects representing the open packages.Set<String>packages()Returns the set of packages in the module.Set<ModuleDescriptor.Provides>provides()Returns the set ofProvidesobjects representing the services that the module provides.Optional<String>rawVersion()Returns the string with the possibly-unparseable version of the modulestatic ModuleDescriptorread(InputStream in)Reads the binary form of a module declaration from an input stream as a module descriptor.static ModuleDescriptorread(InputStream in, Supplier<Set<String>> packageFinder)Reads the binary form of a module declaration from an input stream as a module descriptor.static ModuleDescriptorread(ByteBuffer bb)Reads the binary form of a module declaration from a byte buffer as a module descriptor.static ModuleDescriptorread(ByteBuffer bb, Supplier<Set<String>> packageFinder)Reads the binary form of a module declaration from a byte buffer as a module descriptor.Set<ModuleDescriptor.Requires>requires()Returns the set ofRequiresobjects representing the module dependences.StringtoNameAndVersion()Returns a string containing the module name and, if present, its version.StringtoString()Returns a string describing the module.Set<String>uses()Returns the set of service dependences.Optional<ModuleDescriptor.Version>version()Returns the module version.
 
- 
- 
- 
Method Detail- 
namepublic String name() Returns the module name. - Returns:
- The module name
 
 - 
modifierspublic Set<ModuleDescriptor.Modifier> modifiers() Returns the set of module modifiers. - Returns:
- A possibly-empty unmodifiable set of modifiers
 
 - 
isOpenpublic boolean isOpen() Returns trueif this is an open module.This method is equivalent to testing if the set of modifierscontains theOPENmodifier.- Returns:
- trueif this is an open module
 
 - 
isAutomaticpublic boolean isAutomatic() Returns trueif this is an automatic module.This method is equivalent to testing if the set of modifierscontains theAUTOMATICmodifier.- Returns:
- trueif this is an automatic module
 
 - 
requirespublic Set<ModuleDescriptor.Requires> requires() Returns the set of Requiresobjects representing the module dependences.The set includes a dependency on " java.base" when this module is not named "java.base". If this module is an automatic module then it does not have a dependency on any module other than "java.base".- Returns:
- A possibly-empty unmodifiable set of ModuleDescriptor.Requiresobjects
 
 - 
exportspublic Set<ModuleDescriptor.Exports> exports() Returns the set of Exportsobjects representing the exported packages.If this module is an automatic module then the set of exports is empty. - Returns:
- A possibly-empty unmodifiable set of exported packages
 
 - 
openspublic Set<ModuleDescriptor.Opens> opens() Returns the set of Opensobjects representing the open packages.If this module is an open module or an automatic module then the set of open packages is empty. - Returns:
- A possibly-empty unmodifiable set of open packages
 
 - 
usespublic Set<String> uses() Returns the set of service dependences. If this module is an automatic module then the set of service dependences is empty. - Returns:
- A possibly-empty unmodifiable set of the fully qualified class names of the service types used
 
 - 
providespublic Set<ModuleDescriptor.Provides> provides() Returns the set of Providesobjects representing the services that the module provides.- Returns:
- The possibly-empty unmodifiable set of the services that this module provides
 
 - 
versionpublic Optional<ModuleDescriptor.Version> version() Returns the module version. - Returns:
- This module's version, or an empty Optionalif the module does not have a version or the version is unparseable
 
 - 
rawVersionpublic Optional<String> rawVersion() Returns the string with the possibly-unparseable version of the module - Returns:
- The string containing the version of the module or an empty
         Optionalif the module does not have a version
- See Also:
- version()
 
 - 
toNameAndVersionpublic String toNameAndVersion() Returns a string containing the module name and, if present, its version. - Returns:
- A string containing the module name and, if present, its version
 
 - 
mainClasspublic Optional<String> mainClass() Returns the module main class. - Returns:
- The fully qualified class name of the module's main class
 
 - 
packagespublic Set<String> packages() Returns the set of packages in the module.The set of packages includes all exported and open packages, as well as the packages of any service providers, and the package for the main class. - Returns:
- A possibly-empty unmodifiable set of the packages in the module
 
 - 
compareTopublic int compareTo(ModuleDescriptor that) Compares this module descriptor to another.Two ModuleDescriptorobjects are compared by comparing their module names lexicographically. Where the module names are equal then the module versions are compared. When comparing the module versions then a module descriptor with a version is considered to succeed a module descriptor that does not have a version. If both versions are unparseable then the raw version strings are compared lexicographically. Where the module names are equal and the versions are equal (or not present in both), then the set of modifiers are compared. Sets of modifiers are compared by comparing a binary value computed for each set. If a modifier is present in the set then the bit at the position of its ordinal is1in the binary value, otherwise0. If the two set of modifiers are also equal then the other components of the module descriptors are compared in a manner that is consistent withequals.- Specified by:
- compareToin interface- Comparable<ModuleDescriptor>
- Parameters:
- that- The module descriptor to compare
- 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
 
 - 
equalspublic boolean equals(Object ob) Tests this module descriptor for equality with the given object.If the given object is not a ModuleDescriptorthen this method returnsfalse. Two module descriptors are equal if each of their corresponding components is equal.This method satisfies the general contract of the Object.equalsmethod.- Overrides:
- equalsin class- Object
- Parameters:
- ob- the object to which this object is to be compared
- Returns:
- trueif, and only if, the given object is a module descriptor that is equal to this module descriptor
- See Also:
- Object.hashCode(),- HashMap
 
 - 
hashCodepublic int hashCode() Computes a hash code for this module descriptor.The hash code is based upon the components of the module descriptor, and satisfies the general contract of the Object.hashCodemethod.- Overrides:
- hashCodein class- Object
- Returns:
- The hash-code value for this module descriptor
- See Also:
- Object.equals(java.lang.Object),- System.identityHashCode(java.lang.Object)
 
 - 
toStringpublic String toString() Returns a string describing the module. 
 - 
newModulepublic static ModuleDescriptor.Builder newModule(String name, Set<ModuleDescriptor.Modifier> ms) Instantiates a builder to build a module descriptor.- Parameters:
- name- The module name
- ms- The set of module modifiers
- Returns:
- A new builder
- Throws:
- IllegalArgumentException- If the module name is- nullor is not a legal module name, or the set of modifiers contains- AUTOMATICwith other modifiers
 
 - 
newModulepublic static ModuleDescriptor.Builder newModule(String name) Instantiates a builder to build a module descriptor for a normal module. This method is equivalent to invokingnewModulewith an empty set ofmodifiers.- Parameters:
- name- The module name
- Returns:
- A new builder
- Throws:
- IllegalArgumentException- If the module name is- nullor is not a legal module name
 
 - 
newOpenModulepublic static ModuleDescriptor.Builder newOpenModule(String name) Instantiates a builder to build a module descriptor for an open module. This method is equivalent to invokingnewModulewith theOPENmodifier.The builder for an open module cannot be used to declare any open packages. - Parameters:
- name- The module name
- Returns:
- A new builder that builds an open module
- Throws:
- IllegalArgumentException- If the module name is- nullor is not a legal module name
 
 - 
newAutomaticModulepublic static ModuleDescriptor.Builder newAutomaticModule(String name) Instantiates a builder to build a module descriptor for an automatic module. This method is equivalent to invokingnewModulewith theAUTOMATICmodifier.The builder for an automatic module cannot be used to declare module or service dependences. It also cannot be used to declare any exported or open packages. - Parameters:
- name- The module name
- Returns:
- A new builder that builds an automatic module
- Throws:
- IllegalArgumentException- If the module name is- nullor is not a legal module name
- See Also:
- ModuleFinder.of(Path[])
 
 - 
readpublic static ModuleDescriptor read(InputStream in, Supplier<Set<String>> packageFinder) throws IOException Reads the binary form of a module declaration from an input stream as a module descriptor.If the descriptor encoded in the input stream does not indicate a set of packages in the module then the packageFinderwill be invoked. The set of packages that thepackageFinderreturns must include all the packages that the module exports, opens, as well as the packages of the service implementations that the module provides, and the package of the main class (if the module has a main class). If thepackageFinderthrows anUncheckedIOExceptionthenIOExceptioncause will be re-thrown.If there are bytes following the module descriptor then it is implementation specific as to whether those bytes are read, ignored, or reported as an InvalidModuleDescriptorException. If this method fails with anInvalidModuleDescriptorExceptionorIOExceptionthen it may do so after some, but not all, bytes have been read from the input stream. It is strongly recommended that the stream be promptly closed and discarded if an exception occurs.- API Note:
- The packageFinderparameter is for use when reading module descriptors from legacy module-artifact formats that do not record the set of packages in the descriptor itself.
- Parameters:
- in- The input stream
- packageFinder- A supplier that can produce the set of packages
- Returns:
- The module descriptor
- Throws:
- InvalidModuleDescriptorException- If an invalid module descriptor is detected or the set of packages returned by the- packageFinderdoes not include all of the packages obtained from the module descriptor
- IOException- If an I/O error occurs reading from the input stream or- UncheckedIOExceptionis thrown by the package finder
 
 - 
readpublic static ModuleDescriptor read(InputStream in) throws IOException Reads the binary form of a module declaration from an input stream as a module descriptor. This method works exactly as specified by the 2-argreadmethod with the exception that a packager finder is not used to find additional packages when the module descriptor read from the stream does not indicate the set of packages.- Parameters:
- in- The input stream
- Returns:
- The module descriptor
- Throws:
- InvalidModuleDescriptorException- If an invalid module descriptor is detected
- IOException- If an I/O error occurs reading from the input stream
 
 - 
readpublic static ModuleDescriptor read(ByteBuffer bb, Supplier<Set<String>> packageFinder) Reads the binary form of a module declaration from a byte buffer as a module descriptor.If the descriptor encoded in the byte buffer does not indicate a set of packages in the module then the packageFinderwill be invoked. The set of packages that thepackageFinderreturns must include all the packages that the module exports, opens, as well as the packages of the service implementations that the module provides, and the package of the main class (if the module has a main class). If thepackageFinderthrows anUncheckedIOExceptionthenIOExceptioncause will be re-thrown.The module descriptor is read from the buffer starting at index p, wherepis the buffer'spositionwhen this method is invoked. Upon return the buffer's position will be equal top + nwherenis the number of bytes read from the buffer.If there are bytes following the module descriptor then it is implementation specific as to whether those bytes are read, ignored, or reported as an InvalidModuleDescriptorException. If this method fails with anInvalidModuleDescriptorExceptionthen it may do so after some, but not all, bytes have been read.- API Note:
- The packageFinderparameter is for use when reading module descriptors from legacy module-artifact formats that do not record the set of packages in the descriptor itself.
- Parameters:
- bb- The byte buffer
- packageFinder- A supplier that can produce the set of packages
- Returns:
- The module descriptor
- Throws:
- InvalidModuleDescriptorException- If an invalid module descriptor is detected or the set of packages returned by the- packageFinderdoes not include all of the packages obtained from the module descriptor
 
 - 
readpublic static ModuleDescriptor read(ByteBuffer bb) Reads the binary form of a module declaration from a byte buffer as a module descriptor. This method works exactly as specified by the 2-argreadmethod with the exception that a packager finder is not used to find additional packages when the module descriptor encoded in the buffer does not indicate the set of packages.- Parameters:
- bb- The byte buffer
- Returns:
- The module descriptor
- Throws:
- InvalidModuleDescriptorException- If an invalid module descriptor is detected
 
 
- 
 
-