mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java 1.8, stream api migration: convert to method refs
This commit is contained in:
+11
-1
@@ -261,7 +261,17 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
iteration += ".filter(" + parameter.getName() + " -> " + condition.getText() +")";
|
||||
}
|
||||
}
|
||||
iteration +=".map(" + parameter.getName() + " -> " + methodCallExpression.getArgumentList().getExpressions()[0].getText() + ").collect(java.util.stream.Collectors.";
|
||||
iteration +=".map(";
|
||||
|
||||
final PsiExpression mapperCall = methodCallExpression.getArgumentList().getExpressions()[0];
|
||||
|
||||
final String methodReferenceText = LambdaCanBeMethodReferenceInspection.createMethodReferenceText(mapperCall, null, new PsiParameter[]{parameter});
|
||||
if (methodReferenceText != null) {
|
||||
iteration += methodReferenceText;
|
||||
} else {
|
||||
iteration += parameter.getName() + " -> " + mapperCall.getText();
|
||||
}
|
||||
iteration += ").collect(java.util.stream.Collectors.";
|
||||
|
||||
String variableName = null;
|
||||
PsiExpression initializer = null;
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toList());
|
||||
List<String> names = persons.stream().map(person::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<String> names = persons.stream().filter(person -> person != null).map(person -> person.getName()).collect(Collectors.toList());
|
||||
List<String> names = persons.stream().filter(person -> person != null).map(person::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Collect {
|
||||
class Person {
|
||||
String getName() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<String> names = persons.stream().map(person -> "name: " + person.getName()).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
Set<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toSet());
|
||||
Set<String> names = persons.stream().map(person::getName).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,6 +11,6 @@ public class Collect {
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
void collectNames(List<Person> persons){
|
||||
names.addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
|
||||
names.addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
Set<String> names = persons.stream().map(person -> person.getName()).collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
|
||||
Set<String> names = persons.stream().map(person::getName).collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ public abstract class Collect implements Collection<String>{
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
|
||||
addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons, Set<String> names){
|
||||
names.addAll(persons.stream().map(person -> person.getName()).collect(Collectors.toList()));
|
||||
names.addAll(persons.stream().map(person::getName).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {
|
||||
String getName() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Person person : pers<caret>ons) {
|
||||
names.add("name: " + person.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user