PsiCodeBlock (@NotNull PsiLambdaExpression lambdaExpression) { final PsiElement body = lambdaExpression.getBody(); if (!(body instanceof PsiExpression)) return (PsiCodeBlock)body; @NonNls String newLambdaText = "{"; if (!PsiTypes.voidType().equals(LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression))) newLambdaText += "return "; newLambdaText += "a;}"; final Project project = lambdaExpression.getProject(); final PsiCodeBlock codeBlock = JavaPsiFacade.getElementFactory(project).createCodeBlockFromText(newLambdaText, lambdaExpression); PsiStatement statement = codeBlock.getStatements()[0]; if (statement instanceof PsiReturnStatement) { PsiExpression value = ((PsiReturnStatement)statement).getReturnValue(); LOG.assertTrue(value != null); value.replace(body); } else if (statement instanceof PsiExpressionStatement){ ((PsiExpressionStatement)statement).getExpression().replace(body); } PsiElement arrow = PsiTreeUtil.skipWhitespacesBackward(body); if (arrow != null && arrow.getNextSibling() != body) { lambdaExpression.deleteChildRange(arrow.getNextSibling(), body.getPrevSibling()); } return (PsiCodeBlock)CodeStyleManager.getInstance(project).reformat(body.replace(codeBlock)); }