Example usage for org.eclipse.jdt.core.dom LabeledStatement getBody

List of usage examples for org.eclipse.jdt.core.dom LabeledStatement getBody

Introduction

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

Prototype

public Statement getBody() 

Source Link

Document

Returns the body of this labeled statement.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(LabeledStatement node) {
    node.getLabel().accept(this);
    this.fBuffer.append(": ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(LabeledStatement node) {
    boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder();
    //      b.setPosition(pos.build());
    List<boa.types.Ast.Statement> list = statements.peek();
    b.setKind(boa.types.Ast.Statement.StatementKind.LABEL);
    statements.push(new ArrayList<boa.types.Ast.Statement>());
    node.getBody().accept(this);
    for (boa.types.Ast.Statement s : statements.pop())
        b.addStatements(s);/*ww  w  .j  a v a2s.c  o  m*/
    boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
    //      eb.setPosition(pos.build());//FIXME
    eb.setKind(boa.types.Ast.Expression.ExpressionKind.LITERAL);
    eb.setLiteral(node.getLabel().getFullyQualifiedName());
    b.setExpression(eb.build());
    list.add(b.build());
    return false;
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@Override
public boolean visit(LabeledStatement node) {
    pushNode(node, node.getLabel().getFullyQualifiedName());
    node.getBody().accept(this);
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(LabeledStatement node) {
    printIndent();/*from   w  w  w. java  2s  .  c  o m*/
    node.getLabel().accept(this);
    this.buffer.append(": ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.LabeledStatement node) {
    List<Label> labels = Lists.newArrayList();
    while (true) {
        SimpleIdentifier labelIdentifier = translate(node.getLabel());
        labels.add(label(labelIdentifier));
        if (node.getBody() instanceof org.eclipse.jdt.core.dom.LabeledStatement) {
            node = (org.eclipse.jdt.core.dom.LabeledStatement) node.getBody();
        } else {//w  w w .ja v a 2 s  .  com
            break;
        }
    }
    return done(labeledStatement(labels, (Statement) translate(node.getBody())));
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(LabeledStatement node) {
    node.getLabel().accept(this);
    buffer.append(": ");
    node.getBody().accept(this);
    return false;
}

From source file:com.google.devtools.j2cpp.translate.Rewriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww w .ja va 2s  .com*/
public boolean visit(LabeledStatement node) {
    Statement s = node.getBody();
    Statement statementBody = null;
    if (s instanceof DoStatement) {
        statementBody = ((DoStatement) s).getBody();
    } else if (s instanceof EnhancedForStatement) {
        statementBody = ((EnhancedForStatement) s).getBody();
    } else if (s instanceof ForStatement) {
        statementBody = ((ForStatement) s).getBody();
    } else if (s instanceof WhileStatement) {
        statementBody = ((WhileStatement) s).getBody();
    }
    if (statementBody != null) {
        AST ast = node.getAST();

        final boolean[] hasContinue = new boolean[1];
        final boolean[] hasBreak = new boolean[1];
        node.accept(new ASTVisitor() {
            @Override
            public void endVisit(ContinueStatement node) {
                if (node.getLabel() != null) {
                    hasContinue[0] = true;
                }
            }

            @Override
            public void endVisit(BreakStatement node) {
                if (node.getLabel() != null) {
                    hasBreak[0] = true;
                }
            }
        });

        List<Statement> stmts = null;
        if (hasContinue[0]) {
            if (statementBody instanceof Block) {
                // Add empty labeled statement as last block statement.
                stmts = ((Block) statementBody).statements();
                LabeledStatement newLabel = ast.newLabeledStatement();
                newLabel.setLabel(NodeCopier.copySubtree(ast, node.getLabel()));
                newLabel.setBody(ast.newEmptyStatement());
                stmts.add(newLabel);
            }
        }
        if (hasBreak[0]) {
            ASTNode parent = node.getParent();
            if (parent instanceof Block) {
                stmts = ((Block) parent).statements();
            } else {
                // Surround parent with block.
                Block block = ast.newBlock();
                stmts = block.statements();
                stmts.add((Statement) parent);

                // Replace parent in its statement list with new block.
                List<Statement> superStmts = ((Block) parent.getParent()).statements();
                for (int i = 0; i < superStmts.size(); i++) {
                    if (superStmts.get(i) == parent) {
                        superStmts.set(i, block);
                        break;
                    }
                }
                stmts = block.statements();
            }
            // Find node in statement list, and add empty labeled statement after it.
            for (int i = 0; i < stmts.size(); i++) {
                if (stmts.get(i) == node) {
                    LabeledStatement newLabel = ast.newLabeledStatement();
                    newLabel.setLabel(NodeCopier.copySubtree(ast, node.getLabel()));
                    newLabel.setBody(ast.newEmptyStatement());
                    stmts.add(i + 1, newLabel);
                    break;
                }
            }
        }

        if (hasContinue[0] || hasBreak[0]) {
            // Replace this node with its statement, thus deleting the label.
            ASTNode parent = node.getParent();
            if (parent instanceof Block) {
                stmts = ((Block) parent).statements();
                for (int i = 0; i < stmts.size(); i++) {
                    if (stmts.get(i) == node) {
                        stmts.set(i, NodeCopier.copySubtree(ast, node.getBody()));
                        break;
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.google.devtools.j2cpp.types.BindingMapBuilder.java

License:Open Source License

@Override
public boolean visit(LabeledStatement node) {
    SimpleName label = node.getLabel();/*  ww w .j  a v  a2s  .  c o m*/
    if (label != null) {
        put(label, createLabelBinding(label));
    }
    node.getBody().accept(this);
    return false;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(LabeledStatement node) {
    sb.printIndent();// ww  w. ja v a2s . c  o m
    node.getLabel().accept(this);
    sb.print(": ");
    node.getBody().accept(this);
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link LabeledStatement}s. */
@Override/* w w w . j av a 2s .c  o m*/
public boolean visit(LabeledStatement node) {
    sync(node);
    builder.open(ZERO);
    visit(node.getLabel());
    token(":");
    builder.forcedBreak();
    builder.close();
    node.getBody().accept(this);
    return false;
}