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());
}
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);
}
}
}
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());
}
}
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;
}
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;
}
Aggregations