[java-inspections] isSafeLambdaReplacement: use copyWithExpectedType

GitOrigin-RevId: efdf10a2a346f4c33b18519377e2f6bb0306093d
This commit is contained in:
Tagir Valeev
2021-12-03 12:43:20 +00:00
committed by intellij-monorepo-bot
parent 236350c86a
commit 28deec85d3
@@ -943,11 +943,7 @@ public final class LambdaUtil {
else if (PsiPolyExpressionUtil.isInAssignmentOrInvocationContext(lambda)) {
PsiType origType = lambda.getFunctionalInterfaceType();
if (origType != null) {
Project project = lambda.getProject();
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiDeclarationStatement declaration = factory.createVariableDeclarationStatement("$$$", origType, lambda, lambda);
PsiLocalVariable variable = (PsiLocalVariable)declaration.getDeclaredElements()[0];
PsiLambdaExpression lambdaCopy = (PsiLambdaExpression)variable.getInitializer();
PsiLambdaExpression lambdaCopy = (PsiLambdaExpression)copyWithExpectedType(lambda, origType);
PsiExpression replacement = replacer.apply(lambdaCopy);
PsiType type = replacement.getType();
return type != null && origType.isAssignableFrom(type);