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