private void doIndentCommenting(Commenter commenter) {
    CharSequence chars = myDocument.getCharsSequence();
    final FileType fileType = myFile.getFileType();
    Indent minIndent =
        computeMinIndent(myStartLine, myEndLine, chars, myCodeStyleManager, fileType);

    for (int line = myEndLine; line >= myStartLine; line--) {
      int lineStart = myDocument.getLineStartOffset(line);
      int offset = lineStart;
      final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
      try {
        while (true) {
          String space = buffer.toString();
          Indent indent = myCodeStyleManager.getIndent(space, fileType);
          if (indent.isGreaterThan(minIndent) || indent.equals(minIndent)) break;
          char c = chars.charAt(offset);
          if (c != ' ' && c != '\t') {
            String newSpace = myCodeStyleManager.fillIndent(minIndent, fileType);
            myDocument.replaceString(lineStart, offset, newSpace);
            offset = lineStart + newSpace.length();
            break;
          }
          buffer.append(c);
          offset++;
        }
      } finally {
        StringBuilderSpinAllocator.dispose(buffer);
      }
      commentLine(line, offset, commenter);
    }
  }
 private Indent computeMinIndent(
     int line1,
     int line2,
     CharSequence chars,
     CodeStyleManager codeStyleManager,
     FileType fileType) {
   Indent minIndent = CommentUtil.getMinLineIndent(myProject, myDocument, line1, line2, fileType);
   if (line1 > 0) {
     int commentOffset = getCommentStart(line1 - 1);
     if (commentOffset >= 0) {
       int lineStart = myDocument.getLineStartOffset(line1 - 1);
       String space = chars.subSequence(lineStart, commentOffset).toString();
       Indent indent = codeStyleManager.getIndent(space, fileType);
       minIndent = minIndent != null ? indent.min(minIndent) : indent;
     }
   }
   if (minIndent == null) {
     minIndent = codeStyleManager.zeroIndent();
   }
   return minIndent;
 }