private int calcAnnotationsSize() {
    myGapAfterAnnotations = false;
    int lineCount = Math.max(myEditor.getDocument().getLineCount(), 1);
    myTextAnnotationGutterProviders.replaceAll(info -> {
      TextAnnotationGutterProvider gutterProvider = info.provider();
      int gutterSize = 0;
      for (int i = 0; i < lineCount; i++) {
        String lineText = gutterProvider.getLineText(i, myEditor);
        if (!StringUtil.isEmpty(lineText)) {
          EditorFontType style = gutterProvider.getStyle(i, myEditor);
          Font font = getFontForText(lineText, style);
          FontMetrics fontMetrics = getFontMetrics(font);
          gutterSize = Math.max(gutterSize, fontMetrics.stringWidth(lineText));
        }
        else if (gutterProvider instanceof TextAnnotationGutterProvider.Filler) {
          gutterSize = Math.max(gutterSize, ((TextAnnotationGutterProvider.Filler)gutterProvider).getWidth());
        }
      }
      if (gutterSize > 0) {
        boolean margin = gutterProvider.useMargin();
        myGapAfterAnnotations = margin;
        if (margin) {
          gutterSize += getGapBetweenAnnotations();
        }
      }
      return new TextAnnotationGutterProviderInfo(gutterProvider, gutterSize);
    });
    // separate loop because the operation in myTextAnnotationGutterProviders.replaceAll() can retry on contention
    int totalSize = 0;
    for (TextAnnotationGutterProviderInfo info : myTextAnnotationGutterProviders) {
      totalSize += info.size();
    }
    return totalSize;
  }
private int calcAnnotationsSize()