diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/SimplifyStreamApiCallChainsInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/SimplifyStreamApiCallChainsInspection.java index 0a746484b2b1..6f8e1eb7398b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/SimplifyStreamApiCallChainsInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/SimplifyStreamApiCallChainsInspection.java @@ -81,9 +81,16 @@ public class SimplifyStreamApiCallChainsInspection extends BaseJavaBatchLocalIns } final PsiMethodCallExpression qualifierCall = getQualifierMethodCall(methodCall); if (isCallOf(qualifierCall, CommonClassNames.JAVA_UTIL_COLLECTION, STREAM_METHOD, 0)) { - holder.registerProblem(methodCall, getCallChainRange(methodCall, qualifierCall), - "Collection.stream()." + name + "() can be replaced with Collection.forEach()", - FOR_EACH_METHOD.equals(name) ? new CollectionForEachFix() : new CollectionForEachOrderedFix()); + String message = "Collection.stream()." + name + "() can be replaced with Collection.forEach()"; + final LocalQuickFix fix; + if (FOR_EACH_METHOD.equals(name)) { + fix = new CollectionForEachFix(); + } + else { + fix = new CollectionForEachOrderedFix(); + message += " (may change semantics)"; + } + holder.registerProblem(methodCall, getCallChainRange(methodCall, qualifierCall), message, fix); } } } @@ -221,7 +228,7 @@ public class SimplifyStreamApiCallChainsInspection extends BaseJavaBatchLocalIns @NotNull @Override public String getFamilyName() { - return "Replace Collection.stream()." + FOR_EACH_ORDERED_METHOD + "() with Collection.forEach()"; + return "Replace Collection.stream()." + FOR_EACH_ORDERED_METHOD + "() with Collection.forEach() (may change semantics)"; } @Override diff --git a/java/java-tests/testData/inspection/streamApiCallChains/afterStreamForEachOrderedLambda.java b/java/java-tests/testData/inspection/streamApiCallChains/afterStreamForEachOrderedLambda.java index a2ae9e88a405..2e0de8745474 100644 --- a/java/java-tests/testData/inspection/streamApiCallChains/afterStreamForEachOrderedLambda.java +++ b/java/java-tests/testData/inspection/streamApiCallChains/afterStreamForEachOrderedLambda.java @@ -1,4 +1,4 @@ -// "Replace Collection.stream().forEachOrdered() with Collection.forEach()" "true" +// "Replace Collection.stream().forEachOrdered() with Collection.forEach() (may change semantics)" "true" import java.util.Arrays; diff --git a/java/java-tests/testData/inspection/streamApiCallChains/beforeStreamForEachOrderedLambda.java b/java/java-tests/testData/inspection/streamApiCallChains/beforeStreamForEachOrderedLambda.java index 60747336dd24..f4cbfa406fba 100644 --- a/java/java-tests/testData/inspection/streamApiCallChains/beforeStreamForEachOrderedLambda.java +++ b/java/java-tests/testData/inspection/streamApiCallChains/beforeStreamForEachOrderedLambda.java @@ -1,4 +1,4 @@ -// "Replace Collection.stream().forEachOrdered() with Collection.forEach()" "true" +// "Replace Collection.stream().forEachOrdered() with Collection.forEach() (may change semantics)" "true" import java.util.Arrays; diff --git a/resources-en/src/inspectionDescriptions/SimplifyStreamApiCallChains.html b/resources-en/src/inspectionDescriptions/SimplifyStreamApiCallChains.html index 692945ed15a2..67879aed0911 100644 --- a/resources-en/src/inspectionDescriptions/SimplifyStreamApiCallChains.html +++ b/resources-en/src/inspectionDescriptions/SimplifyStreamApiCallChains.html @@ -1,8 +1,11 @@ This inspection reports stream API call chains which can be simplified. -It allows to avoid creating redundant temporary objects without changing semantics. -
-For example, Collection.stream().forEach() can be replaced with Collection.forEach() +It allows to avoid creating redundant temporary objects when traversing a collection. +

+For example, Collection.stream().forEach() can be replaced with Collection.forEach(). +

+Note that forEachOrdered() is a special case. While the traversal order of Collection.forEach() is usually the same as with +Collection.stream().forEachOrdered(), specific implementations may override that. Please check the documentation on the collection's implementation. \ No newline at end of file