PsiCall (PsiCall expression, PsiType typeByParent) { PsiElement encoded = null; try { if (typeByParent != null && PsiTypesUtil.isDenotableType(typeByParent, expression)) { RecaptureTypeMapper.encode(encoded = expression); return (PsiCall)LambdaUtil.copyWithExpectedType(expression, typeByParent); } else { final PsiCall call = LambdaUtil.treeWalkUp(expression); if (call != null) { RecaptureTypeMapper.encode(encoded = call); Object marker = new Object(); PsiTreeUtil.mark(expression, marker); final PsiCall callCopy = LambdaUtil.copyTopLevelCall(call); if (callCopy == null) return null; return (PsiCall)PsiTreeUtil.releaseMark(callCopy, marker); } else { //it is possible that in several cases there is not enough context, let's add more ParentPathContext contextParent = getContextParent(expression); if (contextParent != null && contextParent.hasPath()) { RecaptureTypeMapper.encode(encoded = contextParent.parent()); PsiElement copy = contextParent.getElementCopy(); if (copy instanceof PsiCall psiCall) { return psiCall; } else { return null; } } RecaptureTypeMapper.encode(encoded = expression); return (PsiCall)expression.copy(); } } } catch (IllegalArgumentException e) { return null; } finally { if (encoded != null) { RecaptureTypeMapper.clean(encoded); } } }