Search in sources :

Example 76 with ReturnStatement

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;
}
Also used : SwitchCase(org.eclipse.jdt.core.dom.SwitchCase) DoStatement(org.eclipse.jdt.core.dom.DoStatement) Statement(org.eclipse.jdt.core.dom.Statement) ContinueStatement(org.eclipse.jdt.core.dom.ContinueStatement) SynchronizedStatement(org.eclipse.jdt.core.dom.SynchronizedStatement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) AssertStatement(org.eclipse.jdt.core.dom.AssertStatement) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) ArrayList(java.util.ArrayList) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Block(org.eclipse.jdt.core.dom.Block) Map(java.util.Map)

Aggregations

ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)76 Block (org.eclipse.jdt.core.dom.Block)46 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)39 Expression (org.eclipse.jdt.core.dom.Expression)37 AST (org.eclipse.jdt.core.dom.AST)31 ASTNode (org.eclipse.jdt.core.dom.ASTNode)31 Type (org.eclipse.jdt.core.dom.Type)26 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)25 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)23 SimpleName (org.eclipse.jdt.core.dom.SimpleName)22 Statement (org.eclipse.jdt.core.dom.Statement)22 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)21 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)16 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)16 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)15 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)14 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)14 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)14 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)14