private static TextAttributes mergeAttributes(TextAttributes primary, TextAttributes secondary) {
   if (primary == null) return secondary;
   if (secondary == null) return primary;
   return new TextAttributes(
       primary.getForegroundColor() == null
           ? secondary.getForegroundColor()
           : primary.getForegroundColor(),
       primary.getBackgroundColor() == null
           ? secondary.getBackgroundColor()
           : primary.getBackgroundColor(),
       primary.getEffectColor() == null ? secondary.getEffectColor() : primary.getEffectColor(),
       primary.getEffectType() == null ? secondary.getEffectType() : primary.getEffectType(),
       primary.getFontType() == Font.PLAIN ? secondary.getFontType() : primary.getFontType());
 }
  public static void printToConsole(
      @NotNull final LanguageConsoleImpl console,
      @NotNull final String string,
      @NotNull final ConsoleViewContentType mainType,
      @Nullable ConsoleViewContentType additionalType) {
    final TextAttributes mainAttributes = mainType.getAttributes();
    final TextAttributes attributes;
    if (additionalType == null) {
      attributes = mainAttributes;
    } else {
      attributes = additionalType.getAttributes().clone();
      attributes.setBackgroundColor(mainAttributes.getBackgroundColor());
    }

    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
      console.printToHistory(string, attributes);
    } else {
      application.invokeLater(
          new Runnable() {
            public void run() {
              console.printToHistory(string, attributes);
            }
          },
          ModalityState.stateForComponent(console.getComponent()));
    }
  }
 private void paintBackground(
     Graphics2D g, TextAttributes attributes, float x, int y, float width) {
   if (attributes == null) return;
   paintBackground(g, attributes.getBackgroundColor(), x, y, width);
 }
 @Nullable
 private static Color getScrollMarkColor(@NotNull TextAttributes attributes) {
   if (attributes.getErrorStripeColor() != null) return attributes.getErrorStripeColor();
   if (attributes.getBackgroundColor() != null) return attributes.getBackgroundColor().darker();
   return null;
 }
  private RangeHighlighter createRangeHighlighter(
      final long date,
      final MarkupModel markupModel,
      final boolean coverageByTestApplicable,
      final TreeMap<Integer, LineData> executableLines,
      @Nullable final String className,
      final int line,
      final int lineNumberInCurrent,
      @NotNull final CoverageSuitesBundle coverageSuite,
      Object[] lines) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    final TextAttributes attributes =
        scheme.getAttributes(CoverageLineMarkerRenderer.getAttributesKey(line, executableLines));
    TextAttributes textAttributes = null;
    if (attributes.getBackgroundColor() != null) {
      textAttributes = attributes;
    }
    final int startOffset = myDocument.getLineStartOffset(lineNumberInCurrent);
    final int endOffset = myDocument.getLineEndOffset(lineNumberInCurrent);
    final RangeHighlighter highlighter =
        markupModel.addRangeHighlighter(
            startOffset,
            endOffset,
            HighlighterLayer.SELECTION - 1,
            textAttributes,
            HighlighterTargetArea.LINES_IN_RANGE);
    final Function<Integer, Integer> newToOldConverter =
        newLine -> {
          if (myEditor == null) return -1;
          final TIntIntHashMap oldLineMapping = getNewToOldLineMapping(date);
          return oldLineMapping != null
              ? oldLineMapping.get(newLine.intValue())
              : newLine.intValue();
        };
    final Function<Integer, Integer> oldToNewConverter =
        newLine -> {
          if (myEditor == null) return -1;
          final TIntIntHashMap newLineMapping = getOldToNewLineMapping(date);
          return newLineMapping != null
              ? newLineMapping.get(newLine.intValue())
              : newLine.intValue();
        };
    final CoverageLineMarkerRenderer markerRenderer =
        coverageSuite
            .getCoverageEngine()
            .getLineMarkerRenderer(
                line,
                className,
                executableLines,
                coverageByTestApplicable,
                coverageSuite,
                newToOldConverter,
                oldToNewConverter,
                CoverageDataManager.getInstance(myProject).isSubCoverageActive());
    highlighter.setLineMarkerRenderer(markerRenderer);

    final LineData lineData = className != null ? (LineData) lines[line + 1] : null;
    if (lineData != null && lineData.getStatus() == LineCoverage.NONE) {
      highlighter.setErrorStripeMarkColor(markerRenderer.getErrorStripeColor(myEditor));
      highlighter.setThinErrorStripeMark(true);
      highlighter.setGreedyToLeft(true);
      highlighter.setGreedyToRight(true);
    }
    return highlighter;
  }