CompareInfo (PsiIfStatement ifStatement) { PsiExpression firstCondition = ifStatement.getCondition(); if (firstCondition == null) return null; PsiIfStatement elseIfStatement = tryCast(getElse(ifStatement), PsiIfStatement.class); if (elseIfStatement == null) return null; PsiExpression secondCondition = elseIfStatement.getCondition(); if (secondCondition == null) return null; PsiStatement firstStatement = ControlFlowUtils.stripBraces(ifStatement.getThenBranch()); if (firstStatement == null) return null; PsiStatement secondStatement = ControlFlowUtils.stripBraces(elseIfStatement.getThenBranch()); if (secondStatement == null) return null; PsiStatement thirdStatement = getElse(elseIfStatement); if (thirdStatement == null) return null; Map<Integer, PsiExpression> result = new HashMap<>(3); // like if(...) return 1; else if(...) return -1; return 0; if (firstStatement instanceof PsiReturnStatement) { if (!(secondStatement instanceof PsiReturnStatement) || !(thirdStatement instanceof PsiReturnStatement)) return null; PsiExpression firstValue = ((PsiReturnStatement)firstStatement).getReturnValue(); if (!storeCondition(result, firstCondition, firstValue)) return null; if (!storeCondition(result, secondCondition, ((PsiReturnStatement)secondStatement).getReturnValue())) return null; if (!storeCondition(result, null, ((PsiReturnStatement)thirdStatement).getReturnValue())) return null; return fromMap(result, firstValue, firstStatement); } // like if(...) x = 1; else if(...) x = -1; else x = 0; PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(firstStatement); if (assignment == null) return null; PsiReferenceExpression ref = tryCast(assignment.getLExpression(), PsiReferenceExpression.class); if (ref == null) return null; PsiVariable variable = tryCast(ref.resolve(), PsiVariable.class); if (variable == null) return null; PsiExpression firstExpression = assignment.getRExpression(); if (!storeCondition(result, firstCondition, firstExpression)) return null; if (!storeCondition(result, secondCondition, ExpressionUtils.getAssignmentTo(secondStatement, variable))) return null; if (!storeCondition(result, null, ExpressionUtils.getAssignmentTo(thirdStatement, variable))) return null; return fromMap(result, firstExpression, firstStatement); }