private static void addCommaIfNeeded(Document document, int line) {
    int offset = document.getLineEndOffset(line);
    if (offset > 0 && document.getCharsSequence().charAt(offset - 1) != ',') {
      document.insertString(offset, ",");
    }
  }
private static void addCommaIfNeeded(Document document, int line)