PsiStatement (@NotNull Project project, @NotNull PsiElementFactory factory) { @NonNls String replacementText = myVoidMode ? "{a;}" : "{return a;}"; PsiCodeBlock newBody = factory.createCodeBlockFromText(replacementText, myLambda); LambdaUtil.extractSingleExpressionFromBody(newBody).replace(Objects.requireNonNull(myLambda.getBody())); newBody = (PsiCodeBlock)myLambda.getBody().replace(newBody); return newBody.getStatements()[0]; // either expression statement or return statement }