Example usage for org.eclipse.jdt.core.dom SwitchCase accept

List of usage examples for org.eclipse.jdt.core.dom SwitchCase accept

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SwitchCase accept.

Prototype

public final void accept(ASTVisitor visitor) 

Source Link

Document

Accepts the given visitor on a visit of the current node.

Usage

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 {//www. j  a v  a2 s  . c o  m
            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;
}