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

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

Introduction

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

Prototype

public SimpleName getLabel() 

Source Link

Document

Returns the label 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);//  w ww  .  j  a  v  a 2s.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   ww w . j av  a 2  s  .  c  om
    node.getLabel().accept(this);
    this.buffer.append(": ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns nodes description./*from  w  ww.jav a 2  s . c  om*/
 * 
 * @param node the AST-node
 * @return description string
 */
public static String getNodeDescr(ASTNode node) {
    StringBuffer elementDescr = new StringBuffer(node.getClass().getSimpleName());
    elementDescr.append(": ");

    int nodeType = node.getNodeType();
    switch (nodeType) {
    case ASTNode.COMPILATION_UNIT:
        CompilationUnit cu = (CompilationUnit) node;
        elementDescr.append(cu.getJavaElement().getElementName());
        break;

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration pd = (PackageDeclaration) node;
        elementDescr.append(pd.getName());
        break;

    case ASTNode.TYPE_DECLARATION:
        TypeDeclaration td = (TypeDeclaration) node;
        appendModifiers(td.getModifiers(), elementDescr);
        elementDescr.append(" class ");
        elementDescr.append(td.getName());
        break;

    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration md = (MethodDeclaration) node;
        appendModifiers(md.getModifiers(), elementDescr);
        elementDescr.append(md.getReturnType2() == null ? "" : md.getReturnType2().toString());
        elementDescr.append(' ');
        elementDescr.append(md.getName());
        elementDescr.append("()");
        break;

    case ASTNode.BLOCK:
        elementDescr.append("{...}");
        break;

    case ASTNode.IF_STATEMENT:
        IfStatement is = (IfStatement) node;
        elementDescr.append("if( ");
        elementDescr.append(is.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.FOR_STATEMENT:
        ForStatement fs = (ForStatement) node;
        elementDescr.append("for (...; ");
        elementDescr.append(fs.getExpression().toString());
        elementDescr.append("; ...){...}");
        break;

    case ASTNode.WHILE_STATEMENT:
        WhileStatement ws = (WhileStatement) node;
        elementDescr.append("while ( ");
        elementDescr.append(ws.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.DO_STATEMENT:
        DoStatement ds = (DoStatement) node;
        elementDescr.append("do {...} while (");
        elementDescr.append(ds.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.LABELED_STATEMENT:
        LabeledStatement ls = (LabeledStatement) node;
        elementDescr.append(ls.getLabel().toString());
        elementDescr.append(":");
        break;

    case ASTNode.CATCH_CLAUSE:
        CatchClause cs = (CatchClause) node;
        elementDescr.append("catch (");
        elementDescr.append(cs.getException().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_STATEMENT:
        SwitchStatement ss = (SwitchStatement) node;
        elementDescr.append("switch (");
        elementDescr.append(ss.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_CASE:
        SwitchCase sc = (SwitchCase) node;
        elementDescr.append("case ");
        elementDescr.append(sc.getExpression() == null ? "default" : sc.getExpression().toString());
        elementDescr.append(":");
        break;
    case ASTNode.JAVADOC:
    case ASTNode.BLOCK_COMMENT:
    case ASTNode.LINE_COMMENT:
    case ASTNode.TRY_STATEMENT:
        /* nothing to do */
        break;

    default:
        elementDescr.append(node.toString());
    }

    /* cut the string if it is too long */
    String str = elementDescr.toString();
    if (str.length() > 128) {
        str = str.substring(0, 128) + " ... ";
    }
    str = str.replaceAll("\n", "");
    return str;
}

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 {//  ww  w . j  a v a2s.c  o  m
            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//from   www.j a va  2s.  co m
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();
    if (label != null) {
        put(label, createLabelBinding(label));
    }//from   w ww. j a  v  a  2  s .c o  m
    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();/* w  ww. j  a  va2s . c om*/
    node.getLabel().accept(this);
    sb.print(": ");
    node.getBody().accept(this);
    return false;
}