Search in sources :

Example 31 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class MarkerAnnotationOrderTest method testDirectDependency.

@Test
public void testDirectDependency() {
    final ArrayList<IStatus> list = new ArrayList<>(2);
    Bundle bundle = Platform.getBundle(EditorsUI.PLUGIN_ID);
    ILog log = Platform.getLog(bundle);
    log.addLogListener(new ILogListener() {

        @Override
        public void logging(IStatus status, String plugin) {
            list.add(status);
        }
    });
    TestMarkerAnnotationModel t1 = new TestMarkerAnnotationModel();
    Position position = new Position(0);
    position.delete();
    IDocument d = null;
    try {
        t1.updateMarker(d, null, position);
    } catch (CoreException e) {
        fail("update marker failed to execute");
        log(e);
    }
    assertEquals("Wrong number of messages", 2, list.size());
    assertEquals("Wrong Message for first status", "Marker Updater 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest2' and 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1' depend on each other, 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest2' will run before 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1'", ((Status) list.get(0)).getMessage());
    assertEquals("Wrong Message for second status", "Marker Updater 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest4' and 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1' depend on each other, 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest4' will run before 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1'", ((Status) list.get(1)).getMessage());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) Position(org.eclipse.jface.text.Position) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ILog(org.eclipse.core.runtime.ILog) ILogListener(org.eclipse.core.runtime.ILogListener) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 32 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class EditorAccessHighlighter method addAnnotations.

private void addAnnotations(IAnnotationModel model, Map<Annotation, Position> annotationToPositionMap) {
    if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension ame = (IAnnotationModelExtension) model;
        ame.replaceAnnotations(new Annotation[0], annotationToPositionMap);
    } else {
        for (Annotation element : annotationToPositionMap.keySet()) {
            Position p = annotationToPositionMap.get(element);
            model.addAnnotation(element, p);
        }
    }
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation)

Example 33 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class EditorAccessHighlighter method addHighlights.

@Override
public void addHighlights(Match[] matches) {
    Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel = new HashMap<>();
    for (Match match : matches) {
        int offset = match.getOffset();
        int length = match.getLength();
        if (offset >= 0 && length >= 0) {
            try {
                Position position = createPosition(match);
                if (position != null) {
                    Map<Annotation, Position> map = getMap(mapsByAnnotationModel, match);
                    if (map != null) {
                        Annotation annotation = match.isFiltered() ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null);
                        fMatchesToAnnotations.put(match, annotation);
                        map.put(annotation, position);
                    }
                }
            } catch (BadLocationException e) {
                SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e));
            }
        }
    }
    for (Entry<IAnnotationModel, HashMap<Annotation, Position>> entry : mapsByAnnotationModel.entrySet()) {
        addAnnotations(entry.getKey(), entry.getValue());
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException) Match(org.eclipse.search.ui.text.Match)

Example 34 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class EditorAccessHighlighter method getMap.

private Map<Annotation, Position> getMap(Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel, Match match) {
    IAnnotationModel model = fEditorAcess.getAnnotationModel(match);
    if (model == null)
        return null;
    HashMap<Annotation, Position> map = mapsByAnnotationModel.get(model);
    if (map == null) {
        map = new HashMap<>();
        mapsByAnnotationModel.put(model, map);
    }
    return map;
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 35 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class MarkerHighlighter method createMarker.

private IMarker createMarker(Match match) throws CoreException {
    Position position = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
    if (position == null) {
        if (match.getOffset() < 0 || match.getLength() < 0)
            return null;
        position = new Position(match.getOffset(), match.getLength());
    } else {
        // need to clone position, can't have it twice in a document.
        position = new Position(position.getOffset(), position.getLength());
    }
    IMarker marker = match.isFiltered() ? fFile.createMarker(SearchPlugin.FILTERED_SEARCH_MARKER) : fFile.createMarker(NewSearchUI.SEARCH_MARKER);
    HashMap<String, Integer> attributes = new HashMap<>(4);
    if (match.getBaseUnit() == Match.UNIT_CHARACTER) {
        attributes.put(IMarker.CHAR_START, Integer.valueOf(position.getOffset()));
        attributes.put(IMarker.CHAR_END, Integer.valueOf(position.getOffset() + position.getLength()));
    } else {
        attributes.put(IMarker.LINE_NUMBER, Integer.valueOf(position.getOffset()));
    }
    marker.setAttributes(attributes);
    return marker;
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

Position (org.eclipse.jface.text.Position)421 BadLocationException (org.eclipse.jface.text.BadLocationException)145 Annotation (org.eclipse.jface.text.source.Annotation)110 IDocument (org.eclipse.jface.text.IDocument)80 ArrayList (java.util.ArrayList)75 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)57 IRegion (org.eclipse.jface.text.IRegion)55 Test (org.junit.Test)54 HashMap (java.util.HashMap)49 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)46 Point (org.eclipse.swt.graphics.Point)40 List (java.util.List)39 Iterator (java.util.Iterator)31 TypedPosition (org.eclipse.jface.text.TypedPosition)31 Region (org.eclipse.jface.text.Region)27 IFile (org.eclipse.core.resources.IFile)22 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)21 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)21 Map (java.util.Map)15 CoreException (org.eclipse.core.runtime.CoreException)15