mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
lambda -> method refs: collapse when acceptable method without supers found
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user