public static boolean isValidLine(int line, @NotNull Document document) {
    if (line < 0) return false;
    int lineCount = document.getLineCount();
    return lineCount == 0 ? line == 0 : line < lineCount;
  }
public static boolean isValidLine(int line, @NotNull Document document)