PsiExpression (@NotNull PsiLambdaExpression expression, @NotNull PsiExpression methodRefCandidate) { PsiParameter[] parameters = expression.getParameterList().getParameters(); PsiType functionalInterfaceType = expression.getFunctionalInterfaceType(); if (functionalInterfaceType == null) return null; final PsiExpression candidate = canBeMethodReferenceProblem(parameters, functionalInterfaceType, null, methodRefCandidate); if (candidate == null) return null; boolean safeLambdaReplacement = LambdaUtil.isSafeLambdaReplacement(expression, () -> { String text = createMethodReferenceText(methodRefCandidate, functionalInterfaceType, parameters); // We already did the same operation inside canBeMethodReferenceProblem LOG.assertTrue(text != null); return JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(text, expression); }); if (!safeLambdaReplacement) return null; return candidate; }