changeset 4270:7dc08febda0a

initial passthrough support for 'exports private'
author jjg
date Tue, 23 Aug 2016 17:12:21 -0700
parents a484bca26c24
children 82914aba2ab3
files src/jdk.compiler/share/classes/com/sun/source/tree/ExportsTree.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/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
diffstat 10 files changed, 82 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/ExportsTree.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ExportsTree.java	Tue Aug 23 17:12:21 2016 -0700
@@ -34,12 +34,26 @@
  * <pre>
  *    exports <em>package-name</em>;
  *    exports <em>package-name</em> to <em>module-name</em>;
+ *    exports dynamic <em>package-name</em> to <em>module-name</em>;
+ *    exports private <em>package-name</em> to <em>module-name</em>;
  * </pre>
  *
  * @since 9
  */
 public interface ExportsTree extends DirectiveTree {
     /**
+     * Returns true if this is a "exports dynamic" directive.
+     * @return true if this is a "exports dynamic" directive
+     */
+    boolean isDynamic();
+
+    /**
+     * Returns true if this is a "exports private" directive.
+     * @return true if this is a "exports private" directive
+     */
+    boolean isPrivate();
+
+    /**
      * Returns the name of the package to be exported.
      * @return  the name of the package to be exported
      */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java	Tue Aug 23 17:12:21 2016 -0700
@@ -76,7 +76,8 @@
 
     /** Flags for ExportsDirective. */
     public enum ExportsFlag {
-        DYNAMIC_PHASE(0x0040);
+        DYNAMIC_PHASE(0x0040),
+        PRIVATE_REFLECTION(0x0080);
 
         // overkill? move to ClassWriter?
         public static int value(Set<ExportsFlag> s) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Tue Aug 23 17:12:21 2016 -0700
@@ -655,8 +655,13 @@
             }
 
             if (toModules == null || !toModules.isEmpty()) {
-                Set<ExportsFlag> flags = tree.isDynamicPhase
-                        ? EnumSet.of(ExportsFlag.DYNAMIC_PHASE) : Collections.emptySet();
+                Set<ExportsFlag> flags = EnumSet.noneOf(ExportsFlag.class);
+                if (tree.isDynamicPhase) {
+                    flags.add(ExportsFlag.DYNAMIC_PHASE);
+                }
+                if (tree.isPrivate) {
+                    flags.add(ExportsFlag.PRIVATE_REFLECTION);
+                }
                 ExportsDirective d = new ExportsDirective(packge, toModules, flags);
                 tree.directive = d;
                 sym.exports = sym.exports.prepend(d);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue Aug 23 17:12:21 2016 -0700
@@ -3221,7 +3221,7 @@
                                 if (t1.kind == SEMI || t1.kind == DOT) {
                                     break loop;
                                 }
-                                if (isPublic || isTransitive) {
+                                if (isPublic) { // temporary
                                     error(token.pos, "repeated.modifier");
                                 }
                                 isTransitive = true;
@@ -3252,18 +3252,31 @@
             } else if (token.name() == names.exports) {
                 nextToken();
                 boolean isDynamicPhase = false;
-                if (token.kind == IDENTIFIER && token.name() == names.dynamic) {
-                    // lookahead to see if dynamic is followed by a package name
-                    // (or if the token is itself the beginning of a package name)
-                    Token t1 = S.token(1);
-                    Token t2 = S.token(2);
-                    if (t1.kind == IDENTIFIER
-                            && (t2.kind == SEMI
-                                || t2.kind == DOT
-                                || t2.kind == IDENTIFIER && t2.name() == names.to)) {
-                        isDynamicPhase = true;
-                        nextToken();
+                boolean isPrivate = false;
+            loop:
+                while (true) {
+                    switch (token.kind) {
+                        case IDENTIFIER:
+                            if (token.name() == names.dynamic && !isDynamicPhase) {
+                                Token t1 = S.token(1);
+                                if (t1.kind == SEMI || t1.kind == DOT) {
+                                    break loop;
+                                }
+                                isDynamicPhase = true;
+                                break;
+                            } else {
+                                break loop;
+                            }
+                        case PRIVATE:
+                            if (isPrivate) {
+                                error(token.pos, "repeated.modifier");
+                            }
+                            isPrivate = true;
+                            break;
+                        default:
+                            break loop;
                     }
+                    nextToken();
                 }
                 JCExpression pkgName = qualident(false);
                 List<JCExpression> moduleNames = null;
@@ -3272,7 +3285,7 @@
                     moduleNames = qualidentList(false);
                 }
                 accept(SEMI);
-                defs.append(toP(F.at(pos).Exports(pkgName, isDynamicPhase, moduleNames)));
+                defs.append(toP(F.at(pos).Exports(pkgName, isDynamicPhase, isPrivate, moduleNames)));
             } else if (token.name() == names.provides) {
                 nextToken();
                 JCExpression serviceName = qualident(false);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Aug 23 17:12:21 2016 -0700
@@ -2678,12 +2678,14 @@
             implements ExportsTree {
         public JCExpression qualid;
         public boolean isDynamicPhase;
+        public boolean isPrivate;
         public List<JCExpression> moduleNames;
         public ExportsDirective directive;
 
-        protected JCExports(JCExpression qualId, boolean isDynamicPhase, List<JCExpression> moduleNames) {
+        protected JCExports(JCExpression qualId, boolean isDynamicPhase, boolean isPrivate, List<JCExpression> moduleNames) {
             this.qualid = qualId;
             this.isDynamicPhase = isDynamicPhase;
+            this.isPrivate = isPrivate;
             this.moduleNames = moduleNames;
         }
 
@@ -2691,6 +2693,16 @@
         public void accept(Visitor v) { v.visitExports(this); }
 
         @Override @DefinedBy(Api.COMPILER_TREE)
+        public boolean isDynamic() {
+            return isDynamicPhase;
+        }
+
+        @Override @DefinedBy(Api.COMPILER_TREE)
+        public boolean isPrivate() {
+            return isPrivate;
+        }
+
+        @Override @DefinedBy(Api.COMPILER_TREE)
         public Kind getKind() {
             return Kind.EXPORTS;
         }
@@ -2973,7 +2985,7 @@
         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
         JCErroneous Erroneous(List<? extends JCTree> errs);
         JCModuleDecl ModuleDef(List<JCAnnotation> annotations, JCExpression qualId, List<JCDirective> directives);
-        JCExports Exports(JCExpression qualId, boolean isDynamicPhase, List<JCExpression> moduleNames);
+        JCExports Exports(JCExpression qualId, boolean isDynamicPhase, boolean isPrivate, List<JCExpression> moduleNames);
         JCProvides Provides(JCExpression serviceName, JCExpression implName);
         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
         JCUses Uses(JCExpression qualId);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Tue Aug 23 17:12:21 2016 -0700
@@ -519,7 +519,7 @@
         JCExports t = (JCExports) node;
         JCExpression qualId = copy(t.qualid, p);
         List<JCExpression> moduleNames = copy(t.moduleNames, p);
-        return M.at(t.pos).Exports(qualId, t.isDynamicPhase, moduleNames);
+        return M.at(t.pos).Exports(qualId, t.isDynamicPhase, t.isPrivate, moduleNames);
     }
 
     @Override @DefinedBy(Api.COMPILER_TREE)
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Aug 23 17:12:21 2016 -0700
@@ -545,8 +545,8 @@
     }
 
     @Override
-    public JCExports Exports(JCExpression qualId, boolean isDynamicPhase, List<JCExpression> moduleNames) {
-        JCExports tree = new JCExports(qualId, isDynamicPhase, moduleNames);
+    public JCExports Exports(JCExpression qualId, boolean isDynamicPhase, boolean isPrivate, List<JCExpression> moduleNames) {
+        JCExports tree = new JCExports(qualId, isDynamicPhase, isPrivate, moduleNames);
         tree.pos = pos;
         return tree;
     }
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java	Tue Aug 23 17:12:21 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -36,11 +36,12 @@
  *  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_DYNAMIC_PHASE =   0x40;
-    public static final int ACC_SYNTHETIC     = 0x1000;
-    public static final int ACC_MANDATED      = 0x8000;
+    public static final int ACC_TRANSITIVE          =   0x10;
+    public static final int ACC_STATIC_PHASE        =   0x20;
+    public static final int ACC_DYNAMIC_PHASE       =   0x40;
+    public static final int ACC_PRIVATE_REFLECTION  =   0x80;
+    public static final int ACC_SYNTHETIC           = 0x1000;
+    public static final int ACC_MANDATED            = 0x8000;
 
     Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
         super(name_index, length);
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Aug 23 17:12:21 2016 -0700
@@ -543,6 +543,8 @@
             print("// " + constantWriter.stringValue(e.exports_index));
             if ((e.exports_flags & Module_attribute.ACC_DYNAMIC_PHASE) != 0)
                 print(" ACC_DYNAMIC_PHASE");
+            if ((e.exports_flags & Module_attribute.ACC_PRIVATE_REFLECTION) != 0)
+                print(" ACC_PRIVATE_REFLECTION");
             if (e.exports_to_index.length == 0) {
                 println();
             } else {
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java	Tue Aug 23 14:27:33 2016 -0700
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java	Tue Aug 23 17:12:21 2016 -0700
@@ -555,20 +555,23 @@
         Module_attribute m = (Module_attribute) attr;
         for (Module_attribute.RequiresEntry entry: m.requires) {
             print("requires");
-            if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
-                print(" public");
             if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0)
                 print(" static");
+            if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
+                print(" transitive");
             print(" ");
             print(getUTF8Value(entry.requires_index).replace('/', '.'));
             println(";");
         }
 
         for (Module_attribute.ExportsEntry entry: m.exports) {
-            print("exports ");
-            print(getUTF8Value(entry.exports_index).replace('/', '.'));
+            print("exports");
             if ((entry.exports_flags & Module_attribute.ACC_DYNAMIC_PHASE) != 0)
                 print(" dynamic");
+            if ((entry.exports_flags & Module_attribute.ACC_PRIVATE_REFLECTION) != 0)
+                print(" private");
+            print(" ");
+            print(getUTF8Value(entry.exports_index).replace('/', '.'));
             boolean first = true;
             for (int i: entry.exports_to_index) {
                 String mname;