mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
FuseStreamOperationsInspection: fixes according to review IDEA-CR-24873
1. Code sample in description 2. Supported toCollection with parameterized method-reference
This commit is contained in:
@@ -69,9 +69,9 @@ public class FuseStreamOperationsInspection extends BaseJavaBatchLocalInspection
|
||||
private static PsiClass resolveClassCreatedByFunction(PsiExpression function) {
|
||||
function = PsiUtil.skipParenthesizedExprDown(function);
|
||||
if (function instanceof PsiMethodReferenceExpression && ((PsiMethodReferenceExpression)function).isConstructor()) {
|
||||
PsiExpression qualifier = ((PsiMethodReferenceExpression)function).getQualifierExpression();
|
||||
if (qualifier instanceof PsiReferenceExpression) {
|
||||
return tryCast(((PsiReferenceExpression)qualifier).resolve(), PsiClass.class);
|
||||
PsiMethod constructor = tryCast(((PsiMethodReferenceExpression)function).resolve(), PsiMethod.class);
|
||||
if (constructor != null) {
|
||||
return constructor.getContainingClass();
|
||||
}
|
||||
}
|
||||
if (function instanceof PsiLambdaExpression) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Fuse ArrayList into the Stream API chain" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
void test(Stream<String> stream) {
|
||||
List<Object> objects = stream.distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Fuse ArrayList into the Stream API chain" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
void test(Stream<String> stream) {
|
||||
List<Object> objects = new ArrayList<>(stream.co<caret>llect(Collectors.toCollection(LinkedHashSet<Object>::new)));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
Detects when some transformations are performed on Stream API result which could be incorporated into the Stream API call chain directly.
|
||||
Detects when some transformations are performed on Stream API result which could be incorporated into the Stream API call chain directly. E.g.:
|
||||
<pre>
|
||||
List<String> list = stream.collect(Collectors.toList());
|
||||
list.sort(null);
|
||||
return list.toArray(new String[list.size()]);
|
||||
</pre>
|
||||
Could be converted to
|
||||
<pre>
|
||||
return stream.sorted().toArray(String[]::new);
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.3</small></p>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user