private int safeGetDocumentLine(int offset) {
    if (offset >= myDocument.getTextLength()) {
      return myDocument.getLineCount() - 1;
    }
    return myDocument.getLineNumber(offset);
  }
private int safeGetDocumentLine(int offset)