Comparison (@NotNull PsiExpression lOperand, @NotNull PsiExpression rOperand, @NotNull PsiVariable loopVariable, boolean isGreater, @Nullable PsiVariable comparator, boolean externalComparison) { final boolean max; final PsiExpression extremumExpr; final PsiExpression loopVarExpr; if (ReferencesSearch.search(loopVariable, new LocalSearchScope(lOperand)).findFirst() != null) { max = isGreater; loopVarExpr = lOperand; extremumExpr = rOperand; } else if (ReferencesSearch.search(loopVariable, new LocalSearchScope(rOperand)).findFirst() != null) { max = !isGreater; loopVarExpr = rOperand; extremumExpr = lOperand; } else { return null; } return new Comparison(extremumExpr, loopVarExpr, max, comparator, externalComparison); }