PsiElement (PsiElement expression, PsiType type) { String canonicalText = type.getCanonicalText(); if (!PsiUtil.isLanguageLevel8OrHigher(expression)) { final String arrayInitializer = "new " + canonicalText + "[]{0}"; PsiNewExpression newExpr = (PsiNewExpression)JavaPsiFacade.getElementFactory(expression.getProject()) .createExpressionFromText(arrayInitializer, expression); final PsiArrayInitializerExpression initializer = newExpr.getArrayInitializer(); LOG.assertTrue(initializer != null); return initializer.getInitializers()[0].replace(expression); } final String callableWithExpectedType = "(java.util.concurrent.Callable<" + canonicalText + ">)() -> x"; PsiTypeCastExpression typeCastExpr = (PsiTypeCastExpression)JavaPsiFacade.getElementFactory(expression.getProject()) .createExpressionFromText(callableWithExpectedType, expression); PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)typeCastExpr.getOperand(); LOG.assertTrue(lambdaExpression != null); PsiElement body = lambdaExpression.getBody(); LOG.assertTrue(body instanceof PsiExpression); return body.replace(expression); }