private @NotNull TextRange calcRangeInsideHostElement(boolean usePsiRange) {
    PsiLanguageInjectionHost host = getHost();
    Segment psiRange = usePsiRange ? relevantRangeInHost.getPsiRange() : relevantRangeInHost.getRange();
    TextRange textRange = psiRange == null ? null : TextRange.create(psiRange);
    if (host == null) {
      if (textRange != null) return textRange;
      Segment fromSP = usePsiRange ? hostElementPointer.getPsiRange() : hostElementPointer.getRange();
      if (fromSP != null) return TextRange.create(fromSP);
      return new TextRange(0,0);
    }
    TextRange hostTextRange = host.getTextRange();
    textRange = textRange == null ? null : textRange.intersection(hostTextRange);
    if (textRange == null) return new ProperTextRange(0, hostTextRange.getLength());

    return textRange.shiftLeft(hostTextRange.getStartOffset());
  }
private @NotNull TextRange calcRangeInsideHostElement(boolean usePsiRange)