List of usage examples for org.eclipse.jdt.core.dom IfStatement getThenStatement
public Statement getThenStatement()
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); }//w ww . j ava2 s . c om 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 w w w. j ava 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:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaMessageGrouper.java
License:Open Source License
/** * @param currentParent//from w ww.ja v a2 s . c o m * @param messageNode * @return */ private ASTNode checkIfSide(IfStatement ifStatement, ASTNode messageNode) { ASTNode currentParent = messageNode; ASTNode thenStatement = ifStatement.getThenStatement(); ASTNode elseStatement = ifStatement.getElseStatement(); while (currentParent != null && currentParent != ifStatement) { if (currentParent == thenStatement) { return ifStatement; } else if (currentParent == elseStatement) { return elseStatement; } currentParent = currentParent.getParent(); } return null; }
From source file:cc.kave.eclipse.commons.analysis.transformer.BodyVisitor.java
License:Apache License
@Override public boolean visit(IfStatement stmt) { if (isTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) { body.add(getEmptyCompletionExpression()); }//from w w w . jav a 2 s . c o m IfElseBlock ifElseBlock = new IfElseBlock(); // TODO: Was bedeutet stmt.Condition? // Condition = _exprVisitor.ToSimpleExpression(stmt.Condition, body) ?? // new UnknownExpression() ifElseBlock.setCondition(exprVisitor.toSimpleExpression(null, body)); if (isTargetMatch(stmt, CompletionCase.InBody)) { ifElseBlock.getThen().add(getEmptyCompletionExpression()); } if (isTargetMatch(stmt, CompletionCase.InElse)) { ifElseBlock.getElse().add(getEmptyCompletionExpression()); } if (stmt.getThenStatement() != null) { stmt.getThenStatement().accept(new BodyVisitor(nameGen, marker, ifElseBlock.getThen())); } if (stmt.getElseStatement() != null) { stmt.getElseStatement().accept(new BodyVisitor(nameGen, marker, ifElseBlock.getElse())); } body.add(ifElseBlock); if (isTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) { body.add(getEmptyCompletionExpression()); } return super.visit(stmt); }
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', ' '); }// www . ja 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);//from w w w . java 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();/*from w w w .j av a 2 s .com*/ 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; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(IfStatement node) { Statement elseNode = node.getElseStatement(); Statement thenNode = node.getThenStatement(); if (elseNode != null) { if (this.options.insert_new_line_before_else_in_if_statement || !(thenNode instanceof Block)) this.tm.firstTokenBefore(elseNode, TokenNameelse).breakBefore(); boolean keepElseOnSameLine = (elseNode instanceof Block) || (this.options.keep_else_statement_on_same_line) || (this.options.compact_else_if && (elseNode instanceof IfStatement)); if (!keepElseOnSameLine) { breakLineBefore(elseNode);// ww w . j a v a 2 s. c o m indent(elseNode); } } boolean keepThenOnSameLine = this.options.keep_then_statement_on_same_line || (this.options.keep_simple_if_on_one_line && elseNode == null); if (!keepThenOnSameLine && !(thenNode instanceof Block)) { breakLineBefore(thenNode); indent(thenNode); } return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(IfStatement node) { if (!(node.getThenStatement() instanceof Block)) { int thenIndex = this.tm.firstIndexIn(node.getThenStatement(), -1); if (this.tm.get(thenIndex).getLineBreaksBefore() == 0) this.wrapIndexes.add(thenIndex); }/*from w w w . j a v a 2 s.c om*/ Statement elseStatement = node.getElseStatement(); if (elseStatement != null && !(elseStatement instanceof Block) && !(elseStatement instanceof IfStatement)) { int elseIndex = this.tm.firstIndexIn(elseStatement, -1); if (this.tm.get(elseIndex).getLineBreaksBefore() == 0) this.wrapIndexes.add(elseIndex); } if (!this.wrapIndexes.isEmpty()) { this.wrapParentIndex = this.tm.firstIndexAfter(node.getExpression(), TokenNameRPAREN); this.wrapGroupEnd = this.tm.lastIndexIn(node, -1); handleWrap(this.options.alignment_for_compact_if, node); } return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(IfStatement node) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_if, this.options.insert_space_after_opening_paren_in_if); Statement thenStatement = node.getThenStatement(); int closingParenIndex = this.tm.firstIndexBefore(thenStatement, TokenNameRPAREN); handleToken(this.tm.get(closingParenIndex), this.options.insert_space_before_closing_paren_in_if, /* space before then statement may be needed if it will stay on the same line */ !(thenStatement instanceof Block) && !this.tm.get(closingParenIndex + 1).isComment()); if (thenStatement instanceof Block && this.tm.isGuardClause((Block) thenStatement)) { handleToken(thenStatement, TokenNameLBRACE, false, true); this.tm.lastTokenIn(node, TokenNameRBRACE).spaceBefore(); }/*from w w w.j ava2 s. c o m*/ return true; }