@Nullable private RangeHighlighter createHighlighter(@NotNull Range range) { myApplication.assertIsDispatchThread(); LOG.assertTrue(!myReleased, "Already released"); if (myMode == Mode.SILENT) return null; int first = range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1()); int second = range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2()); final TextAttributes attr = LineStatusTrackerDrawing.getAttributesFor(range); final RangeHighlighter highlighter = DocumentMarkupModel.forDocument(myDocument, myProject, true) .addRangeHighlighter( first, second, HighlighterLayer.FIRST - 1, attr, HighlighterTargetArea.LINES_IN_RANGE); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); highlighter.setLineMarkerRenderer(LineStatusTrackerDrawing.createRenderer(range, this)); highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter()); final String tooltip; if (range.getLine1() == range.getLine2()) { if (range.getVcsLine1() + 1 == range.getVcsLine2()) { tooltip = VcsBundle.message("tooltip.text.line.before.deleted", range.getLine1() + 1); } else { tooltip = VcsBundle.message( "tooltip.text.lines.before.deleted", range.getLine1() + 1, range.getVcsLine2() - range.getVcsLine1()); } } else if (range.getLine1() + 1 == range.getLine2()) { tooltip = VcsBundle.message("tooltip.text.line.changed", range.getLine1() + 1); } else { tooltip = VcsBundle.message("tooltip.text.lines.changed", range.getLine1() + 1, range.getLine2()); } highlighter.setErrorStripeTooltip(tooltip); return highlighter; }
@NotNull public static RangeHighlighter createRangeHighlighter( @NotNull Range range, @NotNull TextRange textRange, @NotNull MarkupModel markupModel) { TextAttributes attributes = getTextAttributes(range); final RangeHighlighter highlighter = markupModel.addRangeHighlighter( textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.FIRST - 1, attributes, HighlighterTargetArea.LINES_IN_RANGE); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); highlighter.setErrorStripeTooltip(getTooltipText(range)); return highlighter; }
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; }