use of org.eclipse.jface.text.codemining.ICodeMining 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());
}
use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.
the class ProjectReferencesCodeMiningProvider method provideCodeMinings.
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
IDocument document = viewer.getDocument();
List<ICodeMining> minings = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
String line = getLineText(document, i).trim();
int startIndex = line.indexOf("<name>");
if (startIndex != -1) {
// It's the first name, we consider we are in <projectDescription></name>
startIndex += "<name>".length();
int endIndex = line.indexOf("</name>");
if (endIndex > startIndex) {
// Check if parent element is projectDescription
String projectName = line.substring(startIndex, endIndex);
if (projectName.length() > 0) {
try {
minings.add(new ProjectReferenceCodeMining(projectName, i, document, this));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
// <buildCommand><name>
break;
}
}
return minings;
});
}
use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.
the class CodeMiningLineHeaderAnnotation method draw.
@Override
public void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
List<ICodeMining> minings = new ArrayList<>(fMinings);
int nbDraw = 0;
int separatorWidth = -1;
boolean redrawn = false;
fBounds.clear();
for (int i = 0; i < minings.size(); i++) {
ICodeMining mining = minings.get(i);
// try to get the last resolved mining.
ICodeMining lastResolvedMining = (fResolvedMinings != null && fResolvedMinings.length > i) ? fResolvedMinings[i] : null;
if (mining.getLabel() != null) {
// mining is resolved with none error, update the resolved mining list
fResolvedMinings[i] = mining;
} else if (!mining.isResolved()) {
// the mining is not resolved, draw the last resolved mining
mining = lastResolvedMining;
if (!redrawn) {
// redraw the annotation when mining is resolved.
redraw();
redrawn = true;
}
} else {
// the mining is resolved with error, draw the last resolved mining
mining = lastResolvedMining;
}
if (mining == null) {
// ignore the draw of mining
continue;
}
// draw the mining
if (nbDraw > 0) {
initGC(textWidget, color, gc);
gc.drawText(SEPARATOR, x, y);
if (separatorWidth == -1) {
separatorWidth = gc.stringExtent(SEPARATOR).x;
}
x += separatorWidth;
}
initGC(textWidget, color, gc);
Point loc = mining.draw(gc, textWidget, color, x, y);
fBounds.add(new Rectangle(x, y, loc.x, loc.y));
x += loc.x;
nbDraw++;
}
}
use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.
the class ClassImplementationsCodeMiningProvider method provideCodeMinings.
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
IDocument document = viewer.getDocument();
List<ICodeMining> lenses = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
updateContentMining(i, document, "class ", lenses);
updateContentMining(i, document, "interface ", lenses);
}
return lenses;
});
}
use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.
the class ClassReferenceCodeMiningProvider method provideCodeMinings.
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
IDocument document = viewer.getDocument();
List<ICodeMining> lenses = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
String line = AbstractClassCodeMining.getLineText(document, i).trim();
int index = line.indexOf("class ");
if (index == 0) {
String className = line.substring(index + "class ".length(), line.length()).trim();
if (className.length() > 0) {
try {
lenses.add(new ClassReferenceCodeMining(className, i, document, this));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
return lenses;
});
}
Aggregations