Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-08-23 05:46:01 -0400
committerManoj Palat2019-08-25 22:33:40 -0400
commitd2bc269c6942d63976845d0ab022d196f8cb7b82 (patch)
treeca93bc96ad2b0180f1287b041688967c5eab9687
parent79cab6fa86097b5ff3934e826a8ee689820e2eb1 (diff)
downloadeclipse.jdt.core-I20190826-1800.tar.gz
eclipse.jdt.core-I20190826-1800.tar.xz
eclipse.jdt.core-I20190826-1800.zip
Bug 548476 - withdraw Java12-preview-version of switch expr - additionalI20190826-1800I20190826-0640I20190826-0415
failures Change-Id: I6ae66d1082667577806c27b5ad2de49fc1fcf994 Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java99
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java11
4 files changed, 109 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
index adace073f9..fc14e13d23 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -24,7 +24,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
static {
// TESTS_NUMBERS = new int [] { 40 };
-// TESTS_NAMES = new String[] { "testBug543240_1" };
+// TESTS_NAMES = new String[] { "testBug548476" };
}
public static Class<?> testClass() {
@@ -2475,4 +2475,101 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"Duplicate case\n" +
"----------\n");
}
+ public void testBug548476_01() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n" +
+ " I expr = () -> break;\n" +
+ "}\n" +
+ "\n" +
+ "interface I {\n" +
+ " void foo();\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " I expr = () -> break;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", invalid LambdaBody\n" +
+ "----------\n");
+ }
+ public void testBug548476_02() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n" +
+ " void break () {}\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " void break () {}\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", Identifier expected\n" +
+ "----------\n");
+ }
+ public void testBug548476_03() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n" +
+ "}\n" +
+ "\n" +
+ "class break{}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " class break{}\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", Identifier expected\n" +
+ "----------\n");
+ }
+ public void testBug548476_04() {
+ this.runNegativeTest(
+ new String[] {
+ "module-info.java",
+ "module break.me {\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in module-info.java (at line 1)\n" +
+ " module break.me {\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", Identifier expected\n" +
+ "----------\n");
+ }
+ public void testBug548476_05() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X {\n"+
+ " public static void foo(int i) {\n"+
+ " int v = switch (i) {\n"+
+ " case 0 -> {\n"+
+ " I k = () -> break;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " I k = () -> break;\n"+
+ " break 0;\n"+
+ " }\n"+
+ " };\n"+
+ " }\n"+
+ "}\n"+
+ "interface I {\n"+
+ " void foo();\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " I k = () -> break;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", invalid LambdaBody\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " I k = () -> break;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", invalid LambdaBody\n" +
+ "----------\n");
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
index 48e9181580..17754814ab 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
@@ -300,9 +300,7 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
buf.append(" int z = 100;\n");
buf.append(" break z;\n");
buf.append(" }\n");
- buf.append(" case 100, 200 -> {\n");
- buf.append(" break 2048;\n");
- buf.append("}\n");
+ buf.append(" case 100, 200 -> {break 2048;}\n");
buf.append(" default -> {\n");
buf.append(" break 12;\n");
buf.append(" }\n");
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 924d78fc27..f930920dbb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -9308,7 +9308,7 @@ private void createSwitchStatementOrExpression(boolean isStmt) {
//if some declaration occurs.
this.nestedType--;
this.switchNestingLevel--;
-
+ this.scanner.breakPreviewAllowed = this.switchNestingLevel > 0;
int length;
SwitchStatement switchStatement = isStmt ? new SwitchStatement() : new SwitchExpression();
this.expressionLengthPtr--;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
index a4e2bed8f4..883f9385ca 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
@@ -108,6 +108,7 @@ public class Scanner implements TerminalTokens {
public boolean fakeInModule = false;
boolean inCase = false;
+ boolean breakPreviewAllowed = false;
/**
* The current context of the scanner w.r.t restricted keywords
*
@@ -1166,8 +1167,10 @@ public void ungetToken(int unambiguousToken) {
this.nextToken = unambiguousToken;
}
private void updateCase(int token) {
- if (token == TokenNamecase)
+ if (token == TokenNamecase) {
this.inCase = true;
+ this.breakPreviewAllowed = true;
+ }
if (token == TokenNameCOLON || token == TokenNameARROW)
this.inCase = false;
}
@@ -4692,6 +4695,9 @@ private VanguardParser getVanguardParser() {
this.vanguardScanner.resetTo(this.startPosition, this.eofPosition - 1, isInModuleDeclaration(), this.scanContext);
return this.vanguardParser;
}
+protected final boolean mayBeAtBreakPreview() {
+ return this.breakPreviewAllowed && this.lookBack[1] != TokenNameARROW;
+}
protected final boolean maybeAtLambdaOrCast() { // Could the '(' we saw just now herald a lambda parameter list or a cast expression ? (the possible locations for both are identical.)
@@ -4838,7 +4844,8 @@ int disambiguatedRestrictedKeyword(int restrictedKeywordToken) {
}
int disambiguatedToken(int token) {
final VanguardParser parser = getVanguardParser();
- if (token == TokenNamebreak && this.sourceLevel == ClassFileConstants.JDK12 && this.previewEnabled) {
+ if (token == TokenNamebreak && this.sourceLevel == ClassFileConstants.JDK12 &&
+ this.previewEnabled && mayBeAtBreakPreview()) {
this.nextToken = TokenNameBreakPreviewMarker;
return token;
} else if (token == TokenNameARROW && this.inCase) {

Back to the top