use of org.eclipse.jdt.core.dom.ReturnStatement in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final SwitchStatement node) {
this.appendLineWrapToBuffer();
this.appendToBuffer("switch (");
node.getExpression().accept(this);
this.appendToBuffer(") ");
this.appendToBuffer("{");
this.increaseIndent();
final Function2<Map<SwitchCase, ArrayList<Statement>>, Statement, Map<SwitchCase, ArrayList<Statement>>> _function = (Map<SwitchCase, ArrayList<Statement>> map, Statement currStatement) -> {
if ((currStatement instanceof SwitchCase)) {
map.put(((SwitchCase) currStatement), CollectionLiterals.<Statement>newArrayList());
} else {
map.get(IterableExtensions.<SwitchCase>last(map.keySet())).add(currStatement);
}
return map;
};
final Map<SwitchCase, ArrayList<Statement>> foldedCases = IterableExtensions.<Statement, Map<SwitchCase, ArrayList<Statement>>>fold(node.statements(), CollectionLiterals.<SwitchCase, ArrayList<Statement>>newLinkedHashMap(), _function);
final BiConsumer<SwitchCase, ArrayList<Statement>> _function_1 = (SwitchCase switchCase, ArrayList<Statement> statements) -> {
switchCase.accept(this);
final boolean isLastCase = switchCase.equals(IterableExtensions.<SwitchCase>last(foldedCases.keySet()));
if ((statements.isEmpty() && (!isLastCase))) {
this.appendToBuffer(",");
} else {
this.appendToBuffer(":");
final boolean probablyReturns = ((IterableExtensions.<Statement>last(statements) instanceof ReturnStatement) || ((IterableExtensions.<Statement>last(statements) instanceof Block) && (IterableExtensions.<Object>last(((Block) IterableExtensions.<Statement>last(statements)).statements()) instanceof ReturnStatement)));
if (((!isLastCase) && (!probablyReturns))) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/* FIXME unsupported fall-through */");
this.appendToBuffer(_builder.toString());
this.addProblem(node, "Unsupported fall-through case in switch expression");
}
}
final boolean surround = ((isLastCase && statements.isEmpty()) || ((!statements.isEmpty()) && (!(statements.get(0) instanceof Block))));
if (surround) {
this.appendToBuffer("{");
this.increaseIndent();
this.appendLineWrapToBuffer();
}
this.visitAll(statements);
if (surround) {
this.decreaseIndent();
this.appendLineWrapToBuffer();
this.appendToBuffer("}");
}
};
foldedCases.forEach(_function_1);
this.decreaseIndent();
this.appendLineWrapToBuffer();
this.appendToBuffer("}");
return false;
}
Aggregations