Example usage for org.eclipse.jdt.core.dom ForStatement initializers

List of usage examples for org.eclipse.jdt.core.dom ForStatement initializers

Introduction

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

Prototype

ASTNode.NodeList initializers

To view the source code for org.eclipse.jdt.core.dom ForStatement initializers.

Click Source Link

Document

The list of initializer expressions (element type: Expression ).

Usage

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

License:Open Source License

@Override
public boolean visit(ForStatement node) {
    this.fBuffer.append("for (");//$NON-NLS-1$
    for (Iterator<Expression> it = node.initializers().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.accept(this);
    }//from  w w w  .ja va2s . c o  m
    this.fBuffer.append("; ");//$NON-NLS-1$
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    this.fBuffer.append("; ");//$NON-NLS-1$
    for (Iterator<Expression> it = node.updaters().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.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(ForStatement 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.FOR);
    for (Object e : node.initializers()) {
        ((org.eclipse.jdt.core.dom.Expression) e).accept(this);
        b.addInitializations(expressions.pop());
    }//from w w w  .j av a 2 s . c  om
    for (Object e : node.updaters()) {
        ((org.eclipse.jdt.core.dom.Expression) e).accept(this);
        b.addUpdates(expressions.pop());
    }
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        b.setExpression(expressions.pop());
    }
    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.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaMessageGrouper.java

License:Open Source License

/**
 * Updates labels and colours for the grouping.
 * @param currentGrouping//from  ww w.  j av  a2  s  .  c om
 */
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/*from ww w. j  a v a2 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 w  w  .  jav  a  2s.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() + ")";
        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:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ForStatement node) {
    printIndent();//from w  ww .  j a  va 2 s.com
    this.buffer.append("for (");//$NON-NLS-1$
    for (Iterator it = node.initializers().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        e.accept(this);
        if (it.hasNext())
            buffer.append(", ");//$NON-NLS-1$
    }
    this.buffer.append("; ");//$NON-NLS-1$
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    this.buffer.append("; ");//$NON-NLS-1$
    for (Iterator it = node.updaters().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        e.accept(this);
        if (it.hasNext())
            buffer.append(", ");//$NON-NLS-1$
    }
    this.buffer.append(") ");//$NON-NLS-1$
    node.getBody().accept(this);
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(ForStatement node) {
    handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_for,
            this.options.insert_space_after_opening_paren_in_for);
    handleTokenBefore(node.getBody(), TokenNameRPAREN, this.options.insert_space_before_closing_paren_in_for,
            false);//  w w w. j  a  va 2s .c  om
    handleCommas(node.initializers(), this.options.insert_space_before_comma_in_for_inits,
            this.options.insert_space_after_comma_in_for_inits);
    handleCommas(node.updaters(), this.options.insert_space_before_comma_in_for_increments,
            this.options.insert_space_after_comma_in_for_increments);

    boolean part1Empty = node.initializers().isEmpty();
    boolean part2Empty = node.getExpression() == null;
    boolean part3Empty = node.updaters().isEmpty();
    handleToken(node, TokenNameSEMICOLON, this.options.insert_space_before_semicolon_in_for && !part1Empty,
            this.options.insert_space_after_semicolon_in_for && !part2Empty);
    handleTokenBefore(node.getBody(), TokenNameSEMICOLON,
            this.options.insert_space_before_semicolon_in_for && !part2Empty,
            this.options.insert_space_after_semicolon_in_for && !part3Empty);
    return true;
}

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

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.ForStatement node) {
    Expression condition = translateExpression(node.getExpression());
    List<Expression> updaters = translateExpressionList(node.updaters());
    Statement body = (Statement) translate(node.getBody());
    Object javaInitializer = !node.initializers().isEmpty() ? node.initializers().get(0) : null;
    if (javaInitializer instanceof org.eclipse.jdt.core.dom.VariableDeclarationExpression) {
        org.eclipse.jdt.core.dom.VariableDeclarationExpression javaVDE = (org.eclipse.jdt.core.dom.VariableDeclarationExpression) javaInitializer;
        List<VariableDeclaration> variables = Lists.newArrayList();
        for (Iterator<?> I = javaVDE.fragments().iterator(); I.hasNext();) {
            org.eclipse.jdt.core.dom.VariableDeclarationFragment fragment = (org.eclipse.jdt.core.dom.VariableDeclarationFragment) I
                    .next();//from w w w .j  av a  2s.  c o  m
            variables.add((VariableDeclaration) translate(fragment));
        }
        VariableDeclarationList variableList = variableDeclarationList(null,
                (TypeName) translate(javaVDE.getType()), variables);
        return done(forStatement(variableList, condition, updaters, body));
    } else {
        Expression initializer = translate((org.eclipse.jdt.core.dom.ASTNode) javaInitializer);
        return done(forStatement(initializer, condition, updaters, body));
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w  w . ja  va 2  s  . c  o m
public boolean visit(ForStatement node) {
    boolean emitAutoreleasePool = false;
    buffer.append("for (");
    for (Iterator<Expression> it = node.initializers().iterator(); it.hasNext();) {
        Expression next = it.next();
        if (next instanceof VariableDeclarationExpression) {
            List<VariableDeclarationFragment> vars = ((VariableDeclarationExpression) next).fragments();
            for (VariableDeclarationFragment fragment : vars) {
                emitAutoreleasePool |= Types.hasAutoreleasePoolAnnotation(Types.getBinding(fragment));
            }
        }
        next.accept(this);
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append("; ");
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }
    buffer.append("; ");
    for (Iterator<Expression> it = node.updaters().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(") ");
    if (emitAutoreleasePool) {
        buffer.append("{\nNSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n");
    }
    node.getBody().accept(this);
    if (emitAutoreleasePool) {
        buffer.append("[pool__ release];\n}\n");
    }
    return false;
}

From source file:com.google.devtools.j2objc.util.ASTUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Expression> getInitializers(ForStatement node) {
    return node.initializers();
}