private synchronized void checkFile() { if (fActiveEditor == null) return; IEditorInput input = fActiveEditor.getEditorInput(); IPath location = null; if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); location = file.getLocation(); } else if (input instanceof FileStoreEditorInput) { location = URIUtil.toPath(((FileStoreEditorInput) input).getURI()); } else if (input instanceof CommonSourceNotFoundEditorInput) { Object artifact = ((CommonSourceNotFoundEditorInput) input).getArtifact(); if (artifact instanceof CSourceNotFoundElement) { location = new Path(((CSourceNotFoundElement) artifact).getFile()); } } if (location != null && fExpectedFile != null && location.lastSegment().equals(fExpectedFile.lastSegment())) { fFileFound = true; if (fActiveEditor instanceof ITextEditor) { IDocumentProvider docProvider = ((ITextEditor) fActiveEditor).getDocumentProvider(); fAnnotationModel = docProvider.getAnnotationModel(fActiveEditor.getEditorInput()); fAnnotationModel.addAnnotationModelListener(this); checkAnnotations(); } else if (fActiveEditor instanceof CommonSourceNotFoundEditor) { // No annotation will be painted if source not found. fAnnotationFound = true; } } }
void removeOccurrenceAnnotations() { fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; fMarkOccurrenceTargetRegion = null; final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider(); if (documentProvider == null) { return; } final IAnnotationModel annotationModel = documentProvider.getAnnotationModel(erlangEditor.getEditorInput()); if (annotationModel == null || fOccurrenceAnnotations == null) { return; } synchronized (erlangEditor.getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension) annotationModel) .replaceAnnotations(fOccurrenceAnnotations, null); } else { for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++) { annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); } } fOccurrenceAnnotations = null; } }
/** * 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 attach a annotation model to */ public static boolean attach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); IEditorInput input = editor.getEditorInput(); if (provider != null && input instanceof FileEditorInput) { IAnnotationModel model = provider.getAnnotationModel(input); if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension modelex = (IAnnotationModelExtension) model; ColorAnnotationModel colormodel = (ColorAnnotationModel) modelex.getAnnotationModel(KEY); if (colormodel == null) { IFile file = ((FileEditorInput) input).getFile(); IFeatureProject project = CorePlugin.getFeatureProject(file); if (project != null && project.getComposer() != null && project.getComposer().needColor()) { IDocument document = provider.getDocument(input); colormodel = new ColorAnnotationModel(document, file, project, editor); modelex.addAnnotationModel(KEY, colormodel); return true; } } else { colormodel.updateAnnotations(!editor.isDirty()); } } } return false; }
/** * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input. * * @return the marker annotation model */ protected AbstractMarkerAnnotationModel getAnnotationModel() { IDocumentProvider provider = fTextEditor.getDocumentProvider(); IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput()); if (model instanceof AbstractMarkerAnnotationModel) { return (AbstractMarkerAnnotationModel) model; } return null; }
/** * Detaches the coverage annotation model from the given editor. If the editor does not have a * model attached, this method does nothing. * * @param editor Editor to detach the annotation model from */ public static void detach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); // there may be text editors without document providers (SF #1725100) if (provider == null) return; IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput()); if (!(model instanceof IAnnotationModelExtension)) return; IAnnotationModelExtension modelex = (IAnnotationModelExtension) model; modelex.removeAnnotationModel(KEY); }
private IAnnotationModel getAnnotationModel() { if (fTextEditor == null) { return null; } final IDocumentProvider documentProvider = fTextEditor.getDocumentProvider(); if (documentProvider == null) { return null; } return documentProvider.getAnnotationModel(fTextEditor.getEditorInput()); }
/** * Detaches the coverage annotation model from the given editor. If the editor does not have a * model attached, this method does nothing. * * @param editor Editor to detach the annotation model from */ public static void detach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); if (provider != null) { IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput()); if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension modelex = (IAnnotationModelExtension) model; modelex.removeAnnotationModel(KEY); } } }
protected IAnnotationModel getAnnotationModel(XtextEditor editor) { if (editor != null) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput != null) { IDocumentProvider documentProvider = editor.getDocumentProvider(); if (documentProvider != null) { return documentProvider.getAnnotationModel(editorInput); } } } return null; }
/** * 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 attach a annotation model to */ public static void attach(ITextEditor editor) { IDocumentProvider provider = editor.getDocumentProvider(); // there may be text editors without document providers (SF #1725100) 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()); CoverageAnnotationModel coveragemodel = (CoverageAnnotationModel) modelex.getAnnotationModel(KEY); if (coveragemodel == null) { coveragemodel = new CoverageAnnotationModel(editor, document); modelex.addAnnotationModel(KEY, coveragemodel); } }
public void removeAnnotations() { final IDocumentProvider docProvider = fEditor.getDocumentProvider(); if (docProvider == null) { return; } IAnnotationModel model = docProvider.getAnnotationModel(fEditor.getEditorInput()); if (model == null) return; for (Iterator i = model.getAnnotationIterator(); i.hasNext(); ) { Annotation a = (Annotation) i.next(); if (a.getType().equals(fAnnotationType)) model.removeAnnotation(a); } }
private void initializeSourceViewer(IEditorInput input) { IDocumentProvider documentProvider = getDocumentProvider(); IAnnotationModel model = documentProvider.getAnnotationModel(input); IDocument document = documentProvider.getDocument(input); if (document != null) { fSourceViewer.setDocument(document, model); fSourceViewer.setEditable(isEditable()); fSourceViewer.showAnnotations(model != null); } if (fElementStateListener instanceof IElementStateListenerExtension) { boolean isStateValidated = false; if (documentProvider instanceof IDocumentProviderExtension) isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input); IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener; extension.elementStateValidationChanged(input, isStateValidated); } }
@Nullable private DiagnosticAnnotation getAnnotationByOffset(int offset) { AbstractTextEditor editor = getActiveEditor(); if (editor == null) { return null; } IDocumentProvider documentProvider = editor.getDocumentProvider(); IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editor.getEditorInput()); for (Iterator<?> i = annotationModel.getAnnotationIterator(); i.hasNext(); ) { Annotation annotation = (Annotation) i.next(); if (annotation instanceof DiagnosticAnnotation) { DiagnosticAnnotation diagnosticAnnotation = (DiagnosticAnnotation) annotation; TextRange range = diagnosticAnnotation.getRange(); if (range.getStartOffset() <= offset && range.getEndOffset() >= offset) { return diagnosticAnnotation; } } } return null; }
private void findAnnotation() { mPosition = null; mCanFix = false; IDocumentProvider provider = mTextEditor.getDocumentProvider(); IAnnotationModel model = provider.getAnnotationModel(mTextEditor.getEditorInput()); IAnnotationAccessExtension annotationAccess = getAnnotationAccessExtension(); IDocument document = getDocument(); if (model == null) { return; } Iterator<?> iter = model.getAnnotationIterator(); int layer = Integer.MIN_VALUE; while (iter.hasNext()) { Annotation annotation = (Annotation) iter.next(); if (annotation.isMarkedDeleted()) { continue; } int annotationLayer = Integer.MAX_VALUE; if (annotationAccess != null) { annotationLayer = annotationAccess.getLayer(annotation); if (annotationLayer < layer) { continue; } } Position position = model.getPosition(annotation); if (!includesRulerLine(position, document)) { continue; } boolean isReadOnly = mTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension) mTextEditor).isEditorInputReadOnly(); if (!isReadOnly && annotation instanceof INIProblemAnnotation && ((INIProblemAnnotation) annotation).isQuickFixable()) { mPosition = position; mCanFix = true; layer = annotationLayer; continue; } else { AnnotationPreference preference = mAnnotationPreferenceLookup.getAnnotationPreference(annotation); if (preference == null) { continue; } String key = preference.getVerticalRulerPreferenceKey(); if (key == null) { continue; } if (mStore.getBoolean(key)) { mPosition = position; mCanFix = false; layer = annotationLayer; } } } }
/* * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus run(IProgressMonitor progressMonitor) { if (isCanceled(progressMonitor)) { return Status.CANCEL_STATUS; } ITextViewer textViewer = editor.getISourceViewer(); if (textViewer == null) { return Status.CANCEL_STATUS; } IDocument document = textViewer.getDocument(); if (document == null) { return Status.CANCEL_STATUS; } IDocumentProvider documentProvider = editor.getDocumentProvider(); if (documentProvider == null) { return Status.CANCEL_STATUS; } IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editor.getEditorInput()); if (annotationModel == null) { return Status.CANCEL_STATUS; } int length = fLocations.length; Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(length); for (int i = 0; i < length; i++) { if (isCanceled(progressMonitor)) { return Status.CANCEL_STATUS; } OccurrenceLocation occurrence = fLocations[i]; Position position = new Position(occurrence.getOffset(), occurrence.getLength()); String description = occurrence.getDescription(); String annotationType = (occurrence.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE) ? WRITE_OCCURRENCE_ID : READ_OCCURRENCE_ID; /* * // create an annotation to mark the occurrence ReconcileAnnotationKey reconcileAnnotationKey = new * ReconcileAnnotationKey(null, PHPPartitionTypes.PHP_DEFAULT, ReconcileAnnotationKey.TOTAL); * TemporaryAnnotation annotation = new TemporaryAnnotation(position, annotationType, description, * reconcileAnnotationKey) { */ /** * Paint the ruler annotation. * * @param gc * @param canvas * @param r */ /* * @Override public void paint(GC gc, Canvas canvas, Rectangle r) { // TODO - Shalom: Change this image * location ImageUtilities.drawImage(PHPUiPlugin.getImageDescriptorRegistry().get( * PHPPluginImages.DESC_OBJS_OCCURRENCES), gc, canvas, r, SWT.CENTER, SWT.TOP); } }; */ Annotation annotation = new Annotation(annotationType, false, description); annotationMap.put(annotation, position); } if (isCanceled(progressMonitor)) return Status.CANCEL_STATUS; synchronized (getAnnotationModelLock(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension) annotationModel) .replaceAnnotations(fOccurrenceAnnotations, annotationMap); } else { removeOccurrenceAnnotations(); for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) { annotationModel.addAnnotation(entry.getKey(), entry.getValue()); } } fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); } return Status.OK_STATUS; }
/* * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) */ @Override public IStatus run(final IProgressMonitor progressMonitor) { findRefs(module, selection, fHasChanged); if (fRefs == null) { return Status.CANCEL_STATUS; } if (isCanceled(progressMonitor)) { return Status.CANCEL_STATUS; } final ITextViewer textViewer = erlangEditor.getViewer(); if (textViewer == null) { return Status.CANCEL_STATUS; } final IDocument document = textViewer.getDocument(); if (document == null) { return Status.CANCEL_STATUS; } final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider(); if (documentProvider == null) { return Status.CANCEL_STATUS; } final IAnnotationModel annotationModel = documentProvider.getAnnotationModel(erlangEditor.getEditorInput()); if (annotationModel == null) { return Status.CANCEL_STATUS; } // Add occurrence annotations final HashMap<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(fRefs.size()); for (final MarkOccurencesHandler.ErlangRef ref : fRefs) { if (isCanceled(progressMonitor)) { return Status.CANCEL_STATUS; } final Position position = new Position(ref.getOffset(), ref.getLength()); final String description = ref.getDescription(); final String annotationType = ref.isDef() ? "org.erlide.ui.occurrences.definition" //$NON-NLS-1$ : "org.erlide.ui.occurrences"; annotationMap.put(new Annotation(annotationType, false, description), position); } if (isCanceled(progressMonitor)) { return Status.CANCEL_STATUS; } synchronized (erlangEditor.getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension) annotationModel) .replaceAnnotations( erlangEditor.markOccurencesHandler.fOccurrenceAnnotations, annotationMap); } else { erlangEditor.markOccurencesHandler.removeOccurrenceAnnotations(); for (final Map.Entry<Annotation, Position> mapEntry : annotationMap.entrySet()) { annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue()); } } erlangEditor.markOccurencesHandler.fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); } return Status.OK_STATUS; }
private IProblemRequestorExtension getProblemRequestorExtension() { IAnnotationModel model = fDocumentProvider.getAnnotationModel(fEditor.getEditorInput()); if (model instanceof IProblemRequestorExtension) return (IProblemRequestorExtension) model; return null; }
private void updateAnnotations(IWorkbenchWindow window, TCFNode node, Set<TCFAnnotation> set) { if (disposed) return; assert Thread.currentThread() == display.getThread(); WorkbenchWindowInfo win_info = windows.get(window); if (win_info == null) return; Map<IEditorInput, IEditorPart> editors = new HashMap<IEditorInput, IEditorPart>(); Map<IViewPart, ITCFDisassemblyPart> views = new HashMap<IViewPart, ITCFDisassemblyPart>(); IWorkbenchPage page = window.getActivePage(); if (page != null) { for (IEditorReference ref : page.getEditorReferences()) { IEditorPart editor = ref.getEditor(false); if (editor == null) continue; editors.put(editor.getEditorInput(), editor); } for (IViewReference ref : page.getViewReferences()) { IViewPart view = ref.getView(false); if (view == null) continue; ITCFDisassemblyPart disasm = (ITCFDisassemblyPart) view.getAdapter(ITCFDisassemblyPart.class); if (disasm != null) views.put(view, disasm); } } boolean flush_all = node == null || !views.keySet().equals(win_info.views.keySet()) || !editors.equals(win_info.editors) || changed_launch_cfgs.contains(node.launch); win_info.views.clear(); win_info.views.putAll(views); win_info.editors.clear(); win_info.editors.putAll(editors); Iterator<TCFAnnotation> i = win_info.annotations.iterator(); while (i.hasNext()) { TCFAnnotation a = i.next(); if (!flush_all && set != null && set.remove(a)) continue; a.dispose(); i.remove(); } if (set != null) win_info.annotations.addAll(set); ISourcePresentation presentation = TCFModelPresentation.getDefault(); // Disassembly views for (TCFAnnotation a : win_info.annotations) { if (a.addr == null) continue; for (ITCFDisassemblyPart disasm : views.values()) { IAnnotationModel ann_model = disasm.getAnnotationModel(); if (ann_model == null) continue; if (a.models.contains(ann_model)) { ann_model.removeAnnotation(a); a.models.remove(ann_model); } Position p = disasm.getAddressPosition(a.addr); if (p == null) continue; if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue; ann_model.addAnnotation(a, p); a.models.add(ann_model); } } // Disassembly editor for (TCFAnnotation a : win_info.annotations) { if (a.addr == null) continue; IEditorPart editor = editors.get(TCFModel.DisassemblyEditorInput.INSTANCE); if (editor == null) continue; ITCFDisassemblyPart disasm = (ITCFDisassemblyPart) editor.getAdapter(ITCFDisassemblyPart.class); if (disasm == null) continue; IAnnotationModel ann_model = disasm.getAnnotationModel(); if (ann_model == null) continue; if (a.models.contains(ann_model)) { ann_model.removeAnnotation(a); a.models.remove(ann_model); } Position p = disasm.getAddressPosition(a.addr); if (p == null) continue; if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue; ann_model.addAnnotation(a, p); a.models.add(ann_model); } // Source editors if (set == null) return; for (TCFAnnotation a : set) { if (a.area == null) continue; Object source_element = TCFSourceLookupDirector.lookup(node.launch, a.ctx, a.area); if (source_element == null) continue; IEditorInput editor_input = presentation.getEditorInput(source_element); IEditorPart editor = editors.get(editor_input); if (!(editor instanceof ITextEditor)) continue; IDocumentProvider doc_provider = ((ITextEditor) editor).getDocumentProvider(); IAnnotationModel ann_model = doc_provider.getAnnotationModel(editor_input); if (ann_model == null) continue; IRegion region = null; try { doc_provider.connect(editor_input); } catch (CoreException e) { } try { IDocument document = doc_provider.getDocument(editor_input); if (document != null) region = document.getLineInformation(a.area.start_line - 1); } catch (BadLocationException e) { } finally { doc_provider.disconnect(editor_input); } if (region == null) continue; Position p = new Position(region.getOffset(), region.getLength()); if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue; ann_model.addAnnotation(a, p); a.models.add(ann_model); } }