int (@NotNull Document document, @NotNull CaretStop lineStop, int lineNumber, boolean isAtLineEnd) { if (lineNumber + 1 >= document.getLineCount()) { return document.getTextLength(); } else if (!isAtLineEnd) { return lineStop.isAtEnd() ? document.getLineEndOffset(lineNumber) : lineStop.isAtStart() ? document.getLineStartOffset(lineNumber + 1) : document.getTextLength(); } else { return lineStop.isAtStart() ? document.getLineStartOffset(lineNumber + 1) : lineStop.isAtEnd() ? document.getLineEndOffset(lineNumber + 1) : document.getTextLength(); } }