private static boolean isProblemMarkerAnnotation(Annotation annotation) { if (!(annotation instanceof MarkerAnnotation)) return false; try { return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM)); } catch (CoreException e) { return false; } }
@Override public boolean canFix(Annotation annotation) { if (annotation.isMarkedDeleted()) { return false; } if (annotation instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; if (!markerAnnotation.isQuickFixableStateSet()) { markerAnnotation.setQuickFixable(quickFixer.hasResolutions(markerAnnotation.getMarker())); } return markerAnnotation.isQuickFixable(); } return false; }
/** * Creates a new annotation for the given marker. * <p> * Subclasses may override.</p> * * @param marker the marker * @return the new marker annotation */ protected MarkerAnnotation createMarkerAnnotation(IMarker marker) { return new MarkerAnnotation(marker); }
protected void updateMarkerAnnotations(IProgressMonitor monitor) { if (monitor.isCanceled()) { return; } Iterator<MarkerAnnotation> annotationIterator = Iterators.filter(annotationModel.getAnnotationIterator(), MarkerAnnotation.class); // every markerAnnotation produced by fast validation can be marked as deleted. // If its predicate still holds, the validation annotation will be covered anyway. while (annotationIterator.hasNext() && !monitor.isCanceled()) { final MarkerAnnotation annotation = annotationIterator.next(); if (!annotation.isMarkedDeleted()) try { if (isRelevantAnnotationType(annotation.getType())) { boolean markAsDeleted = annotation.getMarker().isSubtypeOf(MarkerTypes.FAST_VALIDATION); if (markAsDeleted) { annotation.markDeleted(true); queueOrFireAnnotationChangedEvent(annotation); } } } catch (CoreException e) { // marker type cannot be resolved - keep state of annotation } } fireQueuedEvents(); }
if (fImage == null) { IMarker marker= getMarker(); if (marker.exists()) { IWorkbenchAdapter adapter= (IWorkbenchAdapter) marker.getAdapter(IWorkbenchAdapter.class); ImageDescriptor descriptor= adapter.getImageDescriptor(marker); if (descriptor != null) fImage= getImage(display, descriptor); fImage= getImage(fImageName);
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
IMarker marker= getMarker(); String name= getUnknownImageName(marker);
public boolean canFix(Annotation annotation) { if (annotation.isMarkedDeleted()) return false; // non-persisted annotation if (annotation instanceof XtextAnnotation) { XtextAnnotation a = (XtextAnnotation) annotation; return getResolutionProvider().hasResolutionFor(a.getIssueCode()); } // persisted markerAnnotation if (annotation instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; if (!markerAnnotation.isQuickFixableStateSet()) markerAnnotation.setQuickFixable(getResolutionProvider().hasResolutionFor( issueUtil.getCode(markerAnnotation))); return markerAnnotation.isQuickFixable(); } if (annotation instanceof SpellingAnnotation) { return true; } return false; }
private Map<String, Image> getImages(Annotation annotation) { if(annotation.isMarkedDeleted()) return XtextPluginImages.getAnnotationImagesDeleted(); else { if (annotation instanceof MarkerAnnotation) { MarkerAnnotation ma = (MarkerAnnotation) annotation; if(ma.isQuickFixableStateSet() && ma.isQuickFixable()) return XtextPluginImages.getAnnotationImagesFixable(); } return XtextPluginImages.getAnnotationImagesNonfixable(); } } }
/** * {@inheritDoc} * * @since 3.4 */ @Override public boolean isQuickFixable() { Assert.isTrue(isQuickFixableStateSet()); return fIsQuickFixable; }
/** * Implement this method to draw a graphical representation of this * annotation within the given bounds. This default implementation does * nothing. * <p> * Note: This is only for backward compatibility. * </p> * @param gc the drawing GC * @param canvas the canvas to draw on * @param r the bounds inside the canvas to draw on * @deprecated As of 3.0 replaced by {@link org.eclipse.jface.text.source.IAnnotationAccessExtension#paint(org.eclipse.jface.text.source.Annotation, GC, Canvas, Rectangle)} * @since 3.0 */ @Deprecated public void paint(GC gc, Canvas canvas, Rectangle r) { Image image= getImage(canvas.getDisplay()); if (image != null) ImageUtilities.drawImage(image, gc, canvas, r, SWT.CENTER, SWT.TOP); }
/** * Returns an image for the given display as specified by the given image * descriptor. * * @param display the display * @param descriptor the image descriptor * @return an image for the display as specified by the descriptor * @deprecated As of 3.0, visual presentation is no longer supported, * annotation with a visible presentation should implement * {@link org.eclipse.jface.text.source.IAnnotationPresentation} */ protected static Image getImage(Display display, ImageDescriptor descriptor) { Map map= getImageRegistry(display); Image image= (Image) map.get(descriptor); if (image == null) { image= descriptor.createImage(); map.put(descriptor, image); } return image; }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
IMarker marker= getMarker(); String name= getUnknownImageName(marker);
/** * Returns an image for this annotation. It first consults the workbench * adapter for this annotation's marker. If none is defined, it tries to * find an image for the image name of this annotation. * * @param display the display for which the image is requested * @return the image for this annotation * @deprecated As of 3.0, visual presentation is no longer supported, * annotation with a visible presentation should implement * {@link org.eclipse.jface.text.source.IAnnotationPresentation} */ @Deprecated protected Image getImage(Display display) { if (fImage == null) { IMarker marker= getMarker(); if (marker.exists()) { IWorkbenchAdapter adapter= marker.getAdapter(IWorkbenchAdapter.class); if (adapter != null) { ImageDescriptor descriptor= adapter.getImageDescriptor(marker); if (descriptor != null) fImage= getImage(display, descriptor); } } if (fImage == null) fImage= getImage(fImageName); } return fImage; }
protected boolean hasQuickFixableAnnotationInCurrentLine() { try { AbstractMarkerAnnotationModel annotationModel = getAnnotationModel(); int line = ruler.getLineOfLastMouseButtonActivity(); IDocument document = getDocument(); IRegion region = document.getLineInformation(line); Iterator<?> iterator = annotationModel.getAnnotationIterator(region .getOffset(), region.getLength(), true, true); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof XtextAnnotation) { XtextAnnotation annotation = (XtextAnnotation) element; if (annotation.isQuickFixable()) return true; } else if (element instanceof MarkerAnnotation) { MarkerAnnotation annotation = (MarkerAnnotation) element; if (annotation.isQuickFixableStateSet() && annotation.isQuickFixable()) return true; } } } catch (BadLocationException e) { // Ignore -> false is returned anyway } return false; }
/** * Implement this method to draw a graphical representation of this * annotation within the given bounds. This default implementation does * nothing. * <p> * Note: This is only for backward compatibility. * </p> * @param gc the drawing GC * @param canvas the canvas to draw on * @param r the bounds inside the canvas to draw on * @deprecated As of 3.0 replaced by {@link org.eclipse.jface.text.source.IAnnotationAccessExtension#paint(org.eclipse.jface.text.source.Annotation, GC, Canvas, Rectangle)} * @since 3.0 */ public void paint(GC gc, Canvas canvas, Rectangle r) { Image image= getImage(canvas.getDisplay()); if (image != null) ImageUtilities.drawImage(image, gc, canvas, r, SWT.CENTER, SWT.TOP); }
/** * Returns an image for the given display as specified by the given image * descriptor. * * @param display the display * @param descriptor the image descriptor * @return an image for the display as specified by the descriptor * @deprecated As of 3.0, visual presentation is no longer supported, * annotation with a visible presentation should implement * {@link org.eclipse.jface.text.source.IAnnotationPresentation} */ @Deprecated protected static Image getImage(Display display, ImageDescriptor descriptor) { Map<ImageDescriptor, Image> map= getImageRegistry(display); Image image= map.get(descriptor); if (image == null) { image= descriptor.createImage(); map.put(descriptor, image); } return image; }
private static boolean isProblemMarkerAnnotation(Annotation annotation) { if (!(annotation instanceof MarkerAnnotation)) return false; try { return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM)); } catch (CoreException e) { return false; } }