mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
EA-68330 - AIOOBE: RedundantLambdaParameterTypeIntention.isAvailable
process lambdas with formal param types at vararg position
This commit is contained in:
+14
-2
@@ -81,15 +81,27 @@ public class RedundantLambdaParameterTypeIntention extends PsiElementBaseIntenti
|
||||
return parameter.getName();
|
||||
}
|
||||
}, ", ") + ") -> {}", expression);
|
||||
final PsiParameter[] methodParams = method.getParameterList().getParameters();
|
||||
final PsiSubstitutor substitutor = javaPsiFacade.getResolveHelper()
|
||||
.inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(),
|
||||
.inferTypeArguments(typeParameters, methodParams, arguments, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(),
|
||||
gParent, DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
|
||||
for (PsiTypeParameter parameter : typeParameters) {
|
||||
final PsiType psiType = substitutor.substitute(parameter);
|
||||
if (psiType == null || dependsOnTypeParams(psiType, expression, parameter)) return false;
|
||||
}
|
||||
return functionalInterfaceType.isAssignableFrom(substitutor.substitute(method.getParameterList().getParameters()[idx].getType()));
|
||||
|
||||
|
||||
final PsiType paramType;
|
||||
if (idx < methodParams.length) {
|
||||
paramType = methodParams[idx].getType();
|
||||
}
|
||||
else {
|
||||
final PsiParameter lastParam = methodParams[methodParams.length - 1];
|
||||
if (!lastParam.isVarArgs()) return false;
|
||||
paramType = ((PsiEllipsisType)lastParam.getType()).getComponentType();
|
||||
}
|
||||
return functionalInterfaceType.isAssignableFrom(substitutor.substitute(paramType));
|
||||
}
|
||||
}
|
||||
if (!LambdaUtil.isLambdaFullyInferred(expression, functionalInterfaceType)) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove redundant types" "false"
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
<K> void f(Function<K, String>... l){}
|
||||
|
||||
{
|
||||
f(null, (Str<caret>ing s) -> s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user