@Override
  public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
    final PsiFile file = holder.getFile();
    if (InjectedLanguageManager.getInstance(file.getProject()).getInjectionHost(file) != null) return PsiElementVisitor.EMPTY_VISITOR;

    final Document document = file.getViewProvider().getDocument();
    if (document == null) return PsiElementVisitor.EMPTY_VISITOR;

    final CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(file);
    final int codeStyleRightMargin = codeStyleSettings.getRightMargin(file.getLanguage());
    final int tabSize = codeStyleSettings.getTabSize(file.getFileType());
    final TextRange restrictRange = session.getRestrictRange();
    final CharSequence text = document.getImmutableCharSequence();
    final int lineCount = document.getLineCount();
    return new PsiElementVisitor() {

      @Override
      public void visitFile(@NotNull PsiFile file) {
        final TextRange range = restrictRange.intersection(file.getTextRange());
        if (range == null || range.isEmpty()) return;

        int line = document.getLineNumber(range.getStartOffset());
        while (true) {
          final int lineStart = document.getLineStartOffset(line);
          if (lineStart > range.getEndOffset()) {
            break;
          }
          final int lineEnd = document.getLineEndOffset(line);
          int count = 0;
          for (int i = lineStart; i < lineEnd; i++) {
            count += (text.charAt(i) == '\t') ? tabSize : 1;
            if (count > codeStyleRightMargin) {
              String message =
                LangBundle.message("inspection.message.line.longer.than.allowed.by.code.style.columns", codeStyleRightMargin);
              final TextRange problemRange = new TextRange(i, lineEnd);
              final PsiElement element = findElementInRange(file, problemRange);
              if (!ignoreFor(element)) {
                holder.registerProblem(element, problemRange.shiftLeft(element.getTextRange().getStartOffset()), message);
              }
              break;
            }
          }
          line++;
          if (line >= lineCount) break;
        }
      }
    };
  }
@Override
  public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session)