PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitAnonymousClass(@NotNull PsiAnonymousClass aClass) { super.visitAnonymousClass(aClass); if (AnonymousCanBeLambdaInspection.canBeConvertedToLambda(aClass, true, reportNotAnnotatedInterfaces, Collections.emptySet())) { final PsiMethod method = aClass.getMethods()[0]; final PsiCodeBlock body = method.getBody(); MethodReferenceCandidate methodReferenceCandidate = LambdaCanBeMethodReferenceInspection.extractMethodReferenceCandidateExpression(body); if (methodReferenceCandidate == null) return; final PsiExpression candidate = LambdaCanBeMethodReferenceInspection .canBeMethodReferenceProblem(method.getParameterList().getParameters(), aClass.getBaseClassType(), aClass.getParent(), methodReferenceCandidate.myExpression); if (candidate instanceof PsiCallExpression callExpression) { final PsiMethod resolveMethod = callExpression.resolveMethod(); if (resolveMethod != method && !AnonymousCanBeLambdaInspection.functionalInterfaceMethodReferenced(resolveMethod, aClass, callExpression)) { final PsiElement parent = aClass.getParent(); if (parent instanceof PsiNewExpression newExpression) { final PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference(); if (classReference != null) { final PsiElement lBrace = aClass.getLBrace(); LOG.assertTrue(lBrace != null); final TextRange rangeInElement = new TextRange(0, aClass.getStartOffsetInParent() + lBrace.getStartOffsetInParent()); ProblemHighlightType type; if (methodReferenceCandidate.mySafeQualifier && methodReferenceCandidate.myConformsCodeStyle) { type = ProblemHighlightType.GENERIC_ERROR_OR_WARNING; } else { if (!isOnTheFly) return; type = ProblemHighlightType.INFORMATION; } holder.registerProblem(parent, JavaBundle.message("inspection.message.anonymous.ref.loc.can.be.replaced.with.method.reference"), type, rangeInElement, new ReplaceWithMethodRefFix()); } } } } } } }; }