test/langtools/tools/javac/lambda/LambdaParserTest.java
changeset 48935 03ae177c26b0
parent 48926 02404e27d356
child 52016 9ea22a0f9540
--- a/test/langtools/tools/javac/lambda/LambdaParserTest.java	Thu Feb 22 12:26:01 2018 -0800
+++ b/test/langtools/tools/javac/lambda/LambdaParserTest.java	Thu Feb 22 15:49:32 2018 -0500
@@ -40,6 +40,7 @@
  */
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import combo.ComboInstance;
 import combo.ComboParameter;
@@ -105,26 +106,44 @@
         }
     }
 
+    enum SourceKind {
+        SOURCE_9("9"),
+        SOURCE_10("10");
+
+        String sourceNumber;
+
+        SourceKind(String sourceNumber) {
+            this.sourceNumber = sourceNumber;
+        }
+    }
+
     enum LambdaParameterKind implements ComboParameter {
-        IMPLICIT(""),
-        EXPLIICT_SIMPLE("A"),
-        EXPLIICT_SIMPLE_ARR1("A[]"),
-        EXPLIICT_SIMPLE_ARR2("A[][]"),
-        EXPLICIT_VARARGS("A..."),
-        EXPLICIT_GENERIC1("A<X>"),
-        EXPLICIT_GENERIC2("A<? extends X, ? super Y>"),
-        EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>..."),
-        EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]"),
-        EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]");
+
+        IMPLICIT_1("", ExplicitKind.IMPLICIT),
+        IMPLICIT_2("var", ExplicitKind.IMPLICIT_VAR),
+        EXPLIICT_SIMPLE("A", ExplicitKind.EXPLICIT),
+        EXPLIICT_SIMPLE_ARR1("A[]", ExplicitKind.EXPLICIT),
+        EXPLIICT_SIMPLE_ARR2("A[][]", ExplicitKind.EXPLICIT),
+        EXPLICIT_VARARGS("A...", ExplicitKind.EXPLICIT),
+        EXPLICIT_GENERIC1("A<X>", ExplicitKind.EXPLICIT),
+        EXPLICIT_GENERIC2("A<? extends X, ? super Y>", ExplicitKind.EXPLICIT),
+        EXPLICIT_GENERIC2_VARARGS("A<? extends X, ? super Y>...", ExplicitKind.EXPLICIT),
+        EXPLICIT_GENERIC2_ARR1("A<? extends X, ? super Y>[]", ExplicitKind.EXPLICIT),
+        EXPLICIT_GENERIC2_ARR2("A<? extends X, ? super Y>[][]", ExplicitKind.EXPLICIT);
+
+        enum ExplicitKind {
+            IMPLICIT,
+            IMPLICIT_VAR,
+            EXPLICIT;
+        }
 
         String parameterType;
+        ExplicitKind explicitKind;
 
-        LambdaParameterKind(String parameterType) {
+
+        LambdaParameterKind(String parameterType, ExplicitKind ekind) {
             this.parameterType = parameterType;
-        }
-
-        boolean explicit() {
-            return this != IMPLICIT;
+            this.explicitKind = ekind;
         }
 
         boolean isVarargs() {
@@ -136,12 +155,23 @@
         public String expand(String optParameter) {
             return parameterType;
         }
+
+        ExplicitKind explicitKind(SourceKind sk) {
+            switch (explicitKind) {
+                case IMPLICIT_VAR:
+                    return (sk == SourceKind.SOURCE_9) ?
+                            ExplicitKind.EXPLICIT : ExplicitKind.IMPLICIT_VAR;
+                default:
+                    return explicitKind;
+            }
+        }
     }
 
     enum ModifierKind implements ComboParameter {
         NONE(""),
         FINAL("final"),
-        PUBLIC("public");
+        PUBLIC("public"),
+        ANNO("@A");
 
         String modifier;
 
@@ -152,7 +182,8 @@
         boolean compatibleWith(LambdaParameterKind pk) {
             switch (this) {
                 case PUBLIC: return false;
-                case FINAL: return pk != LambdaParameterKind.IMPLICIT;
+                case ANNO:
+                case FINAL: return pk != LambdaParameterKind.IMPLICIT_1;
                 case NONE: return true;
                 default: throw new AssertionError("Invalid modifier kind " + this);
             }
@@ -208,6 +239,7 @@
         new ComboTestHelper<LambdaParserTest>()
                 .withFilter(LambdaParserTest::redundantTestFilter)
                 .withFilter(LambdaParserTest::badImplicitFilter)
+                .withDimension("SOURCE", (x, sk) -> x.sk = sk, SourceKind.values())
                 .withDimension("LAMBDA", (x, lk) -> x.lk = lk, LambdaKind.values())
                 .withDimension("NAME", (x, name) -> x.pn = name, LambdaParameterName.values())
                 .withArrayDimension("TYPE", (x, type, idx) -> x.pks[idx] = type, 2, LambdaParameterKind.values())
@@ -221,6 +253,7 @@
     ModifierKind[] mks = new ModifierKind[2];
     LambdaKind lk;
     LambdaParameterName pn;
+    SourceKind sk;
 
     boolean badImplicitFilter() {
         return !(mks[0] != ModifierKind.NONE && lk.isShort());
@@ -240,13 +273,15 @@
         return true;
     }
 
-    String template = "class Test {\n" +
-                      "   SAM s = #{EXPR};\n" +
-                      "}";
+    String template = "@interface A { }\n" +
+            "class Test {\n" +
+            "   SAM s = #{EXPR};\n" +
+            "}";
 
     @Override
     public void doWork() throws IOException {
         newCompilationTask()
+                .withOptions(Arrays.asList("-source", sk.sourceNumber))
                 .withSourceFromTemplate(template)
                 .parse(this::check);
     }
@@ -256,7 +291,7 @@
                 (lk.arity() > 1 && !mks[1].compatibleWith(pks[1]));
 
         if (lk.arity() == 2 &&
-                (pks[0].explicit() != pks[1].explicit() ||
+                (pks[0].explicitKind(sk) != pks[1].explicitKind(sk) ||
                 pks[0].isVarargs())) {
             errorExpected = true;
         }