8173393: Module system implementation refresh (2/2017)
Reviewed-by: mcimadamore, mchung, alanb
Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
--- a/langtools/make/tools/crules/MutableFieldsAnalyzer.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/make/tools/crules/MutableFieldsAnalyzer.java Fri Feb 10 09:06:10 2017 +0000
@@ -102,7 +102,7 @@
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$ModuleFinder",
"moduleFinderClass", "ofMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Configuration",
- "configurationClass", "resolveRequiresAndUsesMethod");
+ "configurationClass", "resolveAndBindMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Layer",
"layerClass", "bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Module",
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/element/Element.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/element/Element.java Fri Feb 10 09:06:10 2017 +0000
@@ -123,6 +123,8 @@
* @see TypeElement#getSimpleName
* @see VariableElement#getSimpleName
* @see ModuleElement#getSimpleName
+ * @revised 9
+ * @spec JPMS
*/
Name getSimpleName();
@@ -158,6 +160,8 @@
*
* @return the enclosing element, or {@code null} if there is none
* @see Elements#getPackageOf
+ * @revised 9
+ * @spec JPMS
*/
Element getEnclosingElement();
@@ -193,6 +197,8 @@
* @see Elements#getAllMembers
* @jls 8.8.9 Default Constructor
* @jls 8.9 Enums
+ * @revised 9
+ * @spec JPMS
*/
List<? extends Element> getEnclosedElements();
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java Fri Feb 10 09:06:10 2017 +0000
@@ -99,6 +99,7 @@
/**
* A module.
* @since 9
+ * @spec JPMS
*/
MODULE;
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/element/ElementVisitor.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/element/ElementVisitor.java Fri Feb 10 09:06:10 2017 +0000
@@ -159,6 +159,7 @@
* @param p a visitor-specified parameter
* @return a visitor-specified result
* @since 9
+ * @spec JPMS
*/
default R visitModule(ModuleElement e, P p) {
return visitUnknown(e, p);
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java Fri Feb 10 09:06:10 2017 +0000
@@ -33,6 +33,7 @@
*
* @see javax.lang.model.util.Elements#getModuleOf
* @since 9
+ * @spec JPMS
*/ // TODO: add @jls to module section
public interface ModuleElement extends Element, QualifiedNameable {
@@ -104,6 +105,7 @@
* future versions of the Java™ programming language.
*
* @since 9
+ * @spec JPMS
*/
enum DirectiveKind {
/** A "requires (static|transitive)* module-name" directive. */
@@ -122,6 +124,7 @@
* Represents a "module statement" within the declaration of this module.
*
* @since 9
+ * @spec JPMS
*
*/ // TODO: add jls to Module Statement
interface Directive {
@@ -136,6 +139,7 @@
/**
* A dependency of a module.
* @since 9
+ * @spec JPMS
*/
interface RequiresDirective extends Directive {
/**
@@ -160,6 +164,7 @@
/**
* An exported package of a module.
* @since 9
+ * @spec JPMS
*/
interface ExportsDirective extends Directive {
@@ -181,6 +186,7 @@
/**
* An opened package of a module.
* @since 9
+ * @spec JPMS
*/
interface OpensDirective extends Directive {
@@ -202,6 +208,7 @@
/**
* An implementation of a service provided by a module.
* @since 9
+ * @spec JPMS
*/
interface ProvidesDirective extends Directive {
/**
@@ -220,6 +227,7 @@
/**
* A reference to a service used by a module.
* @since 9
+ * @spec JPMS
*/
interface UsesDirective extends Directive {
/**
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/element/PackageElement.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/element/PackageElement.java Fri Feb 10 09:06:10 2017 +0000
@@ -93,6 +93,9 @@
* source version} without modules.
*
* @return the enclosing module or {@code null} if no such module exists
+ *
+ * @revised 9
+ * @spec JPMS
*/
@Override
Element getEnclosingElement();
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/type/TypeKind.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/type/TypeKind.java Fri Feb 10 09:06:10 2017 +0000
@@ -157,6 +157,7 @@
* A pseudo-type corresponding to a module element.
* @see NoType
* @since 9
+ * @spec JPMS
*/
MODULE;
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Fri Feb 10 09:06:10 2017 +0000
@@ -136,6 +136,7 @@
* @return the result of {@code visitUnknown}
*
* @since 9
+ * @spec JPMS
*/
@Override
public R visitModule(ModuleElement e, P p) {
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor9.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor9.java Fri Feb 10 09:06:10 2017 +0000
@@ -63,6 +63,7 @@
* @see AbstractElementVisitor7
* @see AbstractElementVisitor8
* @since 9
+ * @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public abstract class AbstractElementVisitor9<R, P> extends AbstractElementVisitor8<R, P> {
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementFilter.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementFilter.java Fri Feb 10 09:06:10 2017 +0000
@@ -189,6 +189,7 @@
* @return a list of modules in {@code elements}
* @param elements the elements to filter
* @since 9
+ * @spec JPMS
*/
public static List<ModuleElement>
modulesIn(Iterable<? extends Element> elements) {
@@ -200,6 +201,7 @@
* @return a set of modules in {@code elements}
* @param elements the elements to filter
* @since 9
+ * @spec JPMS
*/
public static Set<ModuleElement>
modulesIn(Set<? extends Element> elements) {
@@ -236,6 +238,7 @@
* @return a list of {@code exports} directives in {@code directives}
* @param directives the directives to filter
* @since 9
+ * @spec JPMS
*/
public static List<ExportsDirective>
exportsIn(Iterable<? extends Directive> directives) {
@@ -258,6 +261,7 @@
* @return a list of {@code provides} directives in {@code directives}
* @param directives the directives to filter
* @since 9
+ * @spec JPMS
*/
public static List<ProvidesDirective>
providesIn(Iterable<? extends Directive> directives) {
@@ -269,6 +273,7 @@
* @return a list of {@code requires} directives in {@code directives}
* @param directives the directives to filter
* @since 9
+ * @spec JPMS
*/
public static List<RequiresDirective>
requiresIn(Iterable<? extends Directive> directives) {
@@ -280,6 +285,7 @@
* @return a list of {@code uses} directives in {@code directives}
* @param directives the directives to filter
* @since 9
+ * @spec JPMS
*/
public static List<UsesDirective>
usesIn(Iterable<? extends Directive> directives) {
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor9.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor9.java Fri Feb 10 09:06:10 2017 +0000
@@ -75,6 +75,7 @@
* @see ElementKindVisitor7
* @see ElementKindVisitor8
* @since 9
+ * @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class ElementKindVisitor9<R, P> extends ElementKindVisitor8<R, P> {
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner9.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner9.java Fri Feb 10 09:06:10 2017 +0000
@@ -88,6 +88,7 @@
* @see ElementScanner7
* @see ElementScanner8
* @since 9
+ * @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class ElementScanner9<R, P> extends ElementScanner8<R, P> {
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Fri Feb 10 09:06:10 2017 +0000
@@ -111,6 +111,7 @@
* @param name the name
* @return the named module element, or {@code null} if it cannot be found
* @since 9
+ * @spec JPMS
*/
default ModuleElement getModuleElement(CharSequence name) {
return null;
@@ -359,6 +360,7 @@
* @param type the element being examined
* @return the module of an element
* @since 9
+ * @spec JPMS
*/
default ModuleElement getModuleOf(Element type) {
return null;
--- a/langtools/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitor9.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitor9.java Fri Feb 10 09:06:10 2017 +0000
@@ -71,6 +71,7 @@
* @see SimpleElementVisitor7
* @see SimpleElementVisitor8
* @since 9
+ * @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class SimpleElementVisitor9<R, P> extends SimpleElementVisitor8<R, P> {
--- a/langtools/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java Fri Feb 10 09:06:10 2017 +0000
@@ -165,22 +165,42 @@
fileManager.close();
}
+ /**
+ * @since 9
+ * @spec JPMS
+ */
public Location getLocationForModule(Location location, String moduleName) throws IOException {
return fileManager.getLocationForModule(location, moduleName);
}
+ /**
+ * @since 9
+ * @spec JPMS
+ */
public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException {
return fileManager.getLocationForModule(location, fo, pkgName);
}
+ /**
+ * @since 9
+ * @spec JPMS
+ */
public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
return fileManager.getServiceLoader(location, service);
}
+ /**
+ * @since 9
+ * @spec JPMS
+ */
public String inferModuleName(Location location) throws IOException {
return fileManager.inferModuleName(location);
}
+ /**
+ * @since 9
+ * @spec JPMS
+ */
public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
return fileManager.listLocationsForModules(location);
}
--- a/langtools/src/java.compiler/share/classes/javax/tools/JavaFileManager.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/tools/JavaFileManager.java Fri Feb 10 09:06:10 2017 +0000
@@ -165,6 +165,7 @@
*
* @return true if this location is expected to contain modules
* @since 9
+ * @spec JPMS
*/
default boolean isModuleOrientedLocation() {
return getName().matches("\\bMODULE\\b");
@@ -472,6 +473,7 @@
* @throws IllegalArgumentException if the location is neither an output location nor a
* module-oriented location
* @since 9
+ * @spec JPMS
*/ // TODO: describe failure modes
default Location getLocationForModule(Location location, String moduleName) throws IOException {
throw new UnsupportedOperationException();
@@ -499,6 +501,7 @@
* @throws IllegalArgumentException if the location is neither an output location nor a
* module-oriented location
* @since 9
+ * @spec JPMS
*/
default Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException {
throw new UnsupportedOperationException();
@@ -522,6 +525,7 @@
* @throws IOException if an I/O error occurred
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @since 9
+ * @spec JPMS
*/ // TODO: describe failure modes
default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
throw new UnsupportedOperationException();
@@ -540,6 +544,7 @@
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @throws IllegalArgumentException if the location is not one known to this file manager
* @since 9
+ * @spec JPMS
*/ // TODO: describe failure modes
default String inferModuleName(Location location) throws IOException {
throw new UnsupportedOperationException();
@@ -559,6 +564,7 @@
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @throws IllegalArgumentException if the location is not a module-oriented location
* @since 9
+ * @spec JPMS
*/ // TODO: describe failure modes
default Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
throw new UnsupportedOperationException();
--- a/langtools/src/java.compiler/share/classes/javax/tools/StandardLocation.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/java.compiler/share/classes/javax/tools/StandardLocation.java Fri Feb 10 09:06:10 2017 +0000
@@ -64,6 +64,7 @@
/**
* Location to search for modules containing annotation processors.
+ * @spec JPMS
* @since 9
*/
ANNOTATION_PROCESSOR_MODULE_PATH,
@@ -82,24 +83,28 @@
/**
* Location to search for the source code of modules.
+ * @spec JPMS
* @since 9
*/
MODULE_SOURCE_PATH,
/**
* Location to search for upgradeable system modules.
+ * @spec JPMS
* @since 9
*/
UPGRADE_MODULE_PATH,
/**
* Location to search for system modules.
+ * @spec JPMS
* @since 9
*/
SYSTEM_MODULES,
/**
* Location to search for precompiled user modules.
+ * @spec JPMS
* @since 9
*/
MODULE_PATH;
@@ -115,6 +120,9 @@
*
* @param name a name
* @return a location
+ *
+ * @revised 9
+ * @spec JPMS
*/
public static Location locationFor(final String name) {
if (locations.isEmpty()) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java Fri Feb 10 09:06:10 2017 +0000
@@ -53,8 +53,8 @@
/** Flags for RequiresDirective. */
public enum RequiresFlag {
- TRANSITIVE(0x0010),
- STATIC_PHASE(0x0020),
+ TRANSITIVE(0x0020),
+ STATIC_PHASE(0x0040),
SYNTHETIC(0x1000),
MANDATED(0x8000),
EXTRA(0x10000);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Fri Feb 10 09:06:10 2017 +0000
@@ -968,7 +968,7 @@
Collection<Path> paths = locations.getLocation(location);
ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()]));
Layer bootLayer = Layer.boot();
- Configuration cf = bootLayer.configuration().resolveRequiresAndUses(ModuleFinder.of(), finder, Collections.emptySet());
+ Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet());
Layer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader());
return ServiceLoaderHelper.load(layer, service);
} else {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java Fri Feb 10 09:06:10 2017 +0000
@@ -272,12 +272,12 @@
init();
}
- public Configuration resolveRequiresAndUses(
+ public Configuration resolveAndBind(
ModuleFinder beforeFinder,
ModuleFinder afterFinder,
Collection<String> roots) {
try {
- Object result = resolveRequiresAndUsesMethod.invoke(theRealConfiguration,
+ Object result = resolveAndBindMethod.invoke(theRealConfiguration,
beforeFinder.theRealModuleFinder,
afterFinder.theRealModuleFinder,
roots
@@ -293,7 +293,7 @@
// -----------------------------------------------------------------------------------------
private static Class<?> configurationClass = null;
- private static Method resolveRequiresAndUsesMethod;
+ private static Method resolveAndBindMethod;
static final Class<?> getConfigurationClass() {
init();
@@ -305,7 +305,7 @@
try {
configurationClass = Class.forName("java.lang.module.Configuration", false, null);
Class<?> moduleFinderInterface = ModuleFinder.getModuleFinderClass();
- resolveRequiresAndUsesMethod = configurationClass.getDeclaredMethod("resolveRequiresAndUses",
+ resolveAndBindMethod = configurationClass.getDeclaredMethod("resolveAndBind",
moduleFinderInterface,
moduleFinderInterface,
Collection.class
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java Fri Feb 10 09:06:10 2017 +0000
@@ -38,8 +38,8 @@
* deletion without notice.</b>
*/
public class Module_attribute extends Attribute {
- public static final int ACC_TRANSITIVE = 0x10;
- public static final int ACC_STATIC_PHASE = 0x20;
+ public static final int ACC_TRANSITIVE = 0x20;
+ public static final int ACC_STATIC_PHASE = 0x40;
public static final int ACC_OPEN = 0x20;
public static final int ACC_SYNTHETIC = 0x1000;
public static final int ACC_MANDATED = 0x8000;
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java Fri Feb 10 09:06:10 2017 +0000
@@ -118,7 +118,7 @@
}
this.configuration = Configuration.empty()
- .resolveRequires(finder, ModuleFinder.of(), mods);
+ .resolve(finder, ModuleFinder.of(), mods);
this.configuration.modules().stream()
.map(ResolvedModule::reference)
@@ -272,7 +272,7 @@
return nameToModule.values().stream();
} else {
return Configuration.empty()
- .resolveRequires(finder, ModuleFinder.of(), roots)
+ .resolve(finder, ModuleFinder.of(), roots)
.modules().stream()
.map(ResolvedModule::name)
.map(nameToModule::get);
@@ -422,18 +422,13 @@
}
private ModuleDescriptor dropHashes(ModuleDescriptor md) {
- ModuleDescriptor.Builder builder = ModuleDescriptor.module(md.name());
+ ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(md.name());
md.requires().forEach(builder::requires);
md.exports().forEach(builder::exports);
md.opens().forEach(builder::opens);
md.provides().stream().forEach(builder::provides);
md.uses().stream().forEach(builder::uses);
-
- Set<String> concealed = new HashSet<>(md.packages());
- md.exports().stream().map(Exports::source).forEach(concealed::remove);
- md.opens().stream().map(Opens::source).forEach(concealed::remove);
- concealed.forEach(builder::contains);
-
+ builder.packages(md.packages());
return builder.build();
}
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java Fri Feb 10 09:06:10 2017 +0000
@@ -26,8 +26,6 @@
package com.sun.tools.jdeps;
import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleDescriptor.Exports;
-import java.lang.module.ModuleDescriptor.Opens;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
@@ -55,6 +53,7 @@
private final ModuleDescriptor descriptor;
private final Map<String, Set<String>> exports;
+ private final Map<String, Set<String>> opens;
private final boolean isSystem;
private final URI location;
@@ -63,6 +62,7 @@
this.descriptor = null;
this.location = null;
this.exports = Collections.emptyMap();
+ this.opens = Collections.emptyMap();
this.isSystem = true;
}
@@ -70,12 +70,14 @@
URI location,
ModuleDescriptor descriptor,
Map<String, Set<String>> exports,
+ Map<String, Set<String>> opens,
boolean isSystem,
ClassFileReader reader) {
super(name, location, reader);
this.descriptor = descriptor;
this.location = location;
this.exports = Collections.unmodifiableMap(exports);
+ this.opens = Collections.unmodifiableMap(opens);
this.isSystem = isSystem;
}
@@ -124,35 +126,52 @@
return descriptor.packages();
}
- /**
- * Tests if the package of the given name is exported.
- */
- public boolean isExported(String pn) {
- return exports.containsKey(pn) ? exports.get(pn).isEmpty() : false;
- }
-
public boolean isJDKUnsupported() {
return JDK_UNSUPPORTED.equals(this.name());
}
/**
- * Converts this module to a strict module with the given dependences
+ * Converts this module to a normal module with the given dependences
*
* @throws IllegalArgumentException if this module is not an automatic module
*/
- public Module toStrictModule(Map<String, Boolean> requires) {
+ public Module toNormalModule(Map<String, Boolean> requires) {
if (!isAutomatic()) {
- throw new IllegalArgumentException(name() + " already a strict module");
+ throw new IllegalArgumentException(name() + " not an automatic module");
}
- return new StrictModule(this, requires);
+ return new NormalModule(this, requires);
+ }
+
+ /**
+ * Tests if the package of the given name is exported.
+ */
+ public boolean isExported(String pn) {
+ return exports.containsKey(pn) && exports.get(pn).isEmpty();
}
/**
- * Tests if the package of the given name is qualifiedly exported
- * to the target.
+ * Tests if the package of the given name is exported to the target
+ * in a qualified fashion.
*/
public boolean isExported(String pn, String target) {
- return isExported(pn) || exports.containsKey(pn) && exports.get(pn).contains(target);
+ return isExported(pn)
+ || exports.containsKey(pn) && exports.get(pn).contains(target);
+ }
+
+ /**
+ * Tests if the package of the given name is open.
+ */
+ public boolean isOpen(String pn) {
+ return opens.containsKey(pn) && opens.get(pn).isEmpty();
+ }
+
+ /**
+ * Tests if the package of the given name is open to the target
+ * in a qualified fashion.
+ */
+ public boolean isOpen(String pn, String target) {
+ return isOpen(pn)
+ || opens.containsKey(pn) && opens.get(pn).contains(target);
}
@Override
@@ -193,19 +212,28 @@
}
Map<String, Set<String>> exports = new HashMap<>();
+ Map<String, Set<String>> opens = new HashMap<>();
- descriptor.exports().stream()
- .forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
- .addAll(exp.targets()));
-
- return new Module(name, location, descriptor, exports, isSystem, reader);
+ if (descriptor.isAutomatic()) {
+ // ModuleDescriptor::exports and opens returns an empty set
+ descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
+ descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
+ } else {
+ descriptor.exports().stream()
+ .forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
+ .addAll(exp.targets()));
+ descriptor.opens().stream()
+ .forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
+ .addAll(exp.targets()));
+ }
+ return new Module(name, location, descriptor, exports, opens, isSystem, reader);
}
}
private static class UnnamedModule extends Module {
private UnnamedModule() {
super("unnamed", null, null,
- Collections.emptyMap(),
+ Collections.emptyMap(), Collections.emptyMap(),
false, null);
}
@@ -230,19 +258,22 @@
}
}
- private static class StrictModule extends Module {
+ /**
+ * A normal module has a module-info.class
+ */
+ private static class NormalModule extends Module {
private final ModuleDescriptor md;
/**
- * Converts the given automatic module to a strict module.
+ * Converts the given automatic module to a normal module.
*
* Replace this module's dependences with the given requires and also
* declare service providers, if specified in META-INF/services configuration file
*/
- private StrictModule(Module m, Map<String, Boolean> requires) {
- super(m.name(), m.location, m.descriptor, m.exports, m.isSystem, m.reader());
+ private NormalModule(Module m, Map<String, Boolean> requires) {
+ super(m.name(), m.location, m.descriptor, m.exports, m.opens, m.isSystem, m.reader());
- ModuleDescriptor.Builder builder = ModuleDescriptor.module(m.name());
+ ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(m.name());
requires.keySet().forEach(mn -> {
if (requires.get(mn).equals(Boolean.TRUE)) {
builder.requires(Set.of(ModuleDescriptor.Requires.Modifier.TRANSITIVE), mn);
@@ -250,16 +281,10 @@
builder.requires(mn);
}
});
- m.descriptor.exports().forEach(e -> builder.exports(e));
- m.descriptor.opens().forEach(o -> builder.opens(o));
- m.descriptor.uses().forEach(s -> builder.uses(s));
- m.descriptor.provides().forEach(p -> builder.provides(p));
-
- Set<String> concealed = new HashSet<>(m.descriptor.packages());
- m.descriptor.exports().stream().map(Exports::source).forEach(concealed::remove);
- m.descriptor.opens().stream().map(Opens::source).forEach(concealed::remove);
- concealed.forEach(builder::contains);
-
+ // exports all packages
+ m.descriptor.packages().forEach(builder::exports);
+ m.descriptor.uses().forEach(builder::uses);
+ m.descriptor.provides().forEach(builder::provides);
this.md = builder.build();
}
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleAnalyzer.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleAnalyzer.java Fri Feb 10 09:06:10 2017 +0000
@@ -150,7 +150,7 @@
private ModuleDescriptor descriptor(Set<Module> requiresTransitive,
Set<Module> requires) {
- ModuleDescriptor.Builder builder = ModuleDescriptor.module(root.name());
+ ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(root.name());
if (!root.name().equals(JAVA_BASE))
builder.requires(Set.of(MANDATED), JAVA_BASE);
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java Fri Feb 10 09:06:10 2017 +0000
@@ -181,7 +181,7 @@
RootModule(String name) {
super(name);
- ModuleDescriptor.Builder builder = ModuleDescriptor.module(name);
+ ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(name);
this.descriptor = builder.build();
}
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleInfoBuilder.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleInfoBuilder.java Fri Feb 10 09:06:10 2017 +0000
@@ -43,10 +43,12 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.stream.Collectors.*;
@@ -60,8 +62,8 @@
final Analyzer analyzer;
// an input JAR file (loaded as an automatic module for analysis)
- // maps to an explicit module to generate module-info.java
- final Map<Module, Module> automaticToExplicitModule;
+ // maps to a normal module to generate module-info.java
+ final Map<Module, Module> automaticToNormalModule;
public ModuleInfoBuilder(JdepsConfiguration configuration,
List<String> args,
Path outputdir,
@@ -78,20 +80,20 @@
.map(fn -> Paths.get(fn))
.collect(toList());
- // automatic module to convert to explicit module
- this.automaticToExplicitModule = ModuleFinder.of(paths.toArray(new Path[0]))
+ // automatic module to convert to normal module
+ this.automaticToNormalModule = ModuleFinder.of(paths.toArray(new Path[0]))
.findAll().stream()
.map(configuration::toModule)
.collect(toMap(Function.identity(), Function.identity()));
- Optional<Module> om = automaticToExplicitModule.keySet().stream()
+ Optional<Module> om = automaticToNormalModule.keySet().stream()
.filter(m -> !m.descriptor().isAutomatic())
.findAny();
if (om.isPresent()) {
throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile",
om.get().getPathName()));
}
- if (automaticToExplicitModule.isEmpty()) {
+ if (automaticToNormalModule.isEmpty()) {
throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args));
}
}
@@ -115,13 +117,13 @@
Path file = outputdir.resolve(m.name()).resolve("module-info.java");
// computes requires and requires transitive
- Module explicitModule = toExplicitModule(m, apiDeps);
- if (explicitModule != null) {
- automaticToExplicitModule.put(m, explicitModule);
+ Module normalModule = toNormalModule(m, apiDeps);
+ if (normalModule != null) {
+ automaticToNormalModule.put(m, normalModule);
// generate module-info.java
System.out.format("writing to %s%n", file);
- writeModuleInfo(file, explicitModule.descriptor());
+ writeModuleInfo(file, normalModule.descriptor());
} else {
// find missing dependences
System.out.format("Missing dependence: %s not generated%n", file);
@@ -139,7 +141,7 @@
return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS;
}
- private Module toExplicitModule(Module module, Set<Archive> requiresTransitive)
+ private Module toNormalModule(Module module, Set<Archive> requiresTransitive)
throws IOException
{
// done analysis
@@ -159,21 +161,21 @@
.map(Archive::getModule)
.forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE));
- return module.toStrictModule(requires);
+ return module.toNormalModule(requires);
}
/**
* Returns the stream of resulting modules
*/
Stream<Module> modules() {
- return automaticToExplicitModule.values().stream();
+ return automaticToNormalModule.values().stream();
}
/**
* Returns the stream of resulting ModuleDescriptors
*/
public Stream<ModuleDescriptor> descriptors() {
- return automaticToExplicitModule.entrySet().stream()
+ return automaticToNormalModule.entrySet().stream()
.map(Map.Entry::getValue)
.map(Module::descriptor);
}
@@ -205,13 +207,14 @@
md.requires().stream()
.filter(req -> !req.name().equals("java.base")) // implicit requires
.sorted(Comparator.comparing(Requires::name))
- .forEach(req -> writer.format(" requires %s;%n", req));
+ .forEach(req -> writer.format(" requires %s;%n",
+ toString(req.modifiers(), req.name())));
if (!open) {
md.exports().stream()
.peek(exp -> {
- if (exp.targets().size() > 0)
- throw new InternalError(md.name() + " qualified exports: " + exp);
+ if (exp.isQualified())
+ throw new InternalError(md.name() + " qualified exports: " + exp);
})
.sorted(Comparator.comparing(Exports::source))
.forEach(exp -> writer.format(" exports %s;%n", exp.source()));
@@ -231,7 +234,16 @@
}
private Set<Module> automaticModules() {
- return automaticToExplicitModule.keySet();
+ return automaticToNormalModule.keySet();
+ }
+
+ /**
+ * Returns a string containing the given set of modifiers and label.
+ */
+ private static <M> String toString(Set<M> mods, String what) {
+ return (Stream.concat(mods.stream().map(e -> e.toString().toLowerCase(Locale.US)),
+ Stream.of(what)))
+ .collect(Collectors.joining(" "));
}
/**
--- a/langtools/test/jdk/jshell/KullaTesting.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/test/jdk/jshell/KullaTesting.java Fri Feb 10 09:06:10 2017 +0000
@@ -213,7 +213,7 @@
ModuleFinder finder = ModuleFinder.of(modPath);
Layer parent = Layer.boot();
Configuration cf = parent.configuration()
- .resolveRequires(finder, ModuleFinder.of(), Set.of(moduleName));
+ .resolve(finder, ModuleFinder.of(), Set.of(moduleName));
ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = parent.defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader(moduleName);
--- a/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java Thu Feb 09 17:21:49 2017 +0000
+++ b/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java Fri Feb 10 09:06:10 2017 +0000
@@ -107,7 +107,7 @@
// by reflective lookup, to avoid explicit references that are not available
// when running javac on JDK 8.
ignore("com/sun/tools/javac/util/JDK9Wrappers$Configuration",
- "resolveRequiresAndUsesMethod", "configurationClass");
+ "resolveAndBindMethod", "configurationClass");
ignore("com/sun/tools/javac/util/JDK9Wrappers$Layer",
"bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod", "layerClass");
ignore("com/sun/tools/javac/util/JDK9Wrappers$Module",