SimpleRefExtremumTerminal (@NotNull PsiExpression nullCheckExpr, @NotNull PsiExpression comparisonExpr, PsiStatement @NotNull [] statements, @NotNull TerminalBlock terminalBlock, @Nullable List<? extends PsiVariable> nonFinalVars) { PsiBinaryExpression nullCheckBinary = tryCast(nullCheckExpr, PsiBinaryExpression.class); if (nullCheckBinary == null) return null; PsiVariable nullCheckingVar = ExpressionUtils.getVariableFromNullComparison(nullCheckBinary, true); if (nullCheckingVar == null) return null; Comparison comparison = Comparison.extract(comparisonExpr, terminalBlock.getVariable(), false); if (comparison == null) return null; if (statements.length != 1) return null; PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(statements[0]); if (assignment == null) return null; PsiVariable extremum = resolveVariableReference(assignment.getLExpression()); PsiVariable loopVariable = resolveVariableReference(assignment.getRExpression()); if (extremum == null || loopVariable == null) return null; if (nullCheckingVar != extremum) return null; if (!loopVariable.equals(terminalBlock.getVariable())) return null; PsiExpression extremumExpr = comparison.getExtremumExpr(); PsiExpression loopVarExpr = comparison.getLoopVarExpr(); String name = extremum.getName(); if (name == null) return null; if (!equalShape(extremumExpr, loopVarExpr, name, terminalBlock.getVariable())) return null; if (mayChangeBeforeLoop(extremum, terminalBlock)) return null; if (nonFinalVars != null) { if (nonFinalVars.size() != 1) return null; if (!nonFinalVars.get(0).equals(extremum)) return null; if (containsAnyVariable(loopVarExpr, nonFinalVars)) return null; } PsiType loopVarExprType = loopVarExpr.getType(); if (!hasKnownComparableType(comparison, loopVarExprType)) return null; boolean max = comparison.isMax(); PsiExpression initializer = extremum.getInitializer(); if (!ExpressionUtils.isNullLiteral(initializer)) return null; return new SimpleRefExtremumTerminal(max, terminalBlock, loopVarExpr, extremum, comparison.getComparator()); }