use of org.eclipse.jface.text.source.projection.AnnotationBag in project eclipse.platform.text by eclipse.
the class DefaultMarkerAnnotationAccess method getImage.
/**
* Returns the image for the given annotation and the given annotation preferences or
* <code>null</code> if there is no such image.
*
* @param annotation the annotation
* @param preference the annotation preference
* @param annotationType the annotation type
* @return the image or <code>null</code>
* @since 3.0
*/
private Image getImage(Annotation annotation, AnnotationPreference preference, String annotationType) {
if (annotation instanceof AnnotationBag) {
AnnotationBag bag = (AnnotationBag) annotation;
if (!bag.isEmpty())
annotation = bag.iterator().next();
}
ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
IAnnotationImageProvider annotationImageProvider = preference.getAnnotationImageProvider();
if (annotationImageProvider != null) {
Image image = annotationImageProvider.getManagedImage(annotation);
if (image != null)
return image;
String id = annotationImageProvider.getImageDescriptorId(annotation);
if (id != null) {
image = registry.get(id);
if (image == null) {
ImageDescriptor descriptor = annotationImageProvider.getImageDescriptor(id);
registry.put(id, descriptor);
image = registry.get(id);
}
return image;
}
}
if (annotationType == null)
return null;
if (hasQuickFix(annotation)) {
ImageDescriptor quickFixImageDesc = preference.getQuickFixImageDescriptor();
if (quickFixImageDesc != null) {
Image image = registry.get(quickFixImageDesc.toString());
if (image == null) {
registry.put(quickFixImageDesc.toString(), quickFixImageDesc);
image = registry.get(quickFixImageDesc.toString());
}
if (image != null)
return image;
}
}
Image image = registry.get(annotationType);
if (image == null) {
ImageDescriptor descriptor = preference.getImageDescriptor();
if (descriptor != null) {
registry.put(annotationType, descriptor);
image = registry.get(annotationType);
} else {
String symbolicImageName = preference.getSymbolicImageName();
if (symbolicImageName != null) {
String key = getSharedImageName(preference.getSymbolicImageName());
if (key != null) {
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
image = sharedImages.getImage(key);
}
}
}
}
return image;
}
use of org.eclipse.jface.text.source.projection.AnnotationBag in project eclipse.platform.text by eclipse.
the class DefaultAnnotationHover method getAnnotationsForLine.
private List<Annotation> getAnnotationsForLine(ISourceViewer viewer, int line) {
IAnnotationModel model = getAnnotationModel(viewer);
if (model == null)
return null;
IDocument document = viewer.getDocument();
List<Annotation> javaAnnotations = new ArrayList<>();
HashMap<Position, Object> messagesAtPosition = new HashMap<>();
Iterator<Annotation> iterator = model.getAnnotationIterator();
while (iterator.hasNext()) {
Annotation annotation = iterator.next();
Position position = model.getPosition(annotation);
if (position == null)
continue;
if (!isRulerLine(position, document, line))
continue;
if (annotation instanceof AnnotationBag) {
AnnotationBag bag = (AnnotationBag) annotation;
Iterator<Annotation> e = bag.iterator();
while (e.hasNext()) {
annotation = e.next();
position = model.getPosition(annotation);
if (position != null && includeAnnotation(annotation, position, messagesAtPosition))
javaAnnotations.add(annotation);
}
continue;
}
if (includeAnnotation(annotation, position, messagesAtPosition))
javaAnnotations.add(annotation);
}
return javaAnnotations;
}
Aggregations