PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitMethodReferenceExpression(@NotNull PsiMethodReferenceExpression expression) { PsiElement referenceNameElement = expression.getReferenceNameElement(); if(referenceNameElement == null) return; String name = referenceNameElement.getText(); if (!name.equals("min") && !name.equals("max")) return; String className = getMethodReferenceClassName(expression); if (!CommonClassNames.JAVA_LANG_INTEGER.equals(className) && !CommonClassNames.JAVA_LANG_MATH .equals(className)) return; String functionalInterface = getFunctionalInterfaceClassName(expression); if (!CommonClassNames.JAVA_UTIL_COMPARATOR.equals(functionalInterface)) return; holder .registerProblem(expression, JavaAnalysisBundle .message("method.reference.mapped.to.comparator"), new ReplaceWithComparatorQuickFix(name.equals("min"))); } }; }