BaseStreamApiMigration (PsiStatement statement, TerminalBlock tb, boolean replaceTrivialForEach) { boolean shouldWarn = replaceTrivialForEach || tb.hasOperations(); PsiReturnStatement returnStatement = (PsiReturnStatement)tb.getSingleStatement(); if (returnStatement == null) return null; PsiExpression value = PsiUtil.skipParenthesizedExprDown(returnStatement.getReturnValue()); PsiReturnStatement nextReturnStatement = ControlFlowUtils.getNextReturnStatement(statement); if (nextReturnStatement != null && value instanceof PsiLiteralExpression) { Boolean foundResult = tryCast(((PsiLiteralExpression)value).getValue(), Boolean.class); if (foundResult != null) { String methodName; if (foundResult) { methodName = "anyMatch"; } else { methodName = "noneMatch"; FilterOp lastFilter = tb.getLastOperation(FilterOp.class); if (lastFilter != null && (lastFilter.isNegated() ^ BoolUtils.isNegation(lastFilter.getExpression()))) { methodName = "allMatch"; } } if (nextReturnStatement.getParent() == statement.getParent() || ExpressionUtils.isLiteral(nextReturnStatement.getReturnValue(), !foundResult)) { return new MatchMigration(shouldWarn, methodName); } } } if (!VariableAccessUtils.variableIsUsed(tb.getVariable(), value)) { if (!replaceTrivialForEach && !tb.hasOperations() || (tb.getLastOperation() instanceof FilterOp && tb.operations().count() == 2)) { return null; } return new MatchMigration(shouldWarn, "anyMatch"); } if (nextReturnStatement != null && ExpressionUtils.isSafelyRecomputableExpression(nextReturnStatement.getReturnValue()) && (!(tb.getVariable().getType() instanceof PsiPrimitiveType) || ExpressionUtils.isReferenceTo(value, tb.getVariable()))) { return new FindFirstMigration(shouldWarn); } return null; }