void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiFunctionalExpression function = findFunction(element); if (function == null) return; PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(function, PsiMethodCallExpression.class); if (call == null) return; PsiExpression qualifier = call.getMethodExpression().getQualifierExpression(); if (qualifier == null) return; String name = suggestVariableName(function, qualifier); // We create first lambda, then convert to method reference as user code style might be set to prefer lambdas PsiExpression replacement = JavaPsiFacade.getElementFactory(project) .createExpressionFromText(qualifier.getText() + ".filter(" + name + "->" + name + "!=null)", qualifier); PsiMethodCallExpression result = (PsiMethodCallExpression)qualifier.replace(replacement); LambdaCanBeMethodReferenceInspection.replaceAllLambdasWithMethodReferences(result.getArgumentList()); }