List of usage examples for org.eclipse.jdt.core.dom ForStatement getExpression
public Expression getExpression()
null
if there is none. 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 ww. ja va2 s . c om*/ 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()); }/*w ww . j av a 2 s. c o m*/ 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.mcgill.cs.swevo.ppa.inference.ConditionInferenceStrategy.java
License:Open Source License
private Expression getExpression(ASTNode node) { Expression exp = null;/* w w w .j a v a2 s. co 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.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
public static boolean isIndicationOfField(Name node) { boolean isField = false; ASTNode parent = node.getParent();// ww w . j a v a 2s .c o m // The thing here is that if the parent is a qualified name, go one // level up. // If the parent is still a qualified name, then, it means we were in // the middle, so this is // not necessarily a field. if (parent instanceof QualifiedName) { QualifiedName qName = (QualifiedName) parent; if (qName.getName().equals(node)) { node = (Name) parent; parent = parent.getParent(); } } if (parent instanceof ArrayAccess) { isField = true; // } else if (parent instanceof ArrayCreation) { // isField = true; } else if (parent instanceof ArrayInitializer) { isField = true; } else if (parent instanceof Assignment) { isField = true; } else if (parent instanceof CastExpression) { CastExpression cExpression = (CastExpression) parent; isField = cExpression.getExpression().equals(node); } else if (parent instanceof ConditionalExpression) { isField = true; } else if (parent instanceof InfixExpression) { isField = true; } else if (parent instanceof WhileStatement) { isField = true; } else if (parent instanceof DoStatement) { isField = true; } else if (parent instanceof ForStatement) { ForStatement forStatement = (ForStatement) parent; isField = forStatement.getExpression().equals(node); } else if (parent instanceof PrefixExpression) { isField = true; } else if (parent instanceof PostfixExpression) { isField = true; } else if (parent instanceof ReturnStatement) { isField = true; } else if (parent instanceof InstanceofExpression) { InstanceofExpression ioe = (InstanceofExpression) parent; isField = ioe.getLeftOperand().equals(node); } else if (parent instanceof FieldAccess) { isField = true; } else if (parent instanceof SuperFieldAccess) { isField = true; } else if (parent instanceof MethodInvocation) { MethodInvocation mi = (MethodInvocation) parent; for (Object object : mi.arguments()) { if (node == object) { isField = true; break; } } } else if (parent instanceof ClassInstanceCreation) { ClassInstanceCreation cic = (ClassInstanceCreation) parent; for (Object object : cic.arguments()) { if (node == object) { isField = true; break; } } } else if (parent instanceof VariableDeclarationFragment) { isField = true; } return isField; }
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/*w w w .j av 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/*from 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// www .j a v 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:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(ForStatement node) { String value = ""; if (node.getExpression() != null) { value = node.getExpression().toString(); }//from w w w. j a v a 2s. c o m pushNode(node, value); return true; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(ForStatement node) { printIndent();//from ww w . jav a 2 s. co m 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);/*from w ww . jav a2s . co m*/ 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; }