BaseStreamApiMigration (TerminalBlock tb, List<PsiVariable> nonFinalVariables, PsiStatement statement, boolean replaceTrivialForEach) { boolean shouldWarn = replaceTrivialForEach || tb.hasOperations(); if (ReferencesSearch.search(tb.getVariable(), new LocalSearchScope(statement)).findFirst() == null) { return new MatchMigration(shouldWarn, "anyMatch()/noneMatch()/allMatch"); } if (nonFinalVariables.isEmpty() && statement instanceof PsiExpressionStatement) { return new FindFirstMigration(shouldWarn); } if (nonFinalVariables.size() == 1) { PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(statement); if (assignment == null) return null; PsiReferenceExpression lValue = tryCast(assignment.getLExpression(), PsiReferenceExpression.class); if (lValue == null) return null; PsiVariable var = tryCast(lValue.resolve(), PsiVariable.class); if (var == null || !nonFinalVariables.contains(var)) return null; PsiExpression rValue = assignment.getRExpression(); if (rValue == null || VariableAccessUtils.variableIsUsed(var, rValue)) return null; if (tb.getVariable().getType() instanceof PsiPrimitiveType && !ExpressionUtils.isReferenceTo(rValue, tb.getVariable())) return null; return new FindFirstMigration(shouldWarn); } return null; }