Add "source of module name" to ModuleDescriptor API
Christian Stein
sormuras at gmail.com
Thu Jul 4 06:40:36 UTC 2019
On Tue, Jul 2, 2019 at 1:14 PM Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 02/07/2019 09:47, Christian Stein wrote:
> > Hi,
> >
> > at the moment, class `java.lang.module.ModuleDescriptor` only
> > provides an `isAutomatic()` getter -- which doesn't allow to
> > determine from where the module name actually came from.
> >
> > Program `PresentModule.java` [1] creates a `JarFile` instance
> > to determine the source of an automatic module.
> >
> > As the module name is resolved by the runtime from a
> > specific source, it could be stored as a constant in the
> > `ModuleDescriptor` instance at resolution time.
> >
> > I propose to extend the `ModuleDescriptor` class with a
> >
> > public enum NameSource {
> > FILENAME, MANIFEST, DESCRIPTOR
> > }
> >
> > and an accessor:
> >
> > public NameSource nameSource { return ... }
> >
> ModuleDescriptor just describes a named module and doesn't care how the
> module name came about when creating an automatic module. Anything
> working with module locations should use a ModuleReference as it defines
> the "location" method to get a URI to the module content (if possible).
> So probably better if tools like this used a ModuleReference and special
> cased the JAR case when they want to know if the module name was
> derived from the JAR file name or came from the value of the
> Automatic-Module-Name attribute.
>
> -Alan
>
Thank you for the clarification, Alan.
Wondering why `isAutomatic()` is part of the API then. Its underlying
value is also not declared by the author of the module, but rather
determined at/by the runtime.
More information about the jigsaw-dev
mailing list