int (@NotNull Document document, int startOffset) { if (document.getTextLength() == 0) return 0; if (startOffset >= document.getTextLength()) return document.getLineCount(); return document.getLineNumber(startOffset); }