Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2019-02-07 12:42:34 +0000
committerSarika Sinha2019-02-07 12:42:34 +0000
commitf7b7264efd96a9b892819e046d340c8667b196d2 (patch)
treec2b5a639cc8d10700e8113430bdccee6f1d967aa
parentdf9c8b671968162a64690b6ba582d3f7c770decf (diff)
downloadeclipse.jdt.core-f7b7264efd96a9b892819e046d340c8667b196d2.tar.gz
eclipse.jdt.core-f7b7264efd96a9b892819e046d340c8667b196d2.tar.xz
eclipse.jdt.core-f7b7264efd96a9b892819e046d340c8667b196d2.zip
Bug 542558 - [12][dom ast] DOM AST Support for Switch Expressions
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java22
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java2
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java34
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java2
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java4
5 files changed, 38 insertions, 26 deletions
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index 22b150370c..bba5073cd1 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -1299,11 +1299,23 @@ class ASTConverter {
public SwitchCase convert(org.eclipse.jdt.internal.compiler.ast.CaseStatement statement) {
SwitchCase switchCase = new SwitchCase(this.ast);
- org.eclipse.jdt.internal.compiler.ast.Expression constantExpression = statement.constantExpression;
- if (constantExpression == null) {
- switchCase.setExpression(null);
- } else {
- switchCase.setExpression(convert(constantExpression));
+ if (this.ast.apiLevel >= AST.JLS12_INTERNAL) {
+ org.eclipse.jdt.internal.compiler.ast.Expression[] expressions = statement.constantExpressions;
+ if (expressions == null || expressions.length == 0) {
+ switchCase.getExpressions().clear();
+ } else {
+ for (org.eclipse.jdt.internal.compiler.ast.Expression expression : expressions) {
+ switchCase.getExpressions().add(convert(expression));
+ }
+ }
+ }
+ else {
+ org.eclipse.jdt.internal.compiler.ast.Expression constantExpression = statement.constantExpression;
+ if (constantExpression == null) {
+ switchCase.setExpression(null);
+ } else {
+ switchCase.setExpression(convert(constantExpression));
+ }
}
switchCase.setIsExpr(statement.isExpr);
switchCase.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
index 167141dd4c..55e2ed3680 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
@@ -2274,7 +2274,7 @@ public class ASTMatcher {
}
SwitchCase o = (SwitchCase) other;
return ( node.getAST().apiLevel >= AST.JLS12_INTERNAL
- ? safeSubtreeListMatch(node.getExpression2(), o.getExpression2())
+ ? safeSubtreeListMatch(node.getExpressions(), o.getExpressions())
: safeSubtreeMatch(node.getExpression(), o.getExpression()));
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java
index a11d668f73..011fe0d95c 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java
@@ -108,9 +108,7 @@ public class SwitchCase extends Statement {
private Expression optionalExpression = null;
/**
- * The expression; <code>null</code> for none; lazily initialized (but
- * does <b>not</b> default to none).
- * @see #expressionInitialized
+ * <code>true</code> indicates "->" and <code>false</code> indicates ":".
*/
private boolean isExpr = false;
@@ -118,7 +116,7 @@ public class SwitchCase extends Statement {
/**
* The expression; <code>empty</code> for none;
*/
- private ASTNode.NodeList expression = null;
+ private ASTNode.NodeList expressions = null;
/**
* Indicates whether <code>optionalExpression</code> has been initialized.
@@ -134,7 +132,7 @@ public class SwitchCase extends Statement {
SwitchCase(AST ast) {
super(ast);
if (ast.apiLevel >= AST.JLS12_INTERNAL) {
- this.expression = new ASTNode.NodeList(EXPRESSION_2_PROPERTY);
+ this.expressions = new ASTNode.NodeList(EXPRESSION_2_PROPERTY);
}
}
@@ -160,7 +158,7 @@ public class SwitchCase extends Statement {
@Override
final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == EXPRESSION_2_PROPERTY) {
- return getExpression2();
+ return getExpressions();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
@@ -178,8 +176,8 @@ public class SwitchCase extends Statement {
result.setSourceRange(getStartPosition(), getLength());
result.copyLeadingComment(this);
if (this.ast.apiLevel >= AST.JLS12_INTERNAL) {
- result.getExpression2().addAll(
- ASTNode.copySubtrees(target, getExpression2()));
+ result.getExpressions().addAll(
+ ASTNode.copySubtrees(target, getExpressions()));
} else {
result.setExpression(
(Expression) ASTNode.copySubtree(target, getExpression()));
@@ -198,7 +196,7 @@ public class SwitchCase extends Statement {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
if (this.ast.apiLevel >= AST.JLS12_INTERNAL) {
- acceptChildren(visitor, this.expression);
+ acceptChildren(visitor, this.expressions);
} else {
acceptChild(visitor, getExpression());
}
@@ -228,17 +226,17 @@ public class SwitchCase extends Statement {
}
/**
- * Returns the expression of this switch case, or
+ * Returns the list of expressions of this switch case, or
* <code>empty</code> if there is none (the "default:" case).
*
* @return the expression node, or <code>expression</code> if there is none
* @since 3.17 BETA_JAVA_12
*/
- public List getExpression2() {
- if (this.expression == null) {
+ public List getExpressions() {
+ if (this.expressions == null) {
unsupportedBelow12();
}
- return this.expression;
+ return this.expressions;
}
/**
@@ -263,8 +261,9 @@ public class SwitchCase extends Statement {
}
/**
- * Sets the isExpr of this switch case as <code>true</code> or </false>.
- *
+ * Sets the isExpr of this switch case as <code>true</code> or <code>false</code>.
+ * <code>true</code> indicates "->" and <code>false</code> indicates ":".
+
* @param isExpr <code>true</code> or </false>
* @since 3.17 BETA_JAVA_12
*/
@@ -273,7 +272,8 @@ public class SwitchCase extends Statement {
}
/**
- * Gets the isExpr of this switch case as <code>true</code> or </false>.
+ * Gets the isExpr of this switch case as <code>true</code> or <code>false</code>.
+ *<code>true</code> indicates "->" and <code>false</code> indicates ":".
*
* @return isExpr <code>true</code> or </false>
* @since 3.17 BETA_JAVA_12
@@ -294,7 +294,7 @@ public class SwitchCase extends Statement {
*/
public boolean isDefault() {
if (this.ast.apiLevel >= AST.JLS12_INTERNAL) {
- return getExpression2().isEmpty();
+ return getExpressions().isEmpty();
}
return getExpression() == null;
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java
index 97df44e724..5060aff18e 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java
@@ -33,7 +33,7 @@ import java.util.List;
* <b>default</b> <b>{ : | ->}</b>
* </pre>
* <code>SwitchCase</code> nodes are treated as a kind of
- * <code>Expression</code>.
+ * <code>Statement</code>.
* </p>
*
* @since 3.17 BETA_JAVA_12
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
index 5dda5ce5bd..f0a51b523f 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
@@ -1500,8 +1500,8 @@ public class NaiveASTFlattener extends ASTVisitor {
@Override
public boolean visit(SwitchCase node) {
if (node.getAST().apiLevel() >= JLS12) {
- if (!node.getExpression2().isEmpty()) {
- for (Iterator it = node.getExpression2().iterator(); it.hasNext(); ) {
+ if (!node.getExpressions().isEmpty()) {
+ for (Iterator it = node.getExpressions().iterator(); it.hasNext(); ) {
Expression t = (Expression) it.next();
if (node.isDefault()) {
if (node.isExpr()) {

Back to the top