void (PsiLambdaExpression element) { CodeBlockSurrounder surrounder = CodeBlockSurrounder.forExpression(element); if (surrounder == null) return; CodeBlockSurrounder.SurroundResult result = surrounder.surround(); element = (PsiLambdaExpression)result.getExpression(); PsiElement body = element.getBody(); if (!(body instanceof PsiCodeBlock)) return; PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class); if (callExpression == null) return; final CommentTracker ct = new CommentTracker(); inlineCallArguments(callExpression, element, ct); body = element.getBody(); final PsiElement parent = callExpression.getParent(); final PsiStatement[] statements = ((PsiCodeBlock)body).getStatements(); PsiReturnStatement statement = null; if (statements.length > 0) { PsiElement anchor = result.getAnchor(); statement = ObjectUtils.tryCast(statements[statements.length - 1], PsiReturnStatement.class); PsiElement gParent = anchor.getParent(); solveNameConflicts(statements, anchor, element); for (PsiElement child = body.getFirstChild(); child != null; child = child.getNextSibling()) { if (child != statement && !(child instanceof PsiJavaToken)) { gParent.addBefore(ct.markUnchanged(child), anchor); } } } final PsiExpression returnValue = statement == null ? null : statement.getReturnValue(); if (returnValue != null) { ct.replaceAndRestoreComments(callExpression, returnValue); } else { if (parent instanceof PsiExpressionStatement) { ct.deleteAndRestoreComments(callExpression); } else { ct.deleteAndRestoreComments(parent); } } }