use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.
the class MarkOccurrencesTest method testMarkOccurrencesCrossFile.
@Test
public void testMarkOccurrencesCrossFile() throws Exception {
String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }";
String model2 = "Foo {}";
IFile modelFile1 = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test1.outlinetestlanguage", model1);
IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test2.outlinetestlanguage", model2);
IResourcesSetupUtil.waitForBuild();
XtextEditor editor = openEditor(modelFile1);
ISelectionProvider selectionProvider = editor.getSelectionProvider();
selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1));
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel).added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3).added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3);
listener.start();
annotationModel.addAnnotationModelListener(listener);
setMarkOccurrences(true);
listener.verify(TIMEOUT);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method initializeSourceViewer.
/**
* Initializes the editor's source viewer based on the given editor input.
*
* @param input the editor input to be used to initialize the source viewer
*/
private void initializeSourceViewer(IEditorInput input) {
IDocumentProvider documentProvider = getDocumentProvider();
IAnnotationModel model = documentProvider.getAnnotationModel(input);
IDocument document = documentProvider.getDocument(input);
if (document != null) {
fSourceViewer.setDocument(document, model);
fSourceViewer.setEditable(isEditable());
fSourceViewer.showAnnotations(model != null);
}
if (fElementStateListener instanceof IElementStateListenerExtension) {
boolean isStateValidated = false;
if (documentProvider instanceof IDocumentProviderExtension)
isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input);
IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
extension.elementStateValidationChanged(input, isStateValidated);
}
if (fInitialCaret == null)
fInitialCaret = fSourceViewer.getTextWidget().getCaret();
if (fIsOverwriting)
fSourceViewer.getTextWidget().invokeAction(ST.TOGGLE_OVERWRITE);
handleInsertModeChanged();
if (isTabsToSpacesConversionEnabled())
installTabsToSpacesConverter();
if (fSourceViewer instanceof ITextViewerExtension8) {
IPreferenceStore store = getPreferenceStore();
EnrichMode mode = store != null ? convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)) : EnrichMode.AFTER_DELAY;
((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(mode);
}
if (fSourceViewer instanceof ISourceViewerExtension5)
installCodeMiningProviders();
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class GotoAnnotationAction method update.
@Override
public void update() {
ITextEditor editor = getTextEditor();
if (!(editor instanceof AbstractTextEditor)) {
setEnabled(false);
return;
}
IAnnotationModel model = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
setEnabled(model != null);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class SelectAnnotationRulerAction method annotationDefaultSelected.
@Override
public void annotationDefaultSelected(VerticalRulerEvent event) {
Annotation a = event.getSelectedAnnotation();
IAnnotationModel model = getAnnotationModel();
Position position = model.getPosition(a);
if (position == null)
return;
getTextEditor().selectAndReveal(position.offset, position.length);
}
use of org.eclipse.jface.text.source.IAnnotationModel 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