Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-02-18 06:54:36 +0000
committerManoj Palat2019-02-18 06:54:36 +0000
commitfaba81847bc601e02463cc7206ee4d0dfdc5f341 (patch)
tree4af7962497b75186abfa2911d283c03fc51f1da5 /org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
parent75678f56c16789d0e34a7ff19deb7688059a0f16 (diff)
downloadeclipse.jdt.core-faba81847bc601e02463cc7206ee4d0dfdc5f341.tar.gz
eclipse.jdt.core-faba81847bc601e02463cc7206ee4d0dfdc5f341.tar.xz
eclipse.jdt.core-faba81847bc601e02463cc7206ee4d0dfdc5f341.zip
Bug 544523 - [12]Switch Expressions - nested - compilation error
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
index c763fa89b6..3cf51327ab 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java
@@ -27,6 +27,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
import java.util.stream.Collectors;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
@@ -269,28 +270,38 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression
return; // already calculated.
class ResultExpressionsCollector extends ASTVisitor {
- SwitchExpression targetSwitchExpression;
+ Stack<SwitchExpression> targetSwitchExpressions;
public ResultExpressionsCollector(SwitchExpression se) {
- this.targetSwitchExpression = se;
+ if (this.targetSwitchExpressions == null)
+ this.targetSwitchExpressions = new Stack<>();
+ this.targetSwitchExpressions.push(se);
}
@Override
public boolean visit(SwitchExpression switchExpression, BlockScope blockScope) {
- return false;
+ if (switchExpression.resultExpressions == null)
+ switchExpression.resultExpressions = new ArrayList<>(0);
+ this.targetSwitchExpressions.push(switchExpression);
+ return true;
+ }
+ @Override
+ public void endVisit(SwitchExpression switchExpression, BlockScope blockScope) {
+ this.targetSwitchExpressions.pop();
}
@Override
public boolean visit(BreakStatement breakStatement, BlockScope blockScope) {
+ SwitchExpression targetSwitchExpression = this.targetSwitchExpressions.peek();
if (breakStatement.expression != null) {
- this.targetSwitchExpression.resultExpressions.add(breakStatement.expression);
- breakStatement.switchExpression = this.targetSwitchExpression;
+ targetSwitchExpression.resultExpressions.add(breakStatement.expression);
+ breakStatement.switchExpression = this.targetSwitchExpressions.peek();
breakStatement.label = null; // not a label, but an expression
if (breakStatement.expression instanceof SingleNameReference) {
((SingleNameReference) breakStatement.expression).isLabel = false;
}
} else {
// flag an error while resolving
- breakStatement.switchExpression = this.targetSwitchExpression;
+ breakStatement.switchExpression = targetSwitchExpression;
}
- return false;
+ return true;
}
@Override
public boolean visit(DoStatement stmt, BlockScope blockScope) {
@@ -672,4 +683,19 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression
public TypeBinding expectedType() {
return this.expectedType;
}
+ @Override
+ public void traverse(
+ ASTVisitor visitor,
+ BlockScope blockScope) {
+
+ if (visitor.visit(this, blockScope)) {
+ this.expression.traverse(visitor, blockScope);
+ if (this.statements != null) {
+ int statementsLength = this.statements.length;
+ for (int i = 0; i < statementsLength; i++)
+ this.statements[i].traverse(visitor, this.scope);
+ }
+ }
+ visitor.endVisit(this, blockScope);
+ }
} \ No newline at end of file

Back to the top