private static void setHighlightersInRange(@NotNull List<? extends HighlightInfo> newInfos,
                                             @Nullable List<? extends HighlightInfo> oldInfos,
                                             @NotNull MarkupModelEx markup,
                                             @NotNull HighlightingSession session) {
    ApplicationManager.getApplication().assertIsNonDispatchThread();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    PsiFile psiFile = session.getPsiFile();
    Project project = session.getProject();
    SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
    HighlightersRecycler toReuse = new HighlightersRecycler();
    Document document = session.getDocument();
    Long2ObjectMap<RangeMarker> range2markerCache = new Long2ObjectOpenHashMap<>(10);
    boolean changed;
    try {
      if (oldInfos != null) {
        for (HighlightInfo oldInfo : oldInfos) {
          RangeHighlighterEx oldHighlighter = oldInfo.getHighlighter();
          boolean recycled = false;
          if (oldHighlighter != null) {
            recycled = toReuse.recycleHighlighter(oldHighlighter);
          }
          if (oldInfo.isFileLevelAnnotation() && !recycled) {
            ((HighlightingSessionImpl)session).removeFileLevelHighlight(oldInfo);
          }
        }
      }

      for (HighlightInfo info : newInfos) {
        if (info.isFileLevelAnnotation()) {
          RangeHighlighterEx salvagedHighlighter = toReuse.pickupFileLevelRangeHighlighter(psiFile.getTextLength());
          HighlightInfo oldFileInfo = salvagedHighlighter == null ? null : HighlightInfo.fromRangeHighlighter(salvagedHighlighter);

          if (oldFileInfo != null) {
            ((HighlightingSessionImpl)session).replaceFileLevelHighlight(oldFileInfo, info, salvagedHighlighter);
          }
          else {
            ((HighlightingSessionImpl)session).addFileLevelHighlight(info, salvagedHighlighter);
          }
        }
        else {
          BackgroundUpdateHighlightersUtil.createOrReuseHighlighterFor(info, session.getColorsScheme(), document, -1,
                                                                       psiFile, markup, toReuse, range2markerCache, severityRegistrar);
        }
      }
      // remove highlighters recycled from the local psi element, but do not touch invalidElementRecycler just yet
      changed = UpdateHighlightersUtil.incinerateObsoleteHighlighters(toReuse, session);
    }
    finally {
      toReuse.releaseHighlighters();
    }

    if (changed) {
      UpdateHighlightersUtil.clearWhiteSpaceOptimizationFlag(document);
    }
  }
private static void setHighlightersInRange(@NotNull List<? extends HighlightInfo> newInfos,
                                             @Nullable List<? extends HighlightInfo> oldInfos,
                                             @NotNull MarkupModelEx markup,
                                             @NotNull HighlightingSession session)