use of org.eclipse.jface.text.codemining.LineHeaderCodeMining in project eclipse.platform.text by eclipse.
the class CodeMiningManager method renderCodeMinings.
/**
* Render the codemining grouped by line position.
*
* @param groups code minings grouped by lines position
* @param viewer the viewer
* @param monitor the progress monitor
*/
private void renderCodeMinings(Map<Position, List<ICodeMining>> groups, ISourceViewer viewer, IProgressMonitor monitor) {
// check if request was canceled.
monitor.isCanceled();
IDocument document = viewer != null ? viewer.getDocument() : null;
if (document == null) {
// done.
return;
}
Set<ICodeMiningAnnotation> annotationsToRedraw = new HashSet<>();
Set<AbstractInlinedAnnotation> currentAnnotations = new HashSet<>();
// Loop for grouped code minings
groups.entrySet().stream().forEach(g -> {
// check if request was canceled.
monitor.isCanceled();
Position pos = new Position(g.getKey().offset, g.getKey().length);
List<ICodeMining> minings = g.getValue();
boolean inLineHeader = minings.size() > 0 ? (minings.get(0) instanceof LineHeaderCodeMining) : true;
// Try to find existing annotation
AbstractInlinedAnnotation ann = fInlinedAnnotationSupport.findExistingAnnotation(pos);
if (ann == null) {
// The annotation doesn't exists, create it.
ann = inLineHeader ? new CodeMiningLineHeaderAnnotation(pos, viewer) : new CodeMiningLineContentAnnotation(pos, viewer);
} else if (ann instanceof ICodeMiningAnnotation && ((ICodeMiningAnnotation) ann).isInVisibleLines()) {
// annotation is in visible lines
annotationsToRedraw.add((ICodeMiningAnnotation) ann);
}
((ICodeMiningAnnotation) ann).update(minings, monitor);
currentAnnotations.add(ann);
});
// check if request was canceled.
monitor.isCanceled();
fInlinedAnnotationSupport.updateAnnotations(currentAnnotations);
// redraw the existing codemining annotations since their content can change
annotationsToRedraw.stream().forEach(ann -> ann.redraw());
}
Aggregations