Search in sources :

Example 31 with IAnnotationModel

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

the class RpmMacroOccurrencesUpdater method update.

/**
 * Updates the drawn annotations.
 *
 * @param viewer
 *            The viewer to get the document and annotation model from
 */
public void update(ISourceViewer viewer) {
    try {
        IDocument document = viewer.getDocument();
        IAnnotationModel model = viewer.getAnnotationModel();
        if (document == null || model == null) {
            return;
        }
        removeOldAnnotations(model);
        String currentSelectedWord = getWordAtSelection(fEditor.getSelectionProvider().getSelection(), document);
        if (isMacro(currentSelectedWord)) {
            Specfile spec = fEditor.getSpecfile();
            SpecfileDefine define = spec.getDefine(currentSelectedWord);
            // $NON-NLS-1$
            String word = currentSelectedWord + ": ";
            if (define != null) {
                word += define.getStringValue();
            } else {
                // If there's no such define we try to see if it corresponds
                // to
                // a Source or Patch declaration
                String retrivedValue = RPMUtils.getSourceOrPatchValue(spec, currentSelectedWord.toLowerCase());
                if (retrivedValue != null) {
                    word += retrivedValue;
                } else {
                    // If it does not correspond to a Patch or Source macro,
                    // try to find it
                    // in the macro proposals list.
                    retrivedValue = RPMUtils.getMacroValueFromMacroList(currentSelectedWord);
                    if (retrivedValue != null) {
                        word += retrivedValue;
                    }
                }
            }
            createNewAnnotations(currentSelectedWord, word, document, model);
        }
    } catch (BadLocationException e) {
        SpecfileLog.logError(e);
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 32 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel 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();
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 33 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel 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);
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument)

Example 34 with IAnnotationModel

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

the class FileTestCase method getFailures.

protected ArrayList<SpecfileTestFailure> getFailures() {
    ArrayList<SpecfileTestFailure> failures = new ArrayList<>();
    IAnnotationModel model = SpecfileEditor.getSpecfileDocumentProvider().getAnnotationModel(fei);
    for (Iterator<Annotation> i = model.getAnnotationIterator(); i.hasNext(); ) {
        Annotation annotation = i.next();
        Position p = model.getPosition(annotation);
        SpecfileTestFailure t = new SpecfileTestFailure(annotation, p);
        failures.add(t);
    }
    return failures;
}
Also used : Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 35 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project liferay-ide by liferay.

the class InputContext method dispose.

public void dispose() {
    IAnnotationModel amodel = _fDocumentProvider.getAnnotationModel(_fEditorInput);
    if (amodel != null) {
        amodel.disconnect(_fDocumentProvider.getDocument(_fEditorInput));
    }
    _fDocumentProvider.removeElementStateListener(_fElementListener);
    _fDocumentProvider.disconnect(_fEditorInput);
    if ((_fModelListener != null) && _fModel instanceof IModelChangeProvider) {
        ((IModelChangeProvider) _fModel).removeModelChangedListener(_fModelListener);
    }
    if (_fModel != null) {
        _fModel.dispose();
    }
}
Also used : IModelChangeProvider(com.liferay.ide.core.model.IModelChangeProvider) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

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