List of usage examples for org.eclipse.jdt.core.dom IfStatement getExpression
public Expression getExpression()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(IfStatement node) { this.fBuffer.append("if (");//$NON-NLS-1$ node.getExpression().accept(this); this.fBuffer.append(") ");//$NON-NLS-1$ node.getThenStatement().accept(this); if (node.getElseStatement() != null) { this.fBuffer.append(" else ");//$NON-NLS-1$ node.getElseStatement().accept(this); }//from w ww. jav a 2s . c o m return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(IfStatement 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.IF); node.getExpression().accept(this); b.setExpression(expressions.pop());//from ww w . ja v a 2 s . c o m statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getThenStatement().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); // FIXME if (node.getElseStatement() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getElseStatement().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } list.add(b.build()); return false; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(IfStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); int beginLineBlock = 0; int beginColumnBlock = 0; Expression expression = node.getExpression(); if (expression != null) { beginLineBlock = cu.getLineNumber(expression.getStartPosition() + expression.getLength()); beginColumnBlock = cu.getColumnNumber(expression.getStartPosition() + expression.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBlock, endLine, beginColumnBlock, endColumn, null)); } else {/*from w w w.ja v a2s . c o m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:ca.mcgill.cs.swevo.ppa.inference.ConditionInferenceStrategy.java
License:Open Source License
private Expression getExpression(ASTNode node) { Expression exp = null;/*from ww w . ja v a 2s.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 www. j a v a 2 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 . j a va 2 s . c o 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() + ")"; //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/* w ww . j a v a 2s.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:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(IfStatement node) { Statement thenStmt = node.getThenStatement(); Statement elseStmt = node.getElseStatement(); Expression condExpr = node.getExpression(); String thenStr = thenStmt.toString().replace('\n', ' '); String elseStr = ""; if (elseStmt != null) { elseStr = elseStmt.toString().replace('\n', ' '); }//from w w w . j a v a2 s .c o m if (this.mtbStack.isEmpty()) { return true; } IMethodBinding mtb = (IMethodBinding) this.mtbStack.peek(); String methodStr = getQualifiedName(mtb); String condStr = condExpr.toString(); condStr = edit_str(condStr); thenStr = edit_str(thenStr); elseStr = edit_str(elseStr); try { this.facts.add(Fact.makeConditionalFact(condStr, thenStr, elseStr, methodStr)); } catch (Exception e) { System.err.println("Cannot resolve conditional \"" + condExpr.toString() + "\""); System.out.println("ifStmt: " + thenStr); System.out.println("elseStmt: " + elseStr); System.err.println(e.getMessage()); } return true; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(IfStatement node) { String expression = node.getExpression().toString(); pushNode(node, expression/* , node.getStartPosition(), node.getLength() */); Statement stmt = node.getThenStatement(); if (stmt != null) { pushNode(stmt, expression);/*w w w. ja v a 2 s .c o m*/ stmt.accept(this); popNode(); } stmt = node.getElseStatement(); if (stmt != null) { pushNode(stmt, expression); node.getElseStatement().accept(this); popNode(); } return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(IfStatement node) { printIndent();// w w w . j av a 2 s.c o m this.buffer.append("if (");//$NON-NLS-1$ node.getExpression().accept(this); this.buffer.append(") ");//$NON-NLS-1$ node.getThenStatement().accept(this); if (node.getElseStatement() != null) { this.buffer.append(" else ");//$NON-NLS-1$ node.getElseStatement().accept(this); } return false; }