PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitMethod(@NotNull PsiMethod method) { super.visitMethod(method); addDescriptors(checkMethod(method, holder.getManager(), isOnTheFly)); } @Override public void visitClass(@NotNull PsiClass aClass) { super.visitClass(aClass); addDescriptors(checkClass(aClass, holder.getManager(), isOnTheFly)); } @Override public void visitField(@NotNull PsiField field) { super.visitField(field); addDescriptors(checkField(field, holder.getManager(), isOnTheFly)); } @Override public void visitFile(@NotNull PsiFile file) { super.visitFile(file); addDescriptors(checkFile(file, holder.getManager(), isOnTheFly)); } private void addDescriptors(final ProblemDescriptor[] descriptors) { if (descriptors != null) { for (ProblemDescriptor descriptor : descriptors) { holder.registerProblem(descriptor); } } } }; }