changeset 52769:8c442a53c552 amber-demo

manual merge with concise methods branch
author vromero
date Mon, 08 Oct 2018 10:50:59 -0700
parents 100f5811cd57 32f06d86416e
children b6dea1885221
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
diffstat 5 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Sun Oct 07 10:35:51 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Mon Oct 08 10:50:59 2018 -0700
@@ -331,9 +331,14 @@
     public static final long MATCH_BINDING = 1L<<59;
 
     /**
-     * Flag for concise methods
+     * Flag for concise methods `=`
      */
-    public static final long CONCISE = 1L<<60;
+    public static final long CONCISE_EQUAL = 1L<<60;
+
+    /**
+     * Flag for concise methods `->`
+     */
+    public static final long CONCISE_ARROW = 1L<<61;
 
     /** Modifier masks.
      */
@@ -456,7 +461,8 @@
         ANONCONSTR_BASED(Flags.ANONCONSTR_BASED),
         MATCH_BINDING(Flags.MATCH_BINDING),
         RECORD(Flags.RECORD),
-        CONCISE(Flags.CONCISE);
+        CONCISE_EQUAL(Flags.CONCISE_EQUAL),
+        CONCISE_ARROW(Flags.CONCISE_ARROW);
 
         Flag(long flag) {
             this.value = flag;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Oct 07 10:35:51 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Mon Oct 08 10:50:59 2018 -0700
@@ -425,6 +425,12 @@
         return name.isEmpty();
     }
 
+    /** Are we dealing with a concise method?
+     */
+    public boolean isConciseMethod() {
+        return (flags() & CONCISE_ARROW) != 0 || (flags() & CONCISE_EQUAL) != 0;
+    }
+
     /** Is this symbol a constructor?
      */
     public boolean isConstructor() {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Oct 07 10:35:51 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Oct 08 10:50:59 2018 -0700
@@ -1092,7 +1092,9 @@
                 }
             } else if ((tree.mods.flags & NATIVE) != 0) {
                 log.error(tree.pos(), Errors.NativeMethCantHaveBody);
-            } else if ((tree.mods.flags & CONCISE) != 0 && tree.name == names.init) {
+            } else if (((tree.mods.flags & CONCISE_ARROW) != 0 ||
+                    (tree.mods.flags & CONCISE_EQUAL) != 0) &&
+                    tree.name == names.init) {
                 log.error(tree.pos(), Errors.ConstructorsCantHaveConciseBody);
             } else {
                 // Add an implicit super() call unless an explicit call to
@@ -1218,6 +1220,13 @@
                 }
             }
             result = tree.type = v.type;
+            if (env.info.scope.owner.kind == MTH && (env.info.scope.owner.flags() & Flags.CONCISE_EQUAL) != 0) {
+                // remove from the scope so that the arguments can't be used inside the concise method
+                WriteableScope enclScope = enter.enterScope(env);
+                if (enclScope != null) {
+                    enclScope.remove(tree.sym);
+                }
+            }
         }
         finally {
             chk.setLint(prevLint);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sun Oct 07 10:35:51 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Oct 08 10:50:59 2018 -0700
@@ -4178,7 +4178,7 @@
                     conciseMethodRef = expr;
                     body = F.at(bodyPos).Block(0, List.nil());
                 }
-                mods.flags |= Flags.CONCISE;
+                mods.flags |= arrowForm ? Flags.CONCISE_ARROW : Flags.CONCISE_EQUAL;
                 body.endpos = token.pos;
             } else {
                 if (token.kind == DEFAULT) {
--- a/test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.out	Sun Oct 07 10:35:51 2018 -0700
+++ b/test/langtools/tools/javac/concise_methods/ConciseMethodsNegTest01.out	Mon Oct 08 10:50:59 2018 -0700
@@ -1,5 +1,5 @@
 ConciseMethodsNegTest01.java:7:1: compiler.err.does.not.override.abstract: ConciseMethodsNegTest01, length2(java.lang.String), ConciseMethodsNegTest01
-ConciseMethodsNegTest01.java:8:28: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, length, compiler.misc.no.args, java.lang.String, kindname.class, java.lang.String, (compiler.misc.arg.length.mismatch)))
+ConciseMethodsNegTest01.java:8:28: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, ConciseMethodsNegTest01, null)
 ConciseMethodsNegTest01.java:10:18: compiler.err.abstract.meth.cant.have.body
 ConciseMethodsNegTest01.java:12:16: compiler.err.native.meth.cant.have.body
 ConciseMethodsNegTest01.java:18:5: compiler.err.constructors.cant.have.concise.body