/*** * Returns true if it exists a marker annotation in the given offset and false * otherwise. * * @param textViewer * @param offset * @return true if it exists a marker annotation in the given offset and false * otherwise. */ private static boolean hasProblem(ITextViewer textViewer, int offset) { if (!(textViewer instanceof ISourceViewer)) { return false; } IAnnotationModel annotationModel = ((ISourceViewer) textViewer).getAnnotationModel(); Iterator<Annotation> iter = (annotationModel instanceof IAnnotationModelExtension2) ? ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(offset, 1, true, true) : annotationModel.getAnnotationIterator(); while (iter.hasNext()) { Annotation ann = iter.next(); if (ann instanceof MarkerAnnotation) { return true; } } return false; }
@Override public Image getManagedImage(Annotation annotation) { if (!(annotation instanceof MarkerAnnotation)) { return null; } try { MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; IMarker marker = markerAnnotation.getMarker(); if (!BookmarksMarkers.MARKER_TYPE.equals(marker.getType())) { return null; } String attributeBookmarkId = (String) marker.getAttribute(BookmarksMarkers.BOOKMARK_ID); Optional<BookmarkNumber> bookmarkNumber = numberedBookmarks .getBookmarkNumber(new BookmarkId(attributeBookmarkId)); return getBookmarkAnnotationImage(bookmarkNumber); } catch (CoreException e) { return null; } }
protected List<Annotation> getAnnotationsToRemove(IProgressMonitor monitor) { if (monitor.isCanceled() || annotationModel == null) { return Lists.newArrayList(); } @SuppressWarnings("unchecked") Iterator<Annotation> annotationIterator = annotationModel.getAnnotationIterator(); List<Annotation> toBeRemoved = Lists.newArrayList(); while (annotationIterator.hasNext()) { if (monitor.isCanceled()) { return toBeRemoved; } Annotation annotation = annotationIterator.next(); String type = annotation.getType(); if (isRelevantAnnotationType(type)) { if (!(annotation instanceof MarkerAnnotation)) { toBeRemoved.add(annotation); } } } return toBeRemoved; }
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; }
/** * Returns one marker which includes the ruler's line of activity. */ protected IMarker getMarkerForLine(ISourceViewer aViewer, int aLine) { IMarker marker = null; IAnnotationModel model = aViewer.getAnnotationModel(); if (model != null) { Iterator e = model.getAnnotationIterator(); while (e.hasNext()) { Object o = e.next(); if (o instanceof MarkerAnnotation) { MarkerAnnotation a = (MarkerAnnotation) o; if (compareRulerLine(model.getPosition(a), aViewer.getDocument(), aLine) != 0) { marker = a.getMarker(); } } } } return marker; }
/** * DOCUMENT ME! * * @param aMessage * DOCUMENT ME! * @param aLine * DOCUMENT ME! */ public void addProblemMarker(String aMessage, int aLine, int severity) { IFile file = ((IFileEditorInput) getEditorInput()).getFile(); try { IMarker marker = file.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.SEVERITY, severity); marker.setAttribute(IMarker.MESSAGE, aMessage); marker.setAttribute(IMarker.LINE_NUMBER, aLine); Position pos = new Position(getDocument().getLineOffset(aLine - 1)); getSourceViewer().getAnnotationModel().addAnnotation(new MarkerAnnotation(marker), pos); } catch (Exception e) { VelocityPlugin.log(e); } }
/** * Returns one marker which includes the ruler's line of activity. */ protected IMarker getMarkerForLine(ISourceViewer aViewer, int aLine) { IMarker marker = null; IAnnotationModel model = aViewer.getAnnotationModel(); if (model != null) { Iterator e = model.getAnnotationIterator(); while (e.hasNext()) { Object o = e.next(); if (o instanceof MarkerAnnotation) { MarkerAnnotation a = (MarkerAnnotation)o; if (compareRulerLine(model.getPosition(a), aViewer.getDocument(), aLine) != 0) { marker = a.getMarker(); } } } } return marker; }
protected List<IMarker> getMarkersFor(ISourceViewer sourceViewer, int lineOffset, int lineLength) { List<IMarker> result = Lists.newArrayList(); IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); Iterator annotationIter = annotationModel.getAnnotationIterator(); while (annotationIter.hasNext()) { Object annotation = annotationIter.next(); if (annotation instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; IMarker marker = markerAnnotation.getMarker(); Position markerPosition = annotationModel.getPosition(markerAnnotation); if (markerPosition != null && markerPosition.overlapsWith(lineOffset, lineLength)) { result.add(marker); } } } return result; }
@Override protected void updateMarkerViews(Annotation annotation) { if (annotation instanceof IJavaAnnotation) { Iterator<IJavaAnnotation> e= ((IJavaAnnotation) annotation).getOverlaidIterator(); if (e != null) { while (e.hasNext()) { Object o= e.next(); if (o instanceof MarkerAnnotation) { super.updateMarkerViews((MarkerAnnotation)o); return; } } } return; } super.updateMarkerViews(annotation); }
private void testIfProblemMarker(Annotation annotation) { if (fIncludesProblemMarkerAnnotations) { return; } if (annotation instanceof JavaMarkerAnnotation) { fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem(); } else if (annotation instanceof MarkerAnnotation) { try { IMarker marker= ((MarkerAnnotation) annotation).getMarker(); if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) { fIncludesProblemMarkerAnnotations= true; } } catch (CoreException e) { JavaPlugin.log(e); } } }
private void findAndDeleteUnusedImports(PySelection ps, PyEdit edit, IDocumentExtension4 doc, IFile f) throws Exception { Iterator<MarkerAnnotationAndPosition> it; if (edit != null) { it = edit.getPySourceViewer().getMarkerIterator(); } else { IMarker markers[] = f.findMarkers(IMiscConstants.PYDEV_ANALYSIS_PROBLEM_MARKER, true, IResource.DEPTH_ZERO); MarkerAnnotationAndPosition maap[] = new MarkerAnnotationAndPosition[markers.length]; int ix = 0; for (IMarker m : markers) { int start = (Integer) m.getAttribute(IMarker.CHAR_START); int end = (Integer) m.getAttribute(IMarker.CHAR_END); maap[ix++] = new MarkerAnnotationAndPosition(new MarkerAnnotation(m), new Position(start, end - start)); } it = Arrays.asList(maap).iterator(); } ArrayList<MarkerAnnotationAndPosition> unusedImportsMarkers = getUnusedImports(it); sortInReverseDocumentOrder(unusedImportsMarkers); deleteImports(doc, ps, unusedImportsMarkers); }
protected void updateMarkerAnnotation(IMarker marker) { Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); for (Annotation ann : (Iterable<Annotation>) () -> iter) { if(ann instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation) ann; if(markerAnnotation.getMarker().equals(marker)) { Position position = annotationModel.getPosition(markerAnnotation); // Trigger a model update. annotationModelExt.modifyAnnotationPosition(markerAnnotation, position); return; } } } }
@Override protected boolean isIncluded(Annotation annotation) { if (annotation instanceof MarkerAnnotation) { return true; } /* we do not support other annotations */ return false; }
/** * Find a problem marker from the given line and return its error message. * * @param sourceViewer the source viewer * @param lineNumber line number in the file, starting from zero * @return the message of the marker of null, if no marker at the specified line */ public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { IDocument document= sourceViewer.getDocument(); IAnnotationModel model= sourceViewer.getAnnotationModel(); if (model == null) return null; List<String> lineMarkers = null; Iterator<Annotation> e= model.getAnnotationIterator(); while (e.hasNext()) { Annotation o= e.next(); if (o instanceof MarkerAnnotation) { MarkerAnnotation a= (MarkerAnnotation) o; if (isRulerLine(model.getPosition(a), document, lineNumber)) { if (lineMarkers == null) lineMarkers = new LinkedList<String>(); lineMarkers.add(a.getMarker().getAttribute(IMarker.MESSAGE, null)); } } } if (lineMarkers != null) return getMessage(lineMarkers); return null; }
public Issue getIssueFromAnnotation(Annotation annotation) { if (annotation instanceof XtextAnnotation) { XtextAnnotation xtextAnnotation = (XtextAnnotation) annotation; return xtextAnnotation.getIssue(); } else if(annotation instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation; return createIssue(markerAnnotation.getMarker()); } else return null; }
public String getCode(Annotation annotation) { if (annotation instanceof MarkerAnnotation) { MarkerAnnotation ma = (MarkerAnnotation) annotation; return getCode(ma.getMarker()); } if (annotation instanceof XtextAnnotation) { XtextAnnotation xa = (XtextAnnotation) annotation; return xa.getIssueCode(); } return null; }
public String[] getIssueData(Annotation annotation) { if (annotation instanceof MarkerAnnotation) { MarkerAnnotation ma = (MarkerAnnotation) annotation; return getIssueData(ma.getMarker()); } if (annotation instanceof XtextAnnotation) { XtextAnnotation xa = (XtextAnnotation) annotation; return xa.getIssueData(); } return null; }
public URI getUriToProblem(Annotation annotation) { if (annotation instanceof MarkerAnnotation) { MarkerAnnotation ma = (MarkerAnnotation) annotation; return getUriToProblem(ma.getMarker()); } if (annotation instanceof XtextAnnotation) { XtextAnnotation xa = (XtextAnnotation) annotation; return xa.getUriToProblem(); } return null; }
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(); }
private boolean isProblemMarkerAnnotation(final Annotation annotation) { if (!(annotation instanceof MarkerAnnotation)) return false; try { return (((MarkerAnnotation) annotation).getMarker().isSubtypeOf(IMarker.PROBLEM)); } catch (final CoreException e) { 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(); } }
@Override protected MarkerAnnotation createMarkerAnnotation(IMarker marker) { MarkerAnnotation annotation = super.createMarkerAnnotation(marker); String issueCode = issueUtil.getCode(annotation); annotation.setQuickFixable(issueResolutionProvider.hasResolutionFor(issueCode)); return annotation; }
@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 IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException { if (annot instanceof MarkerAnnotation) { if (sourceElement == null || isInside(model.getPosition(annot), sourceElement)) { IMarker marker= ((MarkerAnnotation) annot).getMarker(); if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) { return marker; } } } return null; }
/** * Tells whether the given annotation stands for a problem marker. * * @param annotation the annotation * @return <code>true</code> if it is a problem marker * @since 3.4 */ 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; } }
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 ICompletionProposal[] getCompletionProposals() { if (annotation instanceof IJavaAnnotation) { ICompletionProposal[] result= getJavaAnnotationFixes((IJavaAnnotation) annotation); if (result.length > 0) return result; } if (annotation instanceof MarkerAnnotation) return getMarkerAnnotationFixes((MarkerAnnotation) annotation); return NO_PROPOSALS; }
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<IJavaCompletionProposal>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
@Override public boolean canFix(Annotation annotation) { boolean result = false; String text = null; if (annotation instanceof TemporaryAnnotation) { TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) annotation; int problemID = tempAnnotation.getProblemID(); text = tempAnnotation.getText(); if (problemID == 0 && text != null) result = true; } else if (annotation instanceof MarkerAnnotation) { MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; text = markerAnnotation.getText(); IMarker marker = markerAnnotation.getMarker(); IResource resource = marker == null ? null : marker.getResource(); if (resource != null && resource.exists() && resource.isAccessible() && text != null) { result = true; } } result = result && isWebResourceError(text); return result; }
public void beforeChangeText() { for (Iterator e= getAnnotationIterator(true); e.hasNext();) { Object o= e.next(); if (o instanceof MarkerAnnotation) { MarkerAnnotation a= (MarkerAnnotation) o; //System.out.println(a.getType( )); IMarker mark = a.getMarker( ); try { if (mark == null || !getId( ).equals( mark.getAttribute( SUBNAME ) )) { continue; } if (!(ScriptDocumentProvider.MARK_TYPE.equals( a.getMarker( ).getType( )))) { continue; } } catch ( CoreException e1 ) { continue; } Position p= getPosition( a ); if (p != null && !p.isDeleted( )) { Position tempCopy = new Position(p.getOffset(),p.getLength()); markMap.put( a, tempCopy ); } } } change = true; }
protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged)throws BadLocationException { if (annotation instanceof MarkerAnnotation) { IMarker marker = ((MarkerAnnotation)annotation).getMarker( ); if (marker != null) { try { if (!getId( ).equals( marker.getAttribute( SUBNAME ) )) { return; } if (!(ScriptDocumentProvider.MARK_TYPE.equals( marker.getType( )))) { return; } } catch ( CoreException e ) { //do nothing now } } } super.addAnnotation( annotation, position, fireModelChanged ); }