List of usage examples for org.eclipse.jdt.core.dom SwitchCase equals
@Override public final boolean equals(Object obj)
ASTNode
implementation of this Object
method uses object identity (==). From source file:org.eclipse.xtend.core.javaconverter.JavaASTFlattener.java
License:Open Source License
@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 {//from www . jav a 2 s. com 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; }