private void doSetText(@NotNull CharSequence text) {
    if (Comparing.equal(myText, text)) return;
    text = ImmutableCharSequence.asImmutable(text);

    SegmentArrayWithData tempSegments = createSegments();
    TokenProcessor processor = createTokenProcessor(0, tempSegments, text);
    int textLength = text.length();
    Lexer lexerWrapper = new ValidatingLexerWrapper(myLexer);

    lexerWrapper.start(text, 0, textLength,
                       myLexer instanceof RestartableLexer ? ((RestartableLexer)myLexer).getStartState() : myInitialState);
    int i = 0;
    while (true) {
      IElementType tokenType = lexerWrapper.getTokenType();
      if (tokenType == null) break;

      int state = lexerWrapper.getState();
      int data = tempSegments.packData(tokenType, state, canRestart(state));
      processor.addToken(i, lexerWrapper.getTokenStart(), lexerWrapper.getTokenEnd(), data, tokenType);
      i++;
      if (i % 1024 == 0) {
        ProgressManager.checkCanceled();
      }
      lexerWrapper.advance();
    }

    myText = text;
    mySegments = tempSegments;
    processor.finish();

    if (textLength > 0 && (mySegments.mySegmentCount == 0 || mySegments.myEnds[mySegments.mySegmentCount - 1] != textLength)) {
      throw new IllegalStateException("Unexpected termination offset for lexer " + myLexer);
    }

    if (myEditor != null && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
      UIUtil.invokeLaterIfNeeded(() -> myEditor.repaint(0, textLength));
    }
  }
private void doSetText(@NotNull CharSequence text)