private void replaceAnnotations(Annotation[] remove, Map<Annotation, Position> add) { final IAnnotationModel model = viewer.getAnnotationModel(); if (model instanceof IAnnotationModelExtension) { final IAnnotationModelExtension eModel = (IAnnotationModelExtension) model; eModel.replaceAnnotations(remove, add); } else { for (final Annotation annotation : remove) { model.removeAnnotation(annotation); } for (final Annotation annotation : add.keySet()) { model.addAnnotation(annotation, add.get(annotation)); } } }
private Annotation[] getAnnotations(final boolean selected) { final String type = selected ? SELECTED_ANNOTATION_TYPE : ANNOTATION_TYPE; final IAnnotationModel model = viewer.getAnnotationModel(); final List<Annotation> annotations = new ArrayList<Annotation>(); if (model != null) { final Iterator<?> it = model.getAnnotationIterator(); while (it.hasNext()) { final Annotation annotation = (Annotation) it.next(); if (type.equals(annotation.getType())) { annotations.add(annotation); } } } return annotations.toArray(new Annotation[annotations.size()]); }
private void addProposals(final SubMenuManager quickFixMenu) { IAnnotationModel sourceModel = sourceViewer.getAnnotationModel(); Iterator annotationIterator = sourceModel.getAnnotationIterator(); while (annotationIterator.hasNext()) { Annotation annotation = (Annotation) annotationIterator.next(); boolean isDeleted = annotation.isMarkedDeleted(); boolean isIncluded = includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset()); boolean isFixable = sourceViewer.getQuickAssistAssistant().canFix(annotation); if (!isDeleted && isIncluded && isFixable) { IQuickAssistProcessor processor = sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor(); IQuickAssistInvocationContext context = sourceViewer.getQuickAssistInvocationContext(); ICompletionProposal[] proposals = processor.computeQuickAssistProposals(context); for (ICompletionProposal proposal : proposals) quickFixMenu.add(createQuickFixAction(proposal)); } } }
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { if (oldInput != null) { annotationModel.disconnect(oldInput); } if (newInput != null && sourceViewer != null) { IAnnotationModel originalAnnotationModel = sourceViewer.getAnnotationModel(); if (originalAnnotationModel instanceof IAnnotationModelExtension) { IAnnotationModelExtension annotationModelExtension = (IAnnotationModelExtension) originalAnnotationModel; annotationModelExtension.addAnnotationModel( ReviewsUiPlugin.PLUGIN_ID, originalAnnotationModel); } else { try { Class<SourceViewer> sourceViewerClazz = SourceViewer.class; Field declaredField2 = sourceViewerClazz.getDeclaredField("fVisualAnnotationModel"); declaredField2.setAccessible(true); Method declaredMethod = sourceViewerClazz.getDeclaredMethod( "createVisualAnnotationModel", IAnnotationModel.class); declaredMethod.setAccessible(true); originalAnnotationModel = (IAnnotationModel) declaredMethod.invoke(sourceViewer, annotationModel); declaredField2.set(sourceViewer, originalAnnotationModel); originalAnnotationModel.connect(newInput); sourceViewer.showAnnotations(true); createVerticalRuler(newInput, sourceViewerClazz); createOverviewRuler(newInput, sourceViewerClazz); createHighlighting(sourceViewerClazz); } catch (Throwable t) { StatusHandler.log( new Status( IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error attaching annotation model", t)); } } } }