mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
lambda -> method ref: disable for inapplicable target methods (IDEA-103369)
(cherry picked from commit c05e901232c17e1a93a7024e5d7262d6a324c5e3)
This commit is contained in:
@@ -189,7 +189,13 @@ public class LambdaCanBeMethReferenceInspection extends BaseJavaLocalInspectionT
|
||||
} else if (methodCall instanceof PsiNewExpression) {
|
||||
final PsiExpression[] dimensions = ((PsiNewExpression)methodCall).getArrayDimensions();
|
||||
if (dimensions.length > 0) {
|
||||
return methodCall;
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
|
||||
if (interfaceMethod != null) {
|
||||
final PsiParameter[] psiParameters = interfaceMethod.getParameterList().getParameters();
|
||||
if (psiParameters.length == 1 && PsiType.INT.equals(psiParameters[0].getType())) {
|
||||
return methodCall;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace lambda with method reference" "true"
|
||||
class Example {
|
||||
{
|
||||
long[][] avg = collect(long[][]::new);
|
||||
}
|
||||
|
||||
interface P<T> {
|
||||
T _(int i);
|
||||
}
|
||||
|
||||
<T> T collect(P<T> p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace lambda with method reference" "true"
|
||||
class Example {
|
||||
{
|
||||
long[][] avg = collect((int i) -> new <caret>long[i][]);
|
||||
}
|
||||
|
||||
interface P<T> {
|
||||
T _(int i);
|
||||
}
|
||||
|
||||
<T> T collect(P<T> p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace lambda with method reference" "false"
|
||||
class Example {
|
||||
{
|
||||
long[] avg = collect(() -> new <caret>long[]);
|
||||
}
|
||||
|
||||
interface P<T> {
|
||||
T _();
|
||||
}
|
||||
|
||||
<T> T collect(P<T> p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user