< prev index next >
src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java
Print this page
@@ -24,12 +24,10 @@
*/
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;
import java.util.HashSet;
import java.util.Map;
@@ -53,31 +51,35 @@
}
}
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;
protected Module(String name) {
super(name);
this.descriptor = null;
this.location = null;
this.exports = Collections.emptyMap();
+ this.opens = Collections.emptyMap();
this.isSystem = true;
}
private Module(String name,
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;
}
/**
* Returns module name
@@ -122,39 +124,56 @@
public Set<String> packages() {
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 NormalModule(this, requires);
}
- return new StrictModule(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
public String toString() {
return name();
@@ -191,23 +210,32 @@
if (descriptor.isAutomatic() && isSystem) {
throw new InternalError("JDK module: " + name + " can't be automatic module");
}
Map<String, Set<String>> exports = new HashMap<>();
+ Map<String, Set<String>> opens = new HashMap<>();
+ 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()));
-
- return new Module(name, location, descriptor, exports, isSystem, reader);
+ 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);
}
@Override
public String name() {
@@ -228,40 +256,37 @@
public boolean isExported(String pn) {
return true;
}
}
- 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);
} else {
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);
-
+ m.descriptor.packages().forEach(builder::exports);
+ m.descriptor.packages().forEach(builder::opens);
+ m.descriptor.uses().forEach(builder::uses);
+ m.descriptor.provides().forEach(builder::provides);
this.md = builder.build();
}
@Override
public ModuleDescriptor descriptor() {
< prev index next >