public static boolean checkIndentDedentBalanceWithLexer(@NotNull CharSequence text, @NotNull Lexer lexer, boolean isOnTheSameLine) {
    lexer.start(text);
    int balance = isOnTheSameLine ? 0 : -1;
    while (lexer.getTokenType() != null) {
      if (lexer.getTokenType() == PyTokenTypes.INDENT) {
        balance++;
      }
      else if (lexer.getTokenType() == PyTokenTypes.DEDENT) {
        balance--;
      }
      if (balance < 0) {
        LOG.debug("Indent/Dedent balance is negative, incremental reparse declined");
        return false;
      }
      lexer.advance();
    }
    return true; // positive balance is safe
  }
public static boolean checkIndentDedentBalanceWithLexer(@NotNull CharSequence text, @NotNull Lexer lexer, boolean isOnTheSameLine)