lambda -> method reference: exclude receiver/non-receiver ambiguity (IDEA-129924)

This commit is contained in:
Anna Kozlova
2014-09-17 20:45:43 +04:00
parent 484efff8b4
commit 3e13cddf2b
2 changed files with 24 additions and 3 deletions
@@ -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;
@@ -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());
}
}