@Override
  public int calculateWrapPosition(@NotNull Document document,
                                   @Nullable Project project,
                                   int startOffset,
                                   int endOffset,
                                   int maxPreferredOffset,
                                   boolean allowToBeyondMaxPreferredOffset,
                                   boolean isSoftWrap) {
    if (isSoftWrap && myNonVirtualOnly) {
      LineWrapPositionStrategy implementation = LanguageLineWrapPositionStrategy.INSTANCE.getDefaultImplementation();
      //noinspection ConstantConditions
      return implementation.calculateWrapPosition(
        document, project, startOffset, endOffset, maxPreferredOffset, allowToBeyondMaxPreferredOffset, isSoftWrap
      );
    }

    if (project == null) {
      return -1;
    }

    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    if (documentManager == null) {
      return -1;
    }

    PsiFile psiFile = documentManager.getPsiFile(document);
    if (psiFile == null) {
      return -1;
    }

    documentManager.commitDocument(document);
    PsiElement element = psiFile.findElementAt(maxPreferredOffset);
    if (element == null) {
      return -1;
    }

    for (; element != null && element.getTextRange().getEndOffset() > startOffset; element = getPrevious(element)) {
      if (allowToWrapInside(element)) {
        TextRange textRange = element.getTextRange();
        int start = Math.max(textRange.getStartOffset(), startOffset);
        int end = Math.min(textRange.getEndOffset(), endOffset);
        int result = doCalculateWrapPosition(document, project, element, start, end, maxPreferredOffset, isSoftWrap);
        if (result >= 0) {
          return result;
        }
        else if (result == NO_LINE_WRAP) {
          break;
        }

        // Assume that it's possible to wrap on token boundary (makes sense at least for the tokens that occupy one symbol only).
        if (end <= maxPreferredOffset) {
          return end;
        }

        if (start > startOffset) {
          return start;
        }
      }
    }
    return -1;
  }
@Override
  public int calculateWrapPosition(@NotNull Document document,
                                   @Nullable Project project,
                                   int startOffset,
                                   int endOffset,
                                   int maxPreferredOffset,
                                   boolean allowToBeyondMaxPreferredOffset,
                                   boolean isSoftWrap)