mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda -> method reference: exclude receiver/non-receiver ambiguity (IDEA-129924)
This commit is contained in:
+5
-3
@@ -241,9 +241,11 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
String methodName = psiMethod.getName();
|
||||
PsiClass containingClass = psiMethod.getContainingClass();
|
||||
if (containingClass == null) return null;
|
||||
for (PsiMethod method : containingClass.findMethodsByName(methodName, false)) {
|
||||
final PsiMethod[] psiMethods = containingClass.findMethodsByName(methodName, false);
|
||||
if (psiMethods.length == 1) return psiMethod;
|
||||
for (PsiMethod method : psiMethods) {
|
||||
PsiParameter[] candidateParams = method.getParameterList().getParameters();
|
||||
if (candidateParams.length == 1) {
|
||||
if (candidateParams.length == parameters.length) {
|
||||
if (TypeConversionUtil.areTypesConvertible(candidateParams[0].getType(), parameters[0].getType())) {
|
||||
final PsiMethod[] deepestSuperMethods = psiMethod.findDeepestSuperMethods();
|
||||
if (deepestSuperMethods.length > 0) {
|
||||
@@ -251,9 +253,9 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
PsiMethod validSuperMethod = ensureNonAmbiguousMethod(parameters, superMethod);
|
||||
if (validSuperMethod != null) return validSuperMethod;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return psiMethod;
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace lambda with method reference" "false"
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
class Foo {
|
||||
public String bar() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public static String bar(Foo foo) {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
public void test() {
|
||||
Stream.of(new Foo()).map(e -> e.b<caret>ar());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user