EA-57951 - AIOOBE: AnonymousCanBeLambdaInspection.getInferredType

anonymous -> lambda on varargs place
This commit is contained in:
Anna Kozlova
2014-07-23 20:54:35 +02:00
parent 91a3b9aee8
commit 4a6095476f
3 changed files with 36 additions and 1 deletions

View File

@@ -141,7 +141,19 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
.inferTypeArguments(method.getTypeParameters(), parameters, expressions,
((MethodCandidateInfo)result).getSiteSubstitutor(), callExpr.getParent(),
DefaultParameterTypeInferencePolicy.INSTANCE);
return substitutor.substitute(parameters[i].getType());
PsiType paramType;
if (i < parameters.length) {
paramType = parameters[i].getType();
}
else {
paramType = parameters[parameters.length - 1].getType();
if (!(paramType instanceof PsiEllipsisType)) {
return null;
}
paramType = ((PsiEllipsisType)paramType).getComponentType();
}
return substitutor.substitute(paramType);
}
}
}

View File

@@ -0,0 +1,10 @@
// "Replace with lambda" "true"
class Test2 {
void f(Runnable... rs){}
{
f(null, () -> {
});
}
}

View File

@@ -0,0 +1,13 @@
// "Replace with lambda" "true"
class Test2 {
void f(Runnable... rs){}
{
f(null, new Run<caret>nable() {
@Override
public void run() {
}
});
}
}