Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2018-12-08 05:01:03 +0000
committerManoj Palat2018-12-08 05:01:03 +0000
commitd5f022410c69192070d6fc634d40c75bfe8a1868 (patch)
treeaf43b889a5044012dc460b90c7bc826dc2fb7bb4 /org.eclipse.jdt.core/compiler/org
parent4da3e82a5a60fbea2c307d42387915f0ca6bb5e5 (diff)
downloadeclipse.jdt.core-d5f022410c69192070d6fc634d40c75bfe8a1868.tar.gz
eclipse.jdt.core-d5f022410c69192070d6fc634d40c75bfe8a1868.tar.xz
eclipse.jdt.core-d5f022410c69192070d6fc634d40c75bfe8a1868.zip
Flag errors for pre-12 usage of 12 constructs
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java1
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java19
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java24
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties7
6 files changed, 63 insertions, 7 deletions
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 ddc18aa429..aa75d5bf73 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
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* IBM Corporation - added the following constants
@@ -2092,4 +2096,9 @@ void setSourceStart(int sourceStart);
int MixedCase = 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;
+
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
index 86940e68dd..2e80089e63 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contributions for
@@ -624,12 +628,12 @@ public class SwitchStatement extends Expression {
boolean isExpr = this.switchLabeledRules = this.cases[0].isExpr;
for (int i = 1, l = this.caseCount; i < l; ++i) {
if (this.cases[i].isExpr != isExpr) {
- this.scope.problemReporter().mixedCase(this.cases[i]);
+ this.scope.problemReporter().switchExpressionMixedCase(this.cases[i]);
return;
}
}
if (this.defaultCase != null && this.defaultCase.isExpr != isExpr) {
- this.scope.problemReporter().mixedCase(this.defaultCase);
+ this.scope.problemReporter().switchExpressionMixedCase(this.defaultCase);
}
}
private void reportDuplicateCase(final CaseStatement duplicate, final CaseStatement original, int length) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
index 422d230f8a..8093adc10c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
@@ -157,6 +157,7 @@ public interface ClassFileConstants {
long JDK9 = ((long)ClassFileConstants.MAJOR_VERSION_9 << 16) + ClassFileConstants.MINOR_VERSION_0;
long JDK10 = ((long)ClassFileConstants.MAJOR_VERSION_10 << 16) + ClassFileConstants.MINOR_VERSION_0;
long JDK11 = ((long)ClassFileConstants.MAJOR_VERSION_11 << 16) + ClassFileConstants.MINOR_VERSION_0;
+ long JDK12 = ((long)ClassFileConstants.MAJOR_VERSION_12 << 16) + ClassFileConstants.MINOR_VERSION_0;
public static long getLatestJDKLevel() {
return ((long)ClassFileConstants.MAJOR_LATEST_VERSION << 16) + ClassFileConstants.MINOR_VERSION_0;
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 db2ff70c3d..52cdb5fe6f 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
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Tromey - patch for readTable(String) as described in http://bugs.eclipse.org/bugs/show_bug.cgi?id=32196
@@ -941,6 +945,7 @@ protected int valueLambdaNestDepth = -1;
private int stateStackLengthStack[] = new int[0];
protected boolean parsingJava8Plus;
protected boolean parsingJava9Plus;
+protected boolean parsingJava12Plus;
protected int unstackedAct = ERROR_ACTION;
private boolean haltOnSyntaxError = false;
private boolean tolerateDefaultClassMethods = false;
@@ -959,6 +964,7 @@ public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) {
initializeScanner();
this.parsingJava8Plus = this.options.sourceLevel >= ClassFileConstants.JDK1_8;
this.parsingJava9Plus = this.options.sourceLevel >= ClassFileConstants.JDK9;
+ this.parsingJava12Plus = this.options.sourceLevel >= ClassFileConstants.JDK12;
this.astLengthStack = new int[50];
this.expressionLengthStack = new int[30];
this.typeAnnotationLengthStack = new int[30];
@@ -9485,12 +9491,18 @@ protected void consumeCaseLabelExpr() {
// SwitchLabelExpr ::= SwitchLabelCaseLhs BeginCaseExpr '->'
consumeCaseLabel();
CaseStatement caseStatement = (CaseStatement) this.astStack[this.astPtr];
+ if (!this.parsingJava12Plus) {
+ problemReporter().caseStatementWithArrowNotBelow12(caseStatement);
+ }
caseStatement.isExpr = true;
}
protected void consumeDefaultLabelExpr() {
// SwitchLabelDefaultExpr ::= 'default' '->'
consumeDefaultLabel();
CaseStatement defaultStatement = (CaseStatement) this.astStack[this.astPtr];
+ if (!this.parsingJava12Plus) {
+ problemReporter().caseStatementWithArrowNotBelow12(defaultStatement);
+ }
defaultStatement.isExpr = true;
}
protected void consumeSwitchExpression() {
@@ -9498,6 +9510,11 @@ protected void consumeSwitchExpression() {
createSwitchStatementOrExpression(false);
if (this.astLengthStack[this.astLengthPtr--] != 0) {
SwitchExpression s = (SwitchExpression) this.astStack[this.astPtr--];
+
+ if (!this.parsingJava12Plus) {
+ problemReporter().switchExpressionsNotBelow12(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 9e4be30c9b..366c8f146e 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
@@ -7,7 +7,11 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Benjamin Muskalla - Contribution for bug 239066
@@ -11038,7 +11042,7 @@ public void switchExpressionTrailingSwitchLabels(Statement stmt) {
stmt.sourceStart,
stmt.sourceEnd);
}
-public void mixedCase(ASTNode statement) {
+public void switchExpressionMixedCase(ASTNode statement) {
this.handle(
IProblem.MixedCase,
NoArgument,
@@ -11046,4 +11050,20 @@ public void mixedCase(ASTNode statement) {
statement.sourceStart,
statement.sourceEnd);
}
+public void switchExpressionsNotBelow12(SwitchExpression switchExpr) {
+ this.handle(
+ IProblem.SwitchExpressionNotBelow12,
+ NoArgument,
+ NoArgument,
+ switchExpr.sourceStart,
+ switchExpr.sourceEnd);
+}
+public void caseStatementWithArrowNotBelow12(CaseStatement caseStatement) {
+ this.handle(
+ IProblem.SwitchCaseLabelWithArrowNotBelow12,
+ 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 696807cebb..74c9bcb8a8 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
@@ -7,7 +7,10 @@
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
-#
+#
+# This is an implementation of an early-draft specification developed under the Java
+# Community Process (JCP) and is made available for testing and evaluation purposes
+# only. The code is not compatible with any specification of the JCP.
#
# Contributors:
# IBM Corporation - initial API and implementation
@@ -975,6 +978,8 @@
1605 = Trailing switch labels are not allowed in a switch expression.
1606 = Mixing of different kinds of case statements '->' and ':' is not allowed within a switch
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
### ELABORATIONS

Back to the top