PsiVariable (TerminalBlock tb, List<PsiVariable> variables, OperationReductionMigration.ReductionOperation operation) { IElementType compoundAssignmentOp = operation.getCompoundAssignmentOp(); // have only one non-final variable if (variables.size() != 1) return null; PsiAssignmentExpression assignment = tb.getSingleExpression(PsiAssignmentExpression.class); if (assignment == null) return null; PsiVariable var = extractAccumulator(assignment, compoundAssignmentOp); // the referred variable is the same as non-final variable if (var == null || !variables.contains(var)) return null; if (!operation.getAccumulatorRestriction().test(var)) return null; // the referred variable is not used in intermediate operations if (tb.isReferencedInOperations(var)) return null; PsiExpression operand = extractOperand(assignment, compoundAssignmentOp); LOG.assertTrue(operand != null); if (VariableAccessUtils.variableIsUsed(var, operand)) return null; return var; }