mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-184154 Use Comparator combinator fix produces red code
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
public class MyTest {
|
||||
void setComparator(Comparator<?> comparator) {
|
||||
}
|
||||
|
||||
String getValue() {
|
||||
return "";
|
||||
}
|
||||
|
||||
{
|
||||
setComparator(Comparator.comparing(MyTest::getValue));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
public class MyTest {
|
||||
void setComparator(Comparator<?> comparator) {
|
||||
}
|
||||
|
||||
String getValue(int x) {
|
||||
return "";
|
||||
}
|
||||
|
||||
{
|
||||
setComparator(Comparator.comparing((MyTest o) -> o.getValue(0)));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
public class MyTest {
|
||||
void setComparator(Comparator<?> comparator) {
|
||||
}
|
||||
|
||||
String getValue() {
|
||||
return "";
|
||||
}
|
||||
|
||||
{
|
||||
setComparator((MyTest o1, <caret>MyTest o2) -> o1.getValue().compareTo(o2.getValue()));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
public class MyTest {
|
||||
void setComparator(Comparator<?> comparator) {
|
||||
}
|
||||
|
||||
String getValue(int x) {
|
||||
return "";
|
||||
}
|
||||
|
||||
{
|
||||
setComparator((MyTest o1, <caret>MyTest o2) -> o1.getValue(0).compareTo(o2.getValue(0)));
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -334,13 +334,16 @@ public class ComparatorCombinatorsInspection extends AbstractBaseJavaLocalInspec
|
||||
return null;
|
||||
}
|
||||
if (methodName == null) return null;
|
||||
String parameterName = leftVar.getName();
|
||||
String text;
|
||||
if (!methodName.startsWith("comparing")) {
|
||||
text = "java.util.Comparator." + methodName + "()";
|
||||
}
|
||||
else {
|
||||
text = "java.util.Comparator." + methodName + "(" + (parameterName + " -> " + left.getText()) + ")";
|
||||
String parameterName = leftVar.getName();
|
||||
PsiTypeElement typeElement = leftVar.getTypeElement();
|
||||
String parameterDeclaration = typeElement == null ? parameterName : "(" + typeElement.getText() + " " + parameterName + ")";
|
||||
text = "java.util.Comparator." + methodName + "(" +
|
||||
(parameterDeclaration + " -> " + left.getText()) + ")";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user