Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2018-12-17 01:57:04 -0500
committerManoj Palat2018-12-17 01:57:04 -0500
commit017075321ccc7c722968d2edb6391c64c46bb8c4 (patch)
tree4eda962bb771d298fa4dd0af142aec007c48e734
parent0b3843b4928b0f164072e55bdcd78aa26029a126 (diff)
downloadeclipse.jdt.core-Y20190102-2200.tar.gz
eclipse.jdt.core-Y20190102-2200.tar.xz
eclipse.jdt.core-Y20190102-2200.zip
Bug 531714 - switch expression - re-enabling the enable-preview flagY20190102-2200Y20181226-2200Y20181219-2200manoj_switch_expr_531714
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java101
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java28
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties4
5 files changed, 136 insertions, 9 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 9a1aee407f..4421c293e8 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
@@ -45,6 +45,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12); // FIXME
defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
return defaultOptions;
}
@@ -257,6 +258,102 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
},
"100");
}
+ public void testBug531714_008() {
+ Map<String, String> disablePreviewOptions = getCompilerOptions();
+ disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Switch expression is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case 0 -> i * 0;\n" +
+ " ^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 5)\n" +
+ " case 1 -> 2;\n" +
+ " ^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 6)\n" +
+ " default -> 3;\n" +
+ " ^^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n";
-}
- \ No newline at end of file
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ disablePreviewOptions);
+ }
+ public void testBug531714_009() {
+ Map<String, String> disablePreviewOptions = getCompilerOptions();
+ disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 0 -> i * 0;\n" +
+ " ^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " case 1 -> 2;\n" +
+ " ^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 6)\n" +
+ " default -> 3;\n" +
+ " ^^^^^^^\n" +
+ "Switch Case Label with \'->\' is a preview feature; use --enable-preview at source level 12 or above to enable\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ disablePreviewOptions);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 74d784f409..2facfe95eb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -2099,12 +2099,16 @@ void setSourceStart(int sourceStart);
/** @since 3.16 BETA_JAVA_12 */
int SwitchExpressionTrailingSwitchLabels = Internal + 1605;
/** @since 3.16 BETA_JAVA_12 */
- int MixedCase = Syntax + 1606;
+ int switchMixedCase = Syntax + 1606;
/** @since 3.16 BETA_JAVA_12 */
int SwitchExpressionMissingDefaultCase = Internal + 1607;
/** @since 3.16 BETA_JAVA_12 */
int SwitchExpressionNotBelow12 = Internal + Syntax + 1608;
/** @since 3.16 BETA_JAVA_12 */
int SwitchCaseLabelWithArrowNotBelow12 = Internal + Syntax + 1609;
+ /** @since 3.16 BETA_JAVA_12 */
+ int SwitchExpressionPreviewDisabled = Internal + Syntax + 1610;
+ /** @since 3.16 BETA_JAVA_12 */
+ int SwitchCaseLabelWithArrowPreviewDisabled = Internal + Syntax + 1611;
}
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 52cdb5fe6f..ef860fe7ef 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
@@ -9493,6 +9493,8 @@ protected void consumeCaseLabelExpr() {
CaseStatement caseStatement = (CaseStatement) this.astStack[this.astPtr];
if (!this.parsingJava12Plus) {
problemReporter().caseStatementWithArrowNotBelow12(caseStatement);
+ } else if (!this.options.enablePreviewFeatures){
+ problemReporter().caseStatementWithArrowIsPreview(caseStatement);
}
caseStatement.isExpr = true;
}
@@ -9502,6 +9504,8 @@ protected void consumeDefaultLabelExpr() {
CaseStatement defaultStatement = (CaseStatement) this.astStack[this.astPtr];
if (!this.parsingJava12Plus) {
problemReporter().caseStatementWithArrowNotBelow12(defaultStatement);
+ } else if (!this.options.enablePreviewFeatures){
+ problemReporter().caseStatementWithArrowIsPreview(defaultStatement);
}
defaultStatement.isExpr = true;
}
@@ -9513,6 +9517,8 @@ protected void consumeSwitchExpression() {
if (!this.parsingJava12Plus) {
problemReporter().switchExpressionsNotBelow12(s);
+ } else if (!this.options.enablePreviewFeatures) {
+ problemReporter().switchExpressionIsPreview(s);
}
pushOnExpressionStack(s);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index cff7a7cf77..291bde5985 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -11072,7 +11072,7 @@ public void switchExpressionTrailingSwitchLabels(Statement stmt) {
}
public void switchExpressionMixedCase(ASTNode statement) {
this.handle(
- IProblem.MixedCase,
+ IProblem.switchMixedCase,
NoArgument,
NoArgument,
statement.sourceStart,
@@ -11080,11 +11080,11 @@ public void switchExpressionMixedCase(ASTNode statement) {
}
public void switchExpressionsNotBelow12(SwitchExpression switchExpr) {
this.handle(
- IProblem.SwitchExpressionNotBelow12,
- NoArgument,
- NoArgument,
- switchExpr.sourceStart,
- switchExpr.sourceEnd);
+ IProblem.SwitchExpressionNotBelow12,
+ NoArgument,
+ NoArgument,
+ switchExpr.sourceStart,
+ switchExpr.sourceEnd);
}
public void caseStatementWithArrowNotBelow12(CaseStatement caseStatement) {
this.handle(
@@ -11094,4 +11094,20 @@ public void caseStatementWithArrowNotBelow12(CaseStatement caseStatement) {
caseStatement.sourceStart,
caseStatement.sourceEnd);
}
+public void switchExpressionIsPreview(SwitchExpression switchExpr) {
+ this.handle(
+ IProblem.SwitchExpressionPreviewDisabled,
+ NoArgument,
+ NoArgument,
+ switchExpr.sourceStart,
+ switchExpr.sourceEnd);
+}
+public void caseStatementWithArrowIsPreview(CaseStatement caseStatement) {
+ this.handle(
+ IProblem.SwitchCaseLabelWithArrowPreviewDisabled,
+ NoArgument,
+ NoArgument,
+ caseStatement.sourceStart,
+ caseStatement.sourceEnd);
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 8f04e6efa6..c0c262fc86 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -983,6 +983,10 @@
1607 = A switch expression should have a default case
1608 = Switch expressions are allowed only at source level 12 or above
1609 = Switch Case Labels with '->' are allowed only at source level 12 or above
+1608 = Switch expressions are allowed only at source level 12 or above
+1609 = Switch Case Labels with '->' are allowed only at source level 12 or above
+1610 = Switch expression is a preview feature; use --enable-preview at source level 12 or above to enable
+1611 = Switch Case Label with '->' is a preview feature; use --enable-preview at source level 12 or above to enable
### ELABORATIONS

Back to the top