Java Code Examples for org.eclipse.jdt.core.dom.IfStatement#getThenStatement()
The following examples show how to use
org.eclipse.jdt.core.dom.IfStatement#getThenStatement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SequenceDiagramVisitor.java From txtUML with Eclipse Public License 1.0 | 6 votes |
private void checkSendInIfNode(IfStatement ifNode) { boolean showErrorHere = placeOfError == ifNode; Statement thenStatement = ifNode.getThenStatement(); if (showErrorHere) { placeOfError = thenStatement; } if (thenStatement instanceof Block) { checkSendInBlock((Block) thenStatement, showErrorHere); } else { checkSendInStatement(thenStatement); } Statement elseStatement = ifNode.getElseStatement(); if (showErrorHere) { placeOfError = elseStatement; } if (elseStatement == null) { return; } if (elseStatement instanceof IfStatement) { checkSendInIfNode((IfStatement) elseStatement); } else if (elseStatement instanceof Block) { checkSendInBlock((Block) elseStatement, showErrorHere); } else { checkSendInStatement(elseStatement); } }
Example 2
Source File: OptAltFragmentExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
@Override public boolean preNext(IfStatement curElement) { Statement thenStatement = curElement.getThenStatement(); Statement elseStatement = curElement.getElseStatement(); Expression condition = curElement.getExpression(); if (elseStatement == null) { compiler.println("opt " + condition.toString()); return true; } else { compiler.println("alt " + condition.toString()); thenStatement.accept(compiler); if (elseStatement instanceof IfStatement) { processAltStatement((IfStatement) elseStatement); } else { compiler.println("else"); elseStatement.accept(compiler); } return false; } }
Example 3
Source File: OptAltFragmentExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
private void processAltStatement(IfStatement statement) { Statement thenStatement = statement.getThenStatement(); Statement elseStatement = statement.getElseStatement(); Expression condition = statement.getExpression(); compiler.println("else " + condition.toString()); thenStatement.accept(compiler); if (elseStatement != null) { if (elseStatement instanceof IfStatement) { processAltStatement((IfStatement) elseStatement); } else { compiler.println("else"); elseStatement.accept(compiler); } } }
Example 4
Source File: SourceProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean isSingleControlStatementWithoutBlock() { List<Statement> statements= fDeclaration.getBody().statements(); int size= statements.size(); if (size != 1) return false; Statement statement= statements.get(size - 1); int nodeType= statement.getNodeType(); if (nodeType == ASTNode.IF_STATEMENT) { IfStatement ifStatement= (IfStatement) statement; return !(ifStatement.getThenStatement() instanceof Block) && !(ifStatement.getElseStatement() instanceof Block); } else if (nodeType == ASTNode.FOR_STATEMENT) { return !(((ForStatement)statement).getBody() instanceof Block); } else if (nodeType == ASTNode.WHILE_STATEMENT) { return !(((WhileStatement)statement).getBody() instanceof Block); } return false; }
Example 5
Source File: InputFlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(IfStatement node) { if (skipNode(node)) { return; } Statement thenPart = node.getThenStatement(); Statement elsePart = node.getElseStatement(); if ((thenPart != null && fSelection.coveredBy(thenPart)) || (elsePart != null && fSelection.coveredBy(elsePart))) { GenericSequentialFlowInfo info = createSequential(); setFlowInfo(node, info); endVisitConditional(info, node.getExpression(), new ASTNode[] { thenPart, elsePart }); } else { super.endVisit(node); } }
Example 6
Source File: InputFlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(IfStatement node) { if (skipNode(node)) return; Statement thenPart= node.getThenStatement(); Statement elsePart= node.getElseStatement(); if ((thenPart != null && fSelection.coveredBy(thenPart)) || (elsePart != null && fSelection.coveredBy(elsePart))) { GenericSequentialFlowInfo info= createSequential(); setFlowInfo(node, info); endVisitConditional(info, node.getExpression(), new ASTNode[] {thenPart, elsePart}); } else { super.endVisit(node); } }
Example 7
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean getInverseIfProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) { if (!(covering instanceof IfStatement)) { return false; } IfStatement ifStatement= (IfStatement) covering; if (ifStatement.getElseStatement() == null) { return false; } // we could produce quick assist if (resultingCollections == null) { return true; } // AST ast= covering.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); Statement thenStatement= ifStatement.getThenStatement(); Statement elseStatement= ifStatement.getElseStatement(); // prepare original nodes Expression inversedExpression= getInversedExpression(rewrite, ifStatement.getExpression()); Statement newElseStatement= (Statement) rewrite.createMoveTarget(thenStatement); Statement newThenStatement= (Statement) rewrite.createMoveTarget(elseStatement); // set new nodes rewrite.set(ifStatement, IfStatement.EXPRESSION_PROPERTY, inversedExpression, null); if (elseStatement instanceof IfStatement) {// bug 79507 && bug 74580 Block elseBlock= ast.newBlock(); elseBlock.statements().add(newThenStatement); newThenStatement= elseBlock; } rewrite.set(ifStatement, IfStatement.THEN_STATEMENT_PROPERTY, newThenStatement, null); rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, newElseStatement, null); // add correction proposal String label= CorrectionMessages.AdvancedQuickAssistProcessor_inverseIf_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INVERSE_IF_STATEMENT, image); resultingCollections.add(proposal); return true; }