Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-03-19 06:41:15 -0400
committerJay Arthanareeswaran2019-03-19 12:51:18 -0400
commit2a8617c89c5e3d9080624481df4455c71bf1f04a (patch)
tree99d63c87e36268ed5c9cd726788d5668de53b763
parenta39326e536c471be4affbcc0e5abf7e3abd41b82 (diff)
downloadeclipse.jdt.core-2a8617c89c5e3d9080624481df4455c71bf1f04a.tar.gz
eclipse.jdt.core-2a8617c89c5e3d9080624481df4455c71bf1f04a.tar.xz
eclipse.jdt.core-2a8617c89c5e3d9080624481df4455c71bf1f04a.zip
Bug 545518 - [12] Flow analysis is skipped for multi-constant caseP20190319-2210
statement Change-Id: Ie669650b7742cad52b60cad6b1f508a420e8cf67 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java62
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java24
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java19
3 files changed, 100 insertions, 5 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 4432e80e53..0060cc8dd4 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
@@ -2304,4 +2304,66 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] { "--enable-preview"},
options);
}
+ public void testBug545518a() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String message =
+ "----------\n" +
+ "1. WARNING in X.java (at line 5)\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug545518b() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Multi constant case is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index cc7fc5fb1a..004768ede2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
@@ -3106,6 +3106,30 @@ public void testBug533475() {
"}\n"
});
}
+public void testBug545518() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8 || this.complianceLevel >= ClassFileConstants.JDK12)
+ return;
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 12 and above\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message);
+}
public static Class testClass() {
return SwitchTest.class;
}
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 73a13453b0..a63d6db510 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
@@ -2229,14 +2229,25 @@ protected void consumeCaseLabel() {
// TODO : ERROR
}
CaseStatement caseStatement = new CaseStatement(constantExpressions[0], constantExpressions[length - 1].sourceEnd, this.intStack[this.intPtr--]);
+ if (constantExpressions.length > 1) {
+ if (this.parsingJava12Plus) {
+ if (this.options.enablePreviewFeatures) {
+ if (this.options.isAnyEnabled(IrritantSet.PREVIEW) && constantExpressions.length > 1) {
+ problemReporter().previewFeatureUsed(caseStatement.sourceStart, caseStatement.sourceEnd);
+ }
+ } else {
+ problemReporter().previewFeatureNotEnabled(caseStatement.sourceStart, caseStatement.sourceEnd, "Multi constant case"); //$NON-NLS-1$
+ }
+ } else {
+ problemReporter().previewFeatureNotSupported(caseStatement.sourceStart, caseStatement.sourceEnd, "Multi constant case", CompilerOptions.VERSION_12); //$NON-NLS-1$
+ }
+ }
caseStatement.constantExpressions = constantExpressions;
// Look for $fall-through$ tag in leading comment for case statement
if (hasLeadingTagComment(FALL_THROUGH_TAG, caseStatement.sourceStart)) {
caseStatement.bits |= ASTNode.DocumentedFallthrough;
}
- if (this.options.sourceLevel <= ClassFileConstants.JDK12 && constantExpressions.length > 1) {
- problemReporter().previewFeatureUsed(caseStatement.sourceStart, caseStatement.sourceEnd);
- }
+
pushOnAstStack(caseStatement);
}
protected void consumeCastExpressionLL1() {
@@ -9529,7 +9540,6 @@ protected void consumeCaseLabelExpr() {
consumeCaseLabel();
CaseStatement caseStatement = (CaseStatement) this.astStack[this.astPtr];
if (!this.parsingJava12Plus) {
-// problemReporter().caseStatementWithArrowNotBelow12(caseStatement);
problemReporter().previewFeatureNotSupported(caseStatement.sourceStart, caseStatement.sourceEnd, "Case Labels with '->'", CompilerOptions.VERSION_12); //$NON-NLS-1$
} else if (!this.options.enablePreviewFeatures){
problemReporter().previewFeatureNotEnabled(caseStatement.sourceStart, caseStatement.sourceEnd, "Case Labels with '->'"); //$NON-NLS-1$
@@ -9545,7 +9555,6 @@ protected void consumeDefaultLabelExpr() {
consumeDefaultLabel();
CaseStatement defaultStatement = (CaseStatement) this.astStack[this.astPtr];
if (!this.parsingJava12Plus) {
-// problemReporter().caseStatementWithArrowNotBelow12(defaultStatement);
problemReporter().previewFeatureNotSupported(defaultStatement.sourceStart, defaultStatement.sourceEnd, "Case Labels with '->'", CompilerOptions.VERSION_12); //$NON-NLS-1$
} else if (!this.options.enablePreviewFeatures){
problemReporter().previewFeatureNotEnabled(defaultStatement.sourceStart, defaultStatement.sourceEnd, "Case Labels with '->'"); //$NON-NLS-1$

Back to the top