Search in sources :

Example 1 with LineTooltipRenderer

use of com.intellij.codeInsight.hint.LineTooltipRenderer in project intellij-community by JetBrains.

the class DaemonTooltipRendererProvider method calcTooltipRenderer.

@Override
public TooltipRenderer calcTooltipRenderer(@NotNull final Collection<RangeHighlighter> highlighters) {
    LineTooltipRenderer bigRenderer = null;
    List<HighlightInfo> infos = new SmartList<>();
    //do not show same tooltip twice
    Collection<String> tooltips = new THashSet<>();
    for (RangeHighlighter marker : highlighters) {
        final Object tooltipObject = marker.getErrorStripeTooltip();
        if (tooltipObject == null)
            continue;
        if (tooltipObject instanceof HighlightInfo) {
            HighlightInfo info = (HighlightInfo) tooltipObject;
            if (info.getToolTip() != null && tooltips.add(info.getToolTip())) {
                infos.add(info);
            }
        } else {
            final String text = tooltipObject.toString();
            if (tooltips.add(text)) {
                if (bigRenderer == null) {
                    bigRenderer = new MyRenderer(text, new Object[] { highlighters });
                } else {
                    bigRenderer.addBelow(text);
                }
            }
        }
    }
    if (!infos.isEmpty()) {
        // show errors first
        ContainerUtil.quickSort(infos, (o1, o2) -> {
            int i = SeverityRegistrar.getSeverityRegistrar(myProject).compare(o2.getSeverity(), o1.getSeverity());
            if (i != 0)
                return i;
            return o1.getToolTip().compareTo(o2.getToolTip());
        });
        final HighlightInfoComposite composite = new HighlightInfoComposite(infos);
        String toolTip = composite.getToolTip();
        MyRenderer myRenderer = new MyRenderer(toolTip == null ? null : UIUtil.convertSpace2Nbsp(toolTip), new Object[] { highlighters });
        if (bigRenderer == null) {
            bigRenderer = myRenderer;
        } else {
            myRenderer.addBelow(bigRenderer.getText());
            bigRenderer = myRenderer;
        }
    }
    return bigRenderer;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) SmartList(com.intellij.util.SmartList) LineTooltipRenderer(com.intellij.codeInsight.hint.LineTooltipRenderer) THashSet(gnu.trove.THashSet)

Aggregations

LineTooltipRenderer (com.intellij.codeInsight.hint.LineTooltipRenderer)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 SmartList (com.intellij.util.SmartList)1 THashSet (gnu.trove.THashSet)1