void (@NotNull ActionContext context, @NotNull PsiIdentifier element, @NotNull ModPsiUpdater updater) { PsiMethodCallExpression mapCall = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class); if(mapCall == null) return; PsiMethodCallExpression nextCall = getNextExpressionToMerge(mapCall); if(nextCall == null) return; PsiReferenceExpression nextRef = nextCall.getMethodExpression(); PsiExpression nextQualifier = nextRef.getQualifierExpression(); if(nextQualifier == null) return; String newName = translateName(mapCall, nextCall); if(newName == null) return; PsiLambdaExpression previousLambda = getLambda(mapCall); LOG.assertTrue(previousLambda != null); PsiExpression previousBody = LambdaUtil.extractSingleExpressionFromBody(previousLambda.getBody()); LOG.assertTrue(previousBody != null); PsiLambdaExpression lambda = getLambda(nextCall); LOG.assertTrue(lambda != null); CommentTracker ct = new CommentTracker(); if (lambda.getContainingFile() instanceof DummyHolder) { lambda = (PsiLambdaExpression)nextCall.getArgumentList().add(lambda); } PsiElement body = lambda.getBody(); LOG.assertTrue(body != null); ct.markUnchanged(body); PsiParameter[] nextParameters = lambda.getParameterList().getParameters(); LOG.assertTrue(nextParameters.length == 1); PsiParameter[] prevParameters = previousLambda.getParameterList().getParameters(); LOG.assertTrue(prevParameters.length == 1); PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.project()); for(PsiReferenceExpression ref : VariableAccessUtils.getVariableReferences(nextParameters[0], body)) { PsiExpression replacement = ct.markUnchanged(previousBody); if (ref.getParent() instanceof PsiExpression && ParenthesesUtils.areParenthesesNeeded(previousBody, (PsiExpression)ref.getParent(), false)) { replacement = factory.createExpressionFromText("(a)", ref); PsiExpression parenthesized = ((PsiParenthesizedExpression)replacement).getExpression(); LOG.assertTrue(parenthesized != null); parenthesized.replace(previousBody); } ct.replace(ref, replacement); } ct.replace(lambda.getParameterList(), previousLambda.getParameterList()); ExpressionUtils.bindReferenceTo(nextRef, newName); PsiExpression prevQualifier = mapCall.getMethodExpression().getQualifierExpression(); if(prevQualifier == null) { ct.deleteAndRestoreComments(nextQualifier); } else { ct.replaceAndRestoreComments(nextQualifier, prevQualifier); } CodeStyleManager.getInstance(context.project()).reformat(lambda); }