private static void setHighlightersInRange(@NotNull Document document,
                                             @NotNull TextRange range,
                                             @NotNull List<? extends HighlightInfo> infos,
                                             @NotNull MarkupModelEx markup,
                                             int group,
                                             @NotNull HighlightingSession session) {
    ThreadingAssertions.assertEventDispatchThread();
    Project project = session.getProject();
    PsiFile psiFile = session.getPsiFile();
    SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
    HighlightersRecycler infosToRemove = new HighlightersRecycler();
    DaemonCodeAnalyzerEx.processHighlights(markup, project, null, range.getStartOffset(), range.getEndOffset(), info -> {
      if (info.getGroup() == group) {
        RangeHighlighterEx highlighter = info.getHighlighter();
        int hiStart = highlighter.getStartOffset();
        int hiEnd = highlighter.getEndOffset();
        boolean willBeRemoved = range.containsRange(hiStart, hiEnd)
                                || hiEnd == document.getTextLength() && range.getEndOffset() == hiEnd;
        if (willBeRemoved && infosToRemove.recycleHighlighter(highlighter)) {
          info.setHighlighter(null);
        }
      }
      return true;
    });

    List<HighlightInfo> filteredInfos = HighlightInfoPostFilters.applyPostFilter(project, infos);
    ContainerUtil.quickSort(filteredInfos, BY_ACTUAL_START_OFFSET_NO_DUPS);
    Long2ObjectMap<RangeMarker> range2markerCache = new Long2ObjectOpenHashMap<>(10);
    DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
    boolean[] changed = {false};
    SweepProcessor.Generator<HighlightInfo> generator = processor -> ContainerUtil.process(filteredInfos, processor);
    SweepProcessor.sweep(generator, (__, info, atStart, overlappingIntervals) -> {
      if (!atStart) {
        return true;
      }
      if (info.isFileLevelAnnotation()) {
        codeAnalyzer.addFileLevelHighlight(group, info, psiFile, null);
        changed[0] = true;
        return true;
      }

      if (range.contains(info) && !isWarningCoveredByError(info, severityRegistrar, overlappingIntervals)) {
        createOrReuseHighlighterFor(info, session.getColorsScheme(), document, group, psiFile, markup, infosToRemove, range2markerCache, severityRegistrar);
        changed[0] = true;
      }
      return true;
    });

    changed[0] |= incinerateObsoleteHighlighters(infosToRemove, session);

    if (changed[0]) {
      clearWhiteSpaceOptimizationFlag(document);
    }
  }
private static void setHighlightersInRange(@NotNull Document document,
                                             @NotNull TextRange range,
                                             @NotNull List<? extends HighlightInfo> infos,
                                             @NotNull MarkupModelEx markup,
                                             int group,
                                             @NotNull HighlightingSession session)