lambda -> method refs: collapse when acceptable method without supers found

This commit is contained in:
Anna Kozlova
2014-07-21 20:47:52 +02:00
parent dd4ddfb83f
commit bacc3c2ad6
3 changed files with 29 additions and 4 deletions

View File

@@ -245,11 +245,14 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
PsiParameter[] candidateParams = method.getParameterList().getParameters();
if (candidateParams.length == 1) {
if (TypeConversionUtil.areTypesConvertible(candidateParams[0].getType(), parameters[0].getType())) {
for (PsiMethod superMethod : psiMethod.findDeepestSuperMethods()) {
PsiMethod validSuperMethod = ensureNonAmbiguousMethod(parameters, superMethod);
if (validSuperMethod != null) return validSuperMethod;
final PsiMethod[] deepestSuperMethods = psiMethod.findDeepestSuperMethods();
if (deepestSuperMethods.length > 0) {
for (PsiMethod superMethod : deepestSuperMethods) {
PsiMethod validSuperMethod = ensureNonAmbiguousMethod(parameters, superMethod);
if (validSuperMethod != null) return validSuperMethod;
}
return null;
}
return null;
}
}
}

View File

@@ -0,0 +1,11 @@
// "Replace lambda with method reference" "true"
import java.io.PrintStream;
import java.util.function.BiConsumer;
class Test {
{
BiConsumer<PrintStream, String> printer = PrintStream::println;
}
}

View File

@@ -0,0 +1,11 @@
// "Replace lambda with method reference" "true"
import java.io.PrintStream;
import java.util.function.BiConsumer;
class Test {
{
BiConsumer<PrintStream, String> printer = (printStream, x) -> printSt<caret>ream.println(x);
}
}