Search in sources :

Example 86 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.

the class MarkerRulerAction method getAnnotationModel.

/**
 * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
 *
 * @return the marker annotation model
 */
protected AbstractMarkerAnnotationModel getAnnotationModel() {
    IDocumentProvider provider = fTextEditor.getDocumentProvider();
    IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel)
        return (AbstractMarkerAnnotationModel) model;
    return null;
}
Also used : IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 87 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.

the class SelectMarkerRulerAction method getAnnotationModel.

/**
 * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
 *
 * @return the marker annotation model or <code>null</code> if there's none
 */
protected final AbstractMarkerAnnotationModel getAnnotationModel() {
    IDocumentProvider provider = fTextEditor.getDocumentProvider();
    IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel)
        return (AbstractMarkerAnnotationModel) model;
    return null;
}
Also used : IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 88 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.

the class QuickDiffRestoreAction method getModel.

/**
 * Returns the annotation model of the document displayed in this action's editor, if it
 * implements the {@link IAnnotationModelExtension IAnnotationModelExtension} interface.
 *
 * @return the displayed document's annotation model if it is an <code>IAnnotationModelExtension</code>, or <code>null</code>
 */
private IAnnotationModelExtension getModel() {
    if (getTextEditor() == null)
        return null;
    IDocumentProvider provider = getTextEditor().getDocumentProvider();
    IEditorInput editorInput = getTextEditor().getEditorInput();
    IAnnotationModel m = provider.getAnnotationModel(editorInput);
    if (m instanceof IAnnotationModelExtension)
        return (IAnnotationModelExtension) m;
    return null;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput)

Example 89 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.

the class ReferenceSelectionAction method getDiffer.

/**
 * Fetches the differ installed with the current editor's document's annotation model. If none
 * is installed yet, and <code>createIfNeeded</code> is true, one is created and attached to the
 * model.
 *
 * @param createIfNeeded when set to <code>true</code>, a new differ will be created if needed.
 * @return the differ installed with the annotation model, or <code>null</code>.
 */
private DocumentLineDiffer getDiffer(boolean createIfNeeded) {
    // get annotation model
    if (fEditor == null)
        return null;
    IDocumentProvider provider = fEditor.getDocumentProvider();
    IEditorInput editorInput = fEditor.getEditorInput();
    if (provider == null || editorInput == null)
        return null;
    IAnnotationModel m = provider.getAnnotationModel(editorInput);
    IAnnotationModelExtension model = null;
    if (m instanceof IAnnotationModelExtension) {
        model = (IAnnotationModelExtension) m;
    } else {
        return null;
    }
    // get differ
    DocumentLineDiffer differ = (DocumentLineDiffer) model.getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    // create if needed
    if (differ == null && createIfNeeded) {
        differ = new DocumentLineDiffer();
        model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
    }
    return differ;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput)

Example 90 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.

the class HighlightStrategy method applyHighlights.

private void applyHighlights(int offset) {
    if (sourceViewer == null || !enabled) {
        return;
    }
    String text = document.get();
    offset = ((ITextViewerExtension5) sourceViewer).widgetOffset2ModelOffset(offset);
    int wordStartOffset = Math.max(text.lastIndexOf('/', offset), text.lastIndexOf('<', offset)) + 1;
    int wordEndOffset = findEndingOffset(text, offset);
    if (wordEndOffset <= wordStartOffset || wordEndOffset == -1 || wordStartOffset == -1)
        return;
    String word = text.substring(wordStartOffset, wordEndOffset);
    if (word.indexOf('>') != -1 || word.indexOf('<') != -1) {
        removeOccurrenceAnnotations();
        return;
    }
    Matcher m = TAG_NAME_PATTERN.matcher(text);
    Map<Annotation, Position> annotationMap = new HashMap<>();
    while (m.find()) {
        if (m.group(1).equals(word)) {
            annotationMap.put(new Annotation(ANNOTATION_TYPE, false, null), new Position(m.start(1), m.end(1) - m.start(1)));
        }
    }
    if (annotationMap.size() < 2) {
        removeOccurrenceAnnotations();
        return;
    }
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
        } else {
            removeOccurrenceAnnotations();
            Iterator<Entry<Annotation, Position>> iter = annotationMap.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<Annotation, Position> mapEntry = iter.next();
                annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue());
            }
        }
        fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
    }
}
Also used : Entry(java.util.Map.Entry) Matcher(java.util.regex.Matcher) Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

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