PsiElementVisitor (@NotNull ProblemsHolder holder) { if (!RegistryManager.getInstance().is("groovy.good.code.is.red")) { return PsiElementVisitor.EMPTY_VISITOR; } GroovyFileBase file = (GroovyFileBase)holder.getFile(); Project project = holder.getProject(); GrAccessibilityChecker accessibilityChecker = new GrAccessibilityChecker(file, project); GroovyElementVisitor typeCheckVisitor = new GroovyStaticTypeCheckVisitorBase() { @Override protected void registerError(@NotNull PsiElement location, @NotNull @InspectionMessage String description, @NotNull LocalQuickFix @Nullable [] fixes, @NotNull ProblemHighlightType highlightType) { if (highlightType == ProblemHighlightType.GENERIC_ERROR) { holder.registerProblem(location, description); } } }; return new GroovyPsiElementVisitor(new GroovyElementVisitor() { @Override public void visitElement(@NotNull GroovyPsiElement element) { super.visitElement(element); element.accept(typeCheckVisitor); } @Override public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) { super.visitReferenceExpression(referenceExpression); HighlightInfo info = accessibilityChecker.checkReferenceExpression(referenceExpression); if (info != null) { registerProblem(holder, info, referenceExpression); } } @Override public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement refElement) { super.visitCodeReferenceElement(refElement); HighlightInfo info = accessibilityChecker.checkCodeReferenceElement(refElement); if (info != null) { registerProblem(holder, info, refElement); } } private static void registerProblem(ProblemsHolder holder, HighlightInfo info, PsiElement e) { if (info.getSeverity() == HighlightSeverity.ERROR) { holder.registerProblem(e, info.getDescription()); } } }); }