private static boolean ifStatementsAreEquivalent( @NotNull GrIfStatement statement1, @NotNull GrIfStatement statement2) { final GrExpression condition1 = statement1.getCondition(); final GrExpression condition2 = statement2.getCondition(); final GrStatement thenBranch1 = statement1.getThenBranch(); final GrStatement thenBranch2 = statement2.getThenBranch(); final GrStatement elseBranch1 = statement1.getElseBranch(); final GrStatement elseBranch2 = statement2.getElseBranch(); return expressionsAreEquivalent(condition1, condition2) && statementsAreEquivalent(thenBranch1, thenBranch2) && statementsAreEquivalent(elseBranch1, elseBranch2); }
public void visitIfStatement(GrIfStatement ifStatement) { InstructionImpl ifInstruction = startNode(ifStatement); final GrCondition condition = ifStatement.getCondition(); final GrStatement thenBranch = ifStatement.getThenBranch(); final GrStatement elseBranch = ifStatement.getElseBranch(); InstructionImpl conditionEnd = null; InstructionImpl thenEnd = null; InstructionImpl elseEnd = null; if (condition != null) { condition.accept(this); conditionEnd = myHead; } List<GotoInstruction> negations = collectAndRemoveAllPendingNegations(ifStatement); if (thenBranch != null) { thenBranch.accept(this); handlePossibleReturn(thenBranch); thenEnd = myHead; interruptFlow(); readdPendingEdge(ifStatement); } myHead = reduceAllNegationsIntoInstruction(ifStatement, negations); if (myHead == null && conditionEnd != null) { myHead = conditionEnd; } if (elseBranch != null) { elseBranch.accept(this); handlePossibleReturn(elseBranch); elseEnd = myHead; interruptFlow(); } if (thenBranch != null || elseBranch != null) { if (thenEnd != null || elseEnd != null || elseBranch == null) { final InstructionImpl end = new IfEndInstruction(ifStatement); addNode(end); if (thenEnd != null) { addEdge(thenEnd, end); } if (elseEnd != null) { addEdge(elseEnd, end); } else if (elseBranch == null) { addEdge(conditionEnd != null ? conditionEnd : ifInstruction, end); } } } finishNode(ifInstruction); }
public void visitIfStatement(GrIfStatement ifStatement) { if (myExpression.equals(ifStatement.getCondition())) { myResult = new TypeConstraint[] { new SubtypeConstraint(TypesUtil.getJavaLangObject(ifStatement), PsiType.BOOLEAN) }; } else if (myExpression.equals(ifStatement.getThenBranch()) || myExpression.equals(ifStatement.getElseBranch())) { checkExitPoint(); } }
private static Indent getControlIndent(PsiElement parent, ASTNode child) { final PsiElement psi = child.getPsi(); final IElementType type = child.getElementType(); if (parent instanceof GrIfStatement) { final GrIfStatement ifStatement = (GrIfStatement) parent; if (!BLOCK_SET.contains(type)) { if (psi.equals(ifStatement.getThenBranch())) { return Indent.getNormalIndent(); } if (psi.equals(ifStatement.getElseBranch())) { if (getGroovySettings(parent).SPECIAL_ELSE_IF_TREATMENT && psi instanceof GrIfStatement) { return Indent.getNoneIndent(); } return Indent.getNormalIndent(); } } if (psi.equals(ifStatement.getCondition())) { return Indent.getContinuationWithoutFirstIndent(); } } if (parent instanceof GrWhileStatement) { if (psi.equals(((GrWhileStatement) parent).getBody()) && !BLOCK_SET.contains(type)) { return Indent.getNormalIndent(); } if (psi.equals(((GrWhileStatement) parent).getCondition())) { return Indent.getContinuationWithoutFirstIndent(); } } if (parent instanceof GrSynchronizedStatement) { if (psi.equals(((GrSynchronizedStatement) parent).getMonitor())) { return Indent.getContinuationWithoutFirstIndent(); } } if (parent instanceof GrForStatement) { if (psi.equals(((GrForStatement) parent).getBody()) && !BLOCK_SET.contains(type)) { return Indent.getNormalIndent(); } if (psi.equals(((GrForStatement) parent).getClause())) { return Indent.getContinuationWithoutFirstIndent(); } } return Indent.getNoneIndent(); }