From a3d842b104434846979802be935b324c14f2d533 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 9 Feb 2016 12:03:41 +0100 Subject: [PATCH] convert to streams: disable foreachOrdered for pure collections (without filter) --- .../codeInspection/StreamApiMigrationInspection.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java index e6851105c7ae..66e035b626e8 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/StreamApiMigrationInspection.java @@ -132,10 +132,15 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo new ReplaceWithCollectCallFix("Replace with " + (addAll ? "addAll" : "collect"))); } else if (REPLACE_TRIVIAL_FOREACH || !isTrivial(body, statement.getIterationParameter())) { + final List fixes = new ArrayList(); + fixes.add(new ReplaceWithForeachCallFix("forEach")); + if (extractIfStatement(body) != null) { + //for .stream() + fixes.add(new ReplaceWithForeachCallFix("forEachOrdered")); + } holder.registerProblem(iteratedValue, "Can be replaced with foreach call", - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - new ReplaceWithForeachCallFix("forEach"), - new ReplaceWithForeachCallFix("forEachOrdered")); + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + fixes.toArray(new LocalQuickFix[fixes.size()])); } } }