Comparable<ModuleDescriptor>
public class ModuleDescriptor extends Object implements Comparable<ModuleDescriptor>
A ModuleDescriptor
is typically created from the binary form
of a module declaration. Alternatively, the ModuleDescriptor.Builder
class can be used to create a ModuleDescriptor
from its components.
The module
, openModule
, and automaticModule
methods create builders for building
different kinds of modules.
ModuleDescriptor
objects are immutable and safe for use by
multiple concurrent threads.
Module
Modifier and Type | Class | Description |
---|---|---|
static class |
ModuleDescriptor.Builder |
A builder used for building
ModuleDescriptor objects. |
static class |
ModuleDescriptor.Exports |
A module export, may be qualified or unqualified.
|
static class |
ModuleDescriptor.Opens |
Represents a module opens directive, may be qualified or
unqualified.
|
static class |
ModuleDescriptor.Provides |
A service that a module provides one or more implementations of.
|
static class |
ModuleDescriptor.Requires |
A dependence upon a module
|
static class |
ModuleDescriptor.Version |
A module's version string.
|
Modifier and Type | Method | Description |
---|---|---|
static ModuleDescriptor.Builder |
automaticModule(String name) |
Instantiates a builder to build a module descriptor for an automatic
module.
|
int |
compareTo(ModuleDescriptor that) |
Compares this module descriptor to another.
|
boolean |
equals(Object ob) |
Tests this module descriptor for equality with the given object.
|
Set<ModuleDescriptor.Exports> |
exports() |
The module exports.
|
int |
hashCode() |
Computes a hash code for this module descriptor.
|
boolean |
isAutomatic() |
Returns
true if this is an automatic module. |
boolean |
isOpen() |
Returns
true if this is an open module. |
boolean |
isSynthetic() |
Returns
true if this module descriptor was not generated
from an explicit module declaration (module-info.java )
or an implicit module declaration (an automatic
module). |
Optional<String> |
mainClass() |
Returns the module's main class.
|
static ModuleDescriptor.Builder |
module(String name) |
Instantiates a builder to build a module descriptor.
|
String |
name() |
The module name.
|
static ModuleDescriptor.Builder |
openModule(String name) |
Instantiates a builder to build a module descriptor for an open module.
|
Set<ModuleDescriptor.Opens> |
opens() |
The module opens directives.
|
Optional<String> |
osArch() |
Returns the operating system architecture if this module is operating
system architecture specific.
|
Optional<String> |
osName() |
Returns the operating system name if this module is operating system
specific.
|
Optional<String> |
osVersion() |
Returns the operating system version if this module is operating
system version specific.
|
Set<String> |
packages() |
Returns the names of all packages in this module.
|
Set<ModuleDescriptor.Provides> |
provides() |
The services that this module provides.
|
static ModuleDescriptor |
read(InputStream in) |
Reads the binary form of a module declaration from an input stream
as a module descriptor.
|
static ModuleDescriptor |
read(InputStream in,
Supplier<Set<String>> packageFinder) |
Reads the binary form of a module declaration from an input stream
as a module descriptor.
|
static ModuleDescriptor |
read(ByteBuffer bb) |
Reads the binary form of a module declaration from a byte buffer
as a module descriptor.
|
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.
|
Set<ModuleDescriptor.Requires> |
requires() |
The dependences of this module.
|
String |
toNameAndVersion() |
Returns a string containing this module's name and, if present, its
version.
|
String |
toString() |
Returns a string describing this descriptor.
|
Set<String> |
uses() |
The service dependences of this module.
|
Optional<ModuleDescriptor.Version> |
version() |
Returns this module's version.
|
public String name()
The module name.
public boolean isOpen()
Returns true
if this is an open module.
An open module does not declare any open packages (the opens
method returns an empty set) but the resulting module is treated
as if all packages are open.
true
if this is an open modulepublic boolean isAutomatic()
Returns true
if this is an automatic module.
An automatic module is defined implicitly rather than explicitly
and therefore does not have a module declaration. JAR files located on
the application module path, or by the ModuleFinder
returned by
ModuleFinder.of
, are
treated as automatic modules if they do have not have a module
declaration.
true
if this is an automatic modulepublic boolean isSynthetic()
Returns true
if this module descriptor was not generated
from an explicit module declaration (module-info.java
)
or an implicit module declaration (an automatic
module).
true
if this module descriptor was not generated by
an explicit or implicit module declarationpublic Set<ModuleDescriptor.Requires> requires()
The dependences of this module.
ModuleDescriptor.Requires
objectspublic Set<ModuleDescriptor.Exports> exports()
The module exports.
public Set<ModuleDescriptor.Opens> opens()
The module opens directives.
Each Opens
object in the set represents a package (and
the set of target module names when qualified) where all types in the
package, and all their members, not just public types and their public
members, can be reflected on when using APIs that bypass or suppress
default Java language access control checks.
This method returns an empty set when invoked on open
module.
public Set<String> uses()
The service dependences of this module.
public Set<ModuleDescriptor.Provides> provides()
The services that this module provides.
public Optional<ModuleDescriptor.Version> version()
public String toNameAndVersion()
public Optional<String> mainClass()
public Optional<String> osName()
Optional
if this module is not operating system specificpublic Optional<String> osArch()
Optional
if this module is not operating system architecture specificpublic Optional<String> osVersion()
Optional
if this module is not operating system version specificpublic Set<String> packages()
public int compareTo(ModuleDescriptor that)
Two ModuleDescriptor
objects are compared by comparing their
module name lexicographically. Where the module names are equal then
the versions, if present, are compared.
compareTo
in interface Comparable<ModuleDescriptor>
that
- The object to which this module descriptor is to be comparedpublic boolean equals(Object ob)
If the given object is not a ModuleDescriptor
then this
method returns false
. Two module descriptors are equal if each
of their corresponding components is equal.
This method satisfies the general contract of the Object.equals
method.
equals
in class Object
ob
- the object to which this object is to be comparedtrue
if, and only if, the given object is a module
descriptor that is equal to this module descriptorObject.hashCode()
,
HashMap
public int hashCode()
The hash code is based upon the components of the module descriptor,
and satisfies the general contract of the Object.hashCode
method.
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
public static ModuleDescriptor.Builder module(String name)
name
- The module nameIllegalArgumentException
- If the module name is null
or is not a legal Java
identifierpublic static ModuleDescriptor.Builder openModule(String name)
As an example, the following creates a module descriptor for an open
name "m
" containing two packages, one of which is exported.
ModuleDescriptor descriptor = ModuleDescriptor.openModule("m")
.requires("java.base")
.exports("p")
.contains("q")
.build();
name
- The module nameIllegalArgumentException
- If the module name is null
or is not a legal Java
identifierpublic static ModuleDescriptor.Builder automaticModule(String name)
Configuration
) so that they read all other modules. When
Instantiated in the Java virtual machine as a Module
then the Module reads every unnamed module in the Java virtual machine.name
- The module nameIllegalArgumentException
- If the module name is null
or is not a legal Java
identifierModuleFinder.of(Path[])
public static ModuleDescriptor read(InputStream in, Supplier<Set<String>> packageFinder) throws IOException
If the descriptor encoded in the input stream does not indicate a
set of packages in the module then the packageFinder
will be
invoked. If the packageFinder
throws an UncheckedIOException
then IOException
cause 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 an InvalidModuleDescriptorException
or
IOException
then 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.
packageFinder
parameter is for use when reading
module descriptors from legacy module-artifact formats that do not
record the set of packages in the descriptor itself.in
- The input streampackageFinder
- A supplier that can produce the set of packagesInvalidModuleDescriptorException
- If an invalid module descriptor is detectedIOException
- If an I/O error occurs reading from the input stream or
UncheckedIOException
is thrown by the package finderpublic static ModuleDescriptor read(InputStream in) throws IOException
in
- The input streamInvalidModuleDescriptorException
- If an invalid module descriptor is detectedIOException
- If an I/O error occurs reading from the input streampublic static ModuleDescriptor read(ByteBuffer bb, Supplier<Set<String>> packageFinder)
If the descriptor encoded in the byte buffer does not indicate a
set of packages then the packageFinder
will be invoked.
The module descriptor is read from the buffer stating at index
p
, where p
is the buffer's position
when this method is invoked. Upon return the buffer's position
will be equal to p + n
where n
is 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 an InvalidModuleDescriptorException
then it
may do so after some, but not all, bytes have been read.
packageFinder
parameter is for use when reading
module descriptors from legacy module-artifact formats that do not
record the set of packages in the descriptor itself.bb
- The byte bufferpackageFinder
- A supplier that can produce the set of packagesInvalidModuleDescriptorException
- If an invalid module descriptor is detectedpublic static ModuleDescriptor read(ByteBuffer bb)
bb
- The byte bufferInvalidModuleDescriptorException
- If an invalid module descriptor is detected Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b153-2