changeset 4268:187bcc7881f7

more 'requires public' to 'requires transitive'
author jjg
date Tue, 23 Aug 2016 14:26:13 -0700
parents 77cd200ee6ed
children a484bca26c24
files src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java src/jdk.compiler/share/classes/com/sun/source/tree/RequiresTree.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java test/tools/javac/modules/ModuleInfoTest.java
diffstat 7 files changed, 43 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java	Tue Aug 23 14:26:13 2016 -0700
@@ -96,7 +96,7 @@
      * @since 9
      */
     enum DirectiveKind {
-        /** A "requires [public] module-name" directive. */
+        /** A "requires (static|transitive)* module-name" directive. */
         REQUIRES,
         /** An "exports package-name [to module-name-list]" directive. */
         EXPORTS,
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/RequiresTree.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/RequiresTree.java	Tue Aug 23 14:26:13 2016 -0700
@@ -31,17 +31,24 @@
  * For example:
  * <pre>
  *    requires <em>module-name</em>;
- *    requires public <em>module-name</em>;
+ *    requires static <em>module-name</em>;
+ *    requires transitive <em>module-name</em>;
  * </pre>
  *
  * @since 9
  */
 public interface RequiresTree extends DirectiveTree {
     /**
-     * Returns true if this is a "requires public" directive.
-     * @return true if this is a "requires public" directive
+     * Returns true if this is a "requires static" directive.
+     * @return true if this is a "requires static" directive
      */
-    boolean isPublic();
+    boolean isStatic();
+
+    /**
+     * Returns true if this is a "requires transitive" directive.
+     * @return true if this is a "requires transitive" directive
+     */
+    boolean isTransitive();
 
     /**
      * Returns the name of the module that is required.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java	Tue Aug 23 14:26:13 2016 -0700
@@ -187,7 +187,7 @@
     }
 
     /**
-     * 'requires' ['public'] ModuleName ';'
+     * 'requires' ('static' | 'transitive')* ModuleName ';'
      */
     public static class RequiresDirective extends Directive
             implements ModuleElement.RequiresDirective {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Tue Aug 23 14:26:13 2016 -0700
@@ -1029,7 +1029,7 @@
         };
     }
 
-    private final Map<ModuleSymbol, Set<ModuleSymbol>> requiresPublicCache = new HashMap<>();
+    private final Map<ModuleSymbol, Set<ModuleSymbol>> requiresTransitiveCache = new HashMap<>();
 
     private void completeModule(ModuleSymbol msym) {
         if (inInitModules) {
@@ -1075,21 +1075,21 @@
         }
 
         Set<ModuleSymbol> readable = new LinkedHashSet<>();
-        Set<ModuleSymbol> requiresPublic = new HashSet<>();
+        Set<ModuleSymbol> requiresTransitive = new HashSet<>();
 
         for (RequiresDirective d : msym.requires) {
             d.module.complete();
             readable.add(d.module);
-            Set<ModuleSymbol> s = retrieveRequiresPublic(d.module);
+            Set<ModuleSymbol> s = retrieveRequiresTransitive(d.module);
             Assert.checkNonNull(s, () -> "no entry in cache for " + d.module);
             readable.addAll(s);
             if (d.flags.contains(RequiresFlag.TRANSITIVE)) {
-                requiresPublic.add(d.module);
-                requiresPublic.addAll(s);
+                requiresTransitive.add(d.module);
+                requiresTransitive.addAll(s);
             }
         }
 
-        requiresPublicCache.put(msym, requiresPublic);
+        requiresTransitiveCache.put(msym, requiresTransitive);
         initVisiblePackages(msym, readable);
         for (ExportsDirective d: msym.exports) {
             d.packge.modle = msym;
@@ -1097,12 +1097,12 @@
 
     }
 
-    private Set<ModuleSymbol> retrieveRequiresPublic(ModuleSymbol msym) {
-        Set<ModuleSymbol> requiresPublic = requiresPublicCache.get(msym);
+    private Set<ModuleSymbol> retrieveRequiresTransitive(ModuleSymbol msym) {
+        Set<ModuleSymbol> requiresTransitive = requiresTransitiveCache.get(msym);
 
-        if (requiresPublic == null) {
+        if (requiresTransitive == null) {
             //the module graph may contain cycles involving automatic modules or -XaddReads edges
-            requiresPublic = new HashSet<>();
+            requiresTransitive = new HashSet<>();
 
             Set<ModuleSymbol> seen = new HashSet<>();
             List<ModuleSymbol> todo = List.of(msym);
@@ -1112,7 +1112,7 @@
                 todo = todo.tail;
                 if (!seen.add(current))
                     continue;
-                requiresPublic.add(current);
+                requiresTransitive.add(current);
                 current.complete();
                 Iterable<? extends RequiresDirective> requires;
                 if (current != syms.unnamedModule) {
@@ -1129,10 +1129,10 @@
                 }
             }
 
-            requiresPublic.remove(msym);
+            requiresTransitive.remove(msym);
         }
 
-        return requiresPublic;
+        return requiresTransitive;
     }
 
     private void initVisiblePackages(ModuleSymbol msym, Collection<ModuleSymbol> readable) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Aug 23 14:26:13 2016 -0700
@@ -2782,11 +2782,16 @@
         }
 
         @Override @DefinedBy(Api.COMPILER_TREE)
-        public boolean isPublic() {
+        public boolean isTransitive() {
             return isTransitive;
         }
 
         @Override @DefinedBy(Api.COMPILER_TREE)
+        public boolean isStatic() {
+            return isStaticPhase;
+        }
+
+        @Override @DefinedBy(Api.COMPILER_TREE)
         public JCExpression getModuleName() {
             return moduleName;
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Aug 23 14:26:13 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -559,8 +559,8 @@
     }
 
     @Override
-    public JCRequires Requires(boolean isPublic, boolean isStaticPhase, JCExpression qualId) {
-        JCRequires tree = new JCRequires(isPublic, isStaticPhase, qualId);
+    public JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId) {
+        JCRequires tree = new JCRequires(isTransitive, isStaticPhase, qualId);
         tree.pos = pos;
         return tree;
     }
--- a/test/tools/javac/modules/ModuleInfoTest.java	Tue Aug 23 08:14:28 2016 +0100
+++ b/test/tools/javac/modules/ModuleInfoTest.java	Tue Aug 23 14:26:13 2016 -0700
@@ -160,8 +160,14 @@
     public void testExportsDynamicNotFound(Path base) throws Exception {
         Path src = base.resolve("src");
 
-        tb.writeJavaFiles(src.resolve("m1"), "module m1 { requires m2; }", "package pack1; public class B { pack.A a; }");
-        tb.writeJavaFiles(src.resolve("m2"), "module m2 { exports dynamic pack; }","package pack; public class A { }");
+        tb.writeJavaFiles(src.resolve("m1"),
+                "module m1 { requires m2; }",
+                "package pack1; public class B { pack.A a; }"
+        );
+        tb.writeJavaFiles(src.resolve("m2"),
+                "module m2 { exports dynamic pack; }",
+                "package pack; public class A { }"
+        );
 
         Path classes = base.resolve("classes");
         Files.createDirectories(classes);