private static int calculatePreferredWrapPosition(@NotNull Editor editor,
                                                    @NotNull CharSequence text,
                                                    int tabSize,
                                                    int spaceSize,
                                                    int startLineOffset,
                                                    int endLineOffset,
                                                    int targetRangeEndOffset,
                                                    int rightMargin) {
    boolean hasTabs = false;
    boolean canOptimize = true;
    boolean hasNonSpaceSymbols = false;
    loop:
    for (int i = startLineOffset; i < Math.min(endLineOffset, targetRangeEndOffset); i++) {
      char c = text.charAt(i);
      switch (c) {
        case '\t': {
          hasTabs = true;
          if (hasNonSpaceSymbols) {
            canOptimize = false;
            break loop;
          }
        }
        case ' ': break;
        default: hasNonSpaceSymbols = true;
      }
    }

    int reservedWidthInColumns = FormatConstants.getReservedLineWrapWidthInColumns(editor);

    if (!hasTabs) {
      return wrapPositionForTextWithoutTabs(startLineOffset, endLineOffset, targetRangeEndOffset, reservedWidthInColumns, rightMargin);
    }
    else if (canOptimize) {
      return wrapPositionForTabbedTextWithOptimization(text, tabSize, startLineOffset, endLineOffset, targetRangeEndOffset,
                                                       reservedWidthInColumns, rightMargin);
    }
    else {
      return wrapPositionForTabbedTextWithoutOptimization(editor, text, spaceSize, startLineOffset, endLineOffset, targetRangeEndOffset,
                                                          reservedWidthInColumns, rightMargin);
    }
  }
private static int calculatePreferredWrapPosition(@NotNull Editor editor,
                                                    @NotNull CharSequence text,
                                                    int tabSize,
                                                    int spaceSize,
                                                    int startLineOffset,
                                                    int endLineOffset,
                                                    int targetRangeEndOffset,
                                                    int rightMargin)