private static void moveCaretToTheLineEndIfPossible(@NotNull Editor editor, int line) {
    final Document document = editor.getDocument();
    final CaretModel caretModel = editor.getCaretModel();
    int offset;
    if (line >= document.getLineCount()) {
      offset = document.getTextLength();
    }
    else {
      offset = document.getLineEndOffset(line);
    }
    caretModel.moveToOffset(offset);
  }
private static void moveCaretToTheLineEndIfPossible(@NotNull Editor editor, int line)