PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { JvmElementVisitor<Boolean> visitor = null; for (JvmElement jvmElement : JvmDeclarationSearch.getElementsByIdentifier(element)) { if (visitor == null) { // don't build visitor until there is at least one JvmElement visitor = buildVisitor( holder.getProject(), new HighlightSinkImpl() { @Override public void highlight(@Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String message, @NotNull ProblemHighlightType highlightType, LocalQuickFix @NotNull ... fixes) { holder.registerProblem(element, message, highlightType, fixes); } @Override public @NotNull ProblemsHolder getHolder() { return holder; } }, isOnTheFly ); if (visitor == null) return; } Boolean result = jvmElement.accept(visitor); if (result == Boolean.TRUE) { return; } } } }; }