use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class ProjectionAnnotationHover method getProjectionTextAtLine.
private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numberOfLines) {
IAnnotationModel model = null;
if (viewer instanceof ISourceViewerExtension2) {
ISourceViewerExtension2 viewerExtension = (ISourceViewerExtension2) viewer;
IAnnotationModel visual = viewerExtension.getVisualAnnotationModel();
if (visual instanceof IAnnotationModelExtension) {
IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) visual;
model = modelExtension.getAnnotationModel(ProjectionSupport.PROJECTION);
}
}
if (model != null) {
try {
IDocument document = viewer.getDocument();
Iterator<Annotation> e = model.getAnnotationIterator();
while (e.hasNext()) {
ProjectionAnnotation annotation = (ProjectionAnnotation) e.next();
if (!annotation.isCollapsed())
continue;
Position position = model.getPosition(annotation);
if (position == null)
continue;
if (isCaptionLine(position, document, line))
return getText(document, position.getOffset(), position.getLength(), numberOfLines);
}
} catch (BadLocationException x) {
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project linuxtools by eclipse.
the class GcovAnnotationModel method clear.
public static void clear(ITextEditor editor) {
IDocumentProvider provider = editor.getDocumentProvider();
if (provider == null) {
return;
}
IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
if (!(model instanceof IAnnotationModelExtension)) {
return;
}
IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
IAnnotationModel coverageModel = modelex.getAnnotationModel(KEY);
if (coverageModel instanceof GcovAnnotationModel) {
((GcovAnnotationModel) coverageModel).clear();
}
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project linuxtools by eclipse.
the class GcovAnnotationModel method attach.
/**
* Attaches a coverage annotation model for the given editor if the editor
* can be annotated. Does nothing if the model is already attached.
*
* @param editor Editor to which an annotation model should be attached
*/
public static void attach(ITextEditor editor) {
IDocumentProvider provider = editor.getDocumentProvider();
if (provider == null) {
return;
}
IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
if (!(model instanceof IAnnotationModelExtension)) {
return;
}
IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
IDocument document = provider.getDocument(editor.getEditorInput());
GcovAnnotationModel coveragemodel = (GcovAnnotationModel) modelex.getAnnotationModel(KEY);
if (coveragemodel == null) {
coveragemodel = new GcovAnnotationModel(editor, document);
modelex.addAnnotationModel(KEY, coveragemodel);
} else {
coveragemodel.updateAnnotations(false);
}
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project xtext-xtend by eclipse.
the class OverrideIndicatorModelListener method updateAnnotationModel.
private IStatus updateAnnotationModel(IProgressMonitor monitor) {
if (xtextEditor == null || xtextEditor.getDocument() == null || xtextEditor.getInternalSourceViewer().getAnnotationModel() == null) {
return Status.OK_STATUS;
}
IXtextDocument xtextDocument = xtextEditor.getDocument();
IAnnotationModel annotationModel = xtextEditor.getInternalSourceViewer().getAnnotationModel();
Map<Annotation, Position> annotationToPosition = xtextDocument.readOnly(new CancelableUnitOfWork<Map<Annotation, Position>, XtextResource>() {
@Override
public Map<Annotation, Position> exec(XtextResource xtextResource, CancelIndicator cancelIndicator) {
if (xtextResource == null)
return Collections.emptyMap();
return createOverrideIndicatorAnnotationMap(xtextResource, cancelIndicator);
}
});
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
if (annotationModel instanceof IAnnotationModelExtension) {
IAnnotationModelExtension annotationModelExtension = (IAnnotationModelExtension) annotationModel;
Object lockObject = getLockObject(annotationModel);
synchronized (lockObject) {
annotationModelExtension.replaceAnnotations(overrideIndicatorAnnotations.toArray(new Annotation[overrideIndicatorAnnotations.size()]), annotationToPosition);
}
overrideIndicatorAnnotations = annotationToPosition.keySet();
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class SpellingProblem method removeAll.
/**
* Removes all spelling problems that are reported
* for the given <code>word</code> in the active editor.
*
* @param sourceViewer the source viewer
* @param word the word for which to remove the problems or <code>null</code> to remove all
* @since 3.4
*/
public static void removeAll(ISourceViewer sourceViewer, String word) {
Assert.isNotNull(sourceViewer);
IAnnotationModel model = sourceViewer.getAnnotationModel();
if (model == null)
return;
IDocument document = sourceViewer.getDocument();
if (document == null)
return;
boolean supportsBatchReplace = (model instanceof IAnnotationModelExtension);
List<Annotation> toBeRemovedAnnotations = new ArrayList<>();
Iterator<Annotation> iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = iter.next();
if (SpellingAnnotation.TYPE.equals(annotation.getType())) {
boolean doRemove = word == null;
if (word == null)
doRemove = true;
else {
String annotationWord = null;
Position pos = model.getPosition(annotation);
try {
annotationWord = document.get(pos.getOffset(), pos.getLength());
} catch (BadLocationException e) {
continue;
}
doRemove = word.equals(annotationWord);
}
if (doRemove) {
if (supportsBatchReplace)
toBeRemovedAnnotations.add(annotation);
else
model.removeAnnotation(annotation);
}
}
}
if (supportsBatchReplace && !toBeRemovedAnnotations.isEmpty()) {
Annotation[] annotationArray = toBeRemovedAnnotations.toArray(new Annotation[toBeRemovedAnnotations.size()]);
((IAnnotationModelExtension) model).replaceAnnotations(annotationArray, null);
}
}
Aggregations