public @Nullable Segment getSegment() {
    PsiElement element = getElement();
    if (element instanceof PsiFile && ((PsiFile)element).getFileType().isBinary()) {
      return null;
    }
    TextRange range = element != null ? element.getTextRange() : null;
    if (range == null) {
      return null;
    }

    TextRange.assertProperRange(range, element);
    if (element instanceof PsiFile) {
      // hack: it's actually a range inside file, use document for range checking since during the "find|replace all" operation, file range might have been changed
      Document document = PsiDocumentManager.getInstance(getProject()).getDocument((PsiFile)element);
      if (document != null) {
        range = new ProperTextRange(0, document.getTextLength());
      }
    }
    ProperTextRange rangeInElement = getRangeInElement();
    if (rangeInElement == null) return null;
    return new ProperTextRange(Math.min(range.getEndOffset(), range.getStartOffset() + rangeInElement.getStartOffset()),
                               Math.min(range.getEndOffset(), range.getStartOffset() + rangeInElement.getEndOffset()));
  }
public @Nullable Segment getSegment()