ComparisonBlock (@NotNull PsiVariable first, @NotNull PsiVariable second, PsiVariable lastResult, PsiExpression returnExpr) { PsiConditionalExpression ternary = tryCast(returnExpr, PsiConditionalExpression.class); if (ternary == null) return null; PsiExpression elseExpression = ternary.getElseExpression(); PsiExpression thenExpression = ternary.getThenExpression(); if (elseExpression == null || thenExpression == null) return null; PsiBinaryExpression binOp = tryCast(ternary.getCondition(), PsiBinaryExpression.class); if (binOp == null) return null; PsiExpression finalResult = ExpressionUtils.getValueComparedWithZero(binOp); boolean inverted = false; if (finalResult == null) { finalResult = ExpressionUtils.getValueComparedWithZero(binOp, JavaTokenType.NE); inverted = true; } if (!ExpressionUtils.isReferenceTo(finalResult, lastResult)) return null; if (!ExpressionUtils.isReferenceTo(inverted ? thenExpression : elseExpression, lastResult)) return null; PsiMethodCallExpression lastComparison = tryCast(inverted ? elseExpression : thenExpression, PsiMethodCallExpression.class); ComparisonBlock lastBlock = ComparisonBlock.extractBlock(lastComparison, first, second, lastResult); if (lastBlock == null) return null; return lastBlock; }