Java inspection: Update messages related to forEachOrdered() in the inspection "Replace coll.stream().forEachOrdered(..) with coll.forEach(..)"

This commit is contained in:
Pavel Dolgov
2016-06-30 13:59:37 +03:00
parent 9211066622
commit c345c002a2
4 changed files with 19 additions and 9 deletions
@@ -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
@@ -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;
@@ -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;
@@ -1,8 +1,11 @@
<html>
<body>
This inspection reports stream API call chains which can be simplified.
It allows to avoid creating redundant temporary objects without changing semantics.
<br>
For example, Collection.stream().forEach() can be replaced with Collection.forEach()
It allows to avoid creating redundant temporary objects when traversing a collection.
<p>
For example, <b>Collection.stream().forEach()</b> can be replaced with <b>Collection.forEach()</b>.
<p>
Note that <b>forEachOrdered()</b> is a special case. While the traversal order of <b>Collection.forEach()</b> is usually the same as with
<b>Collection.stream().forEachOrdered()</b>, specific implementations may override that. Please check the documentation on the collection's implementation.
</body>
</html>