PsiElement (PsiMethodCallExpression mapCall) { final PsiMethodCallExpression filterCall = getQualifierMethodCall(mapCall); if (filterCall == null) return null; final PsiExpressionList mapArgList = mapCall.getArgumentList(); final PsiExpressionList filterArgList = filterCall.getArgumentList(); final PsiElement tempMapArgList = mapArgList.copy(); final VariableNameGenerator generator = new VariableNameGenerator(filterCall, VariableKind.PARAMETER); final PsiMethodCallExpression candidateToRemove = findCandidateToRemove(mapCall); if (candidateToRemove == null) return null; final PsiType type = candidateToRemove.getMethodExpression().getType(); if (type == null) return null; final String newName = generator.byExpression(candidateToRemove).byType(type).generate(false); final PsiExpression filterArg = skipParenthesizedExprDown(ArrayUtil.getFirstElement(filterCall.getArgumentList().getExpressions())); if (filterArg == null) return null; final PsiLambdaExpression filterLambda = tryCast(filterArg, PsiLambdaExpression.class); if (filterLambda == null) return null; final CommentTracker ct = new CommentTracker(); final PsiLambdaExpression expression = (PsiLambdaExpression)JavaPsiFacade.getElementFactory(filterLambda.getProject()) .createExpressionFromText(newName + "->{}", filterLambda); ct.replace(candidateToRemove, newName); ct.replace(filterLambda.getParameterList(), expression.getParameterList()); ct.replace(mapArgList, filterArgList); ct.replace(filterArgList, tempMapArgList); ExpressionUtils.bindCallTo(mapCall, "filter"); ExpressionUtils.bindCallTo(filterCall, "map"); return mapCall; }