IDEA-161007 Add new inspection to make comparator lambdas use Comparator.comparing() combinators (Currently only simple comparators supported)

This commit is contained in:
Tagir Valeev
2016-09-12 17:50:47 +07:00
parent 34ed877b9d
commit dc37f19e2b
9 changed files with 252 additions and 34 deletions
@@ -0,0 +1,14 @@
// "Replace with Comparator.comparing" "true"
import java.util.Comparator;
import java.util.List;
public class Main {
interface Person {
String getName();
}
void sort(List<Person> persons) {
persons.sort(Comparator.comparing(Person::getName));
}
}
@@ -0,0 +1,13 @@
// "Replace with Comparator.comparing" "false"
import java.util.List;
public class Main {
interface Person {
String getName();
}
void sort(List<Person> persons) {
persons.sort((p1, p2) -> p2.getNam<caret>e().compareTo(p1.getName()));
}
}
@@ -0,0 +1,13 @@
// "Replace with Comparator.comparing" "true"
import java.util.List;
public class Main {
interface Person {
String getName();
}
void sort(List<Person> persons) {
persons.sort((p1, p2) -> p1.getNam<caret>e().compareTo(p2.getName()));
}
}