Search in sources :

Example 81 with IAnnotationModel

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) RepeatedTest(org.eclipse.xtext.testing.RepeatedTest) Test(org.junit.Test)

Example 82 with IAnnotationModel

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();
}
Also used : ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) EnrichMode(org.eclipse.jface.text.ITextViewerExtension8.EnrichMode) IDocument(org.eclipse.jface.text.IDocument)

Example 83 with IAnnotationModel

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);
}
Also used : IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 84 with IAnnotationModel

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);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 85 with IAnnotationModel

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);
    }
}
Also used : Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)148 Annotation (org.eclipse.jface.text.source.Annotation)71 Position (org.eclipse.jface.text.Position)58 IDocument (org.eclipse.jface.text.IDocument)41 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)26 Iterator (java.util.Iterator)23 ArrayList (java.util.ArrayList)20 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)20 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)19 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)19 BadLocationException (org.eclipse.jface.text.BadLocationException)18 IFile (org.eclipse.core.resources.IFile)17 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)16 IEditorInput (org.eclipse.ui.IEditorInput)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 List (java.util.List)12 CoreException (org.eclipse.core.runtime.CoreException)11 IMarker (org.eclipse.core.resources.IMarker)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10