lambda -> method ref: disable for inapplicable target methods (IDEA-103369)

(cherry picked from commit c05e901232c17e1a93a7024e5d7262d6a324c5e3)
This commit is contained in:
anna
2013-03-19 19:50:47 +01:00
parent caec968429
commit a1753089fe
4 changed files with 49 additions and 1 deletions

View File

@@ -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;
}
}
}
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}