Example usage for org.eclipse.jdt.core.dom WhileStatement getExpression

List of usage examples for org.eclipse.jdt.core.dom WhileStatement getExpression

Introduction

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

Prototype

public Expression getExpression() 

Source Link

Document

Returns the expression of this while statement.

Usage

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

License:Open Source License

@Override
public boolean visit(WhileStatement node) {
    this.fBuffer.append("while (");//$NON-NLS-1$
    node.getExpression().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(WhileStatement 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.WHILE);
    node.getExpression().accept(this);
    b.setExpression(expressions.pop());/*  ww  w.  ja va  2  s.c o  m*/
    statements.push(new ArrayList<boa.types.Ast.Statement>());
    node.getBody().accept(this);
    for (boa.types.Ast.Statement s : statements.pop())
        b.addStatements(s);
    list.add(b.build());
    return false;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.ConditionInferenceStrategy.java

License:Open Source License

private Expression getExpression(ASTNode node) {
    Expression exp = null;/*from   www  . j  a va  2  s .  c o  m*/

    if (node instanceof ForStatement) {
        ForStatement forStatement = (ForStatement) node;
        exp = forStatement.getExpression();
    } else if (node instanceof IfStatement) {
        IfStatement ifStatement = (IfStatement) node;
        exp = ifStatement.getExpression();
    } else if (node instanceof WhileStatement) {
        WhileStatement whileStatement = (WhileStatement) node;
        exp = whileStatement.getExpression();
    } else if (node instanceof DoStatement) {
        DoStatement doStatement = (DoStatement) node;
        exp = doStatement.getExpression();
    }

    return exp;
}

From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaMessageGrouper.java

License:Open Source License

/**
 * Updates labels and colours for the grouping.
 * @param currentGrouping/*from w w w.  ja  v  a2 s  .  c  o  m*/
 */
private void updateGrouping(MappedMessageGrouping grouping) {
    ASTNode node = (ASTNode) grouping.getKey();
    String text = "";
    int i;
    Color bg = null;
    Color fg = null;
    switch (node.getNodeType()) {
    case ASTNode.IF_STATEMENT:
        IfStatement ifStatement = (IfStatement) node;
        text = "if (" + ifStatement.getExpression().toString() + ")";
        //it could be an else-if, make sure
        if (ifStatement.getParent().getNodeType() == ASTNode.IF_STATEMENT) {
            if (ifStatement.equals(((IfStatement) ifStatement.getParent()).getElseStatement())) {
                text = "else " + text;
            }
        }
        fg = ISketchColorConstants.CONDITION_FG;
        bg = ISketchColorConstants.CONDITION_BG;
        break;
    case ASTNode.WHILE_STATEMENT:
        WhileStatement whileStatement = (WhileStatement) node;
        text = "while (" + whileStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.DO_STATEMENT:
        DoStatement doStatement = (DoStatement) node;
        text = "do..while (" + doStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.FOR_STATEMENT:
        ForStatement forStatement = (ForStatement) node;
        List<?> initializers = forStatement.initializers();
        List<?> updaters = forStatement.updaters();
        text = "for (";
        for (i = 0; i < initializers.size(); i++) {
            text += initializers.get(i).toString();
            if (i < initializers.size() - 1) {
                text += ",";
            }
        }
        text += ";";
        if (forStatement.getExpression() != null) {
            text += forStatement.getExpression();
        }
        text += ";";
        for (i = 0; i < updaters.size(); i++) {
            text += updaters.get(i).toString();
            if (i < updaters.size() - 1) {
                text += ",";
            }
        }
        text += ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.ENHANCED_FOR_STATEMENT:
        EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
        text = "for (" + enhancedForStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.TRY_STATEMENT:
        text = "try";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    case ASTNode.CATCH_CLAUSE:
        CatchClause catchClause = (CatchClause) node;
        text = "catch (" + catchClause.getException().toString() + ")";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    default:
        //get the else blocks
        if (node instanceof Statement) {
            Statement statement = (Statement) node;
            if (statement.getParent() instanceof IfStatement) {
                if (((IfStatement) statement.getParent()).getElseStatement() == statement) {
                    text = "else";
                    fg = ISketchColorConstants.CONDITION_FG;
                    bg = ISketchColorConstants.CONDITION_BG;
                }
            }
        }
        break;
    }

    grouping.setName(text);
    grouping.setForeground(fg);
    grouping.setBackground(bg);
}

From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.ASTMessageGrouper.java

License:Open Source License

/**
 * Updates labels and colours for the grouping.
 * @param currentGrouping//w ww .  ja v  a 2 s .c om
 */
private void updateGrouping(ASTMessageGrouping grouping, ASTNode node) {
    String text = "";
    int i;
    Color bg = null;
    Color fg = null;
    switch (node.getNodeType()) {
    case ASTNode.IF_STATEMENT:
        IfStatement ifStatement = (IfStatement) node;
        text = "if (" + ifStatement.getExpression().toString() + ")";
        //it could be an else-if, make sure
        if (ifStatement.getParent().getNodeType() == ASTNode.IF_STATEMENT) {
            if (ifStatement.equals(((IfStatement) ifStatement.getParent()).getElseStatement())) {
                text = "else " + text;
            }
        }
        fg = ISketchColorConstants.CONDITION_FG;
        bg = ISketchColorConstants.CONDITION_BG;
        break;
    case ASTNode.WHILE_STATEMENT:
        WhileStatement whileStatement = (WhileStatement) node;
        text = "while (" + whileStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.DO_STATEMENT:
        DoStatement doStatement = (DoStatement) node;
        text = "do..while (" + doStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.FOR_STATEMENT:
        ForStatement forStatement = (ForStatement) node;
        List<?> initializers = forStatement.initializers();
        List<?> updaters = forStatement.updaters();
        text = "for (";
        for (i = 0; i < initializers.size(); i++) {
            text += initializers.get(i).toString();
            if (i < initializers.size() - 1) {
                text += ",";
            }
        }
        text += ";";
        if (forStatement.getExpression() != null) {
            text += forStatement.getExpression();
        }
        text += ";";
        for (i = 0; i < updaters.size(); i++) {
            text += updaters.get(i).toString();
            if (i < updaters.size() - 1) {
                text += ",";
            }
        }
        text += ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.ENHANCED_FOR_STATEMENT:
        EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
        text = "for (" + enhancedForStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.TRY_STATEMENT:
        text = "try";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    case ASTNode.CATCH_CLAUSE:
        CatchClause catchClause = (CatchClause) node;
        text = "catch (" + catchClause.getException().toString() + ")";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    default:
        //get the else blocks
        if (node instanceof Statement) {
            Statement statement = (Statement) node;
            if (statement.getParent() instanceof IfStatement) {
                if (((IfStatement) statement.getParent()).getElseStatement() == statement) {
                    text = "else";
                    fg = ISketchColorConstants.CONDITION_FG;
                    bg = ISketchColorConstants.CONDITION_BG;
                }
            }
        }
        break;
    }
    if (grouping.node.isLoop()) {
        ASTMessageGroupingTree[] siblings = grouping.node.getSiblings();
        text = text + "[" + grouping.node.getIteration() + " of " + (siblings.length + 1) + "]";
    }

    grouping.setName(text);
    grouping.setForeground(fg);
    grouping.setBackground(bg);
}

From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.CopyOfASTMessageGrouper.java

License:Open Source License

/**
 * Updates labels and colours for the grouping.
 * @param currentGrouping/*from   w  ww. jav a2 s.co  m*/
 */
private void updateGrouping(ASTMessageGrouping grouping, ASTNode node) {
    String text = "";
    int i;
    Color bg = null;
    Color fg = null;
    switch (node.getNodeType()) {
    case ASTNode.IF_STATEMENT:
        IfStatement ifStatement = (IfStatement) node;
        text = "if (" + ifStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.CONDITION_FG;
        bg = ISketchColorConstants.CONDITION_BG;
        break;
    case ASTNode.WHILE_STATEMENT:
        WhileStatement whileStatement = (WhileStatement) node;
        text = "while (" + whileStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.DO_STATEMENT:
        DoStatement doStatement = (DoStatement) node;
        text = "do..while (" + doStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.FOR_STATEMENT:
        ForStatement forStatement = (ForStatement) node;
        List<?> initializers = forStatement.initializers();
        List<?> updaters = forStatement.updaters();
        text = "for (";
        for (i = 0; i < initializers.size(); i++) {
            text += initializers.get(i).toString();
            if (i < initializers.size() - 1) {
                text += ",";
            }
        }
        text += ";";
        if (forStatement.getExpression() != null) {
            text += forStatement.getExpression();
        }
        text += ";";
        for (i = 0; i < updaters.size(); i++) {
            text += updaters.get(i).toString();
            if (i < updaters.size() - 1) {
                text += ",";
            }
        }
        text += ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.ENHANCED_FOR_STATEMENT:
        EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
        text = "for (" + enhancedForStatement.getExpression().toString() + ")";
        fg = ISketchColorConstants.LOOP_FG;
        bg = ISketchColorConstants.LOOP_BG;
        break;
    case ASTNode.TRY_STATEMENT:
        text = "try";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    case ASTNode.CATCH_CLAUSE:
        CatchClause catchClause = (CatchClause) node;
        text = "catch (" + catchClause.getException().toString() + ")";
        fg = ISketchColorConstants.ERROR_FG;
        bg = ISketchColorConstants.ERROR_BG;
        break;
    default:
        //get the else blocks
        if (node instanceof Statement) {
            Statement statement = (Statement) node;
            if (statement.getParent() instanceof IfStatement) {
                if (((IfStatement) statement.getParent()).getElseStatement() == statement) {
                    text = "else";
                    fg = ISketchColorConstants.CONDITION_FG;
                    bg = ISketchColorConstants.CONDITION_BG;
                }
            }
        }
        break;
    }
    if (grouping.node.isLoop()) {
        ASTMessageGroupingTree[] siblings = grouping.node.getSiblings();
        text = text + "[" + grouping.node.getIteration() + " of " + (siblings.length + 1) + "]";
    }
    grouping.setName(text);
    grouping.setForeground(fg);
    grouping.setBackground(bg);
}

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

License:Open Source License

@Override
public boolean visit(WhileStatement node) {
    pushNode(node, node.getExpression().toString());
    return true;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(WhileStatement node) {
    printIndent();/*w w w  .  j a  v a2 s.  co m*/
    this.buffer.append("while (");//$NON-NLS-1$
    node.getExpression().accept(this);
    this.buffer.append(") ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java

License:Open Source License

@Override
public boolean visit(WhileStatement node) {
    String hint = GetNodeText(node.getExpression());
    int startLoc = node.getStartPosition();
    int endLoc = startLoc + node.getLength() - 1;
    hint = "while( " + hint + " )"; //$NON-NLS-1$ //$NON-NLS-2$ 
    _scopeStack.push(new ScopeInfo(hint, startLoc, node));
    try {/*w  w  w  . ja v a2s  . com*/
        _container.add(new Hint("while", startLoc, endLoc, hint)); //$NON-NLS-1$ 
    } catch (BadLocationException e) {
        _cancelProcessing.set(true);
    }
    return shouldContinue();
}

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

License:Apache License

/**
 * Returns nodes description.//www . j av a 2  s.c  o m
 * 
 * @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;
}