org.eclipse.jface.text.source.IAnnotationModel Java Examples
The following examples show how to use
org.eclipse.jface.text.source.IAnnotationModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeScriptSourceViewer.java From typescript.java with MIT License | 6 votes |
@Override public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) { // partial fix for: // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=1970 // when our document is set, especially to null during close, // immediately uninstall the reconciler. // this is to avoid an unnecessary final "reconcile" // that blocks display thread if (document == null) { if (fReconciler != null) { fReconciler.uninstall(); } } super.setDocument(document, annotationModel, modelRangeOffset, modelRangeLength); }
Example #2
Source File: AbstractASTResolution.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
private MarkerAnnotation getMarkerAnnotation(IAnnotationModel annotationModel, IMarker marker) { Iterator<Annotation> it = annotationModel.getAnnotationIterator(); while (it.hasNext()) { Annotation tmp = it.next(); if (tmp instanceof MarkerAnnotation) { IMarker theMarker = ((MarkerAnnotation) tmp).getMarker(); if (theMarker.equals(marker)) { return (MarkerAnnotation) tmp; } } } return null; }
Example #3
Source File: WorkbenchMarkerResolutionGenerator.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
@Override @SuppressWarnings("PMD.UseVarargs") public IMarker[] findOtherMarkers(final IMarker[] markers) { final List<IMarker> result = Lists.newArrayList(); for (final IMarker marker : markers) { if (!resolutionMarker.equals(marker) && markerCode.equals(getIssueUtil().getCode(marker))) { XtextEditor editor = null; if (Display.getCurrent() != null) { editor = findEditor(marker.getResource()); } if (editor != null) { // if the resource is in an open editor compare the annotation with the marker final IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); if (annotationModel != null && isMarkerStillValid(marker, annotationModel)) { result.add(marker); } } else { result.add(marker); } } } return result.toArray(new IMarker[result.size()]); }
Example #4
Source File: N4JSMarkerResolutionGenerator.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Same as {@link #isMarkerStillValid(IMarker, IAnnotationModel)}, but obtains the annotation model from the * marker's editor. */ @SuppressWarnings("deprecation") private boolean isMarkerStillValid(IMarker marker) { if (marker == null) return false; if (marker.getResource() instanceof IProject) { // This happens with IssueCodes.NODE_MODULES_OUT_OF_SYNC return true; } final XtextEditor editor = getEditor(marker.getResource()); if (editor == null) return false; final IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel( editor.getEditorInput()); if (annotationModel == null) return false; return isMarkerStillValid(marker, annotationModel); }
Example #5
Source File: ContributionAnnotationManager.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Creates contribution annotations with length 1 for each char contained in the range defined by * {@code offset} and {@code length}. * * @param model the model that is assigned to the created contribution annotations. * @param offset start of the annotation range. * @param length length of the annotation range. * @param source of the annotation. * @return a map containing the annotations and their positions */ private Map<ContributionAnnotation, Position> createAnnotationsForContributionRange( final IAnnotationModel model, final int offset, final int length, final User source) { final Map<ContributionAnnotation, Position> annotationsToAdd = new HashMap<>(); for (int i = 0; i < length; i++) { final Pair<ContributionAnnotation, Position> positionedAnnotation = createPositionedAnnotation(model, offset + i, source); if (positionedAnnotation == null) continue; annotationsToAdd.put(positionedAnnotation.getKey(), positionedAnnotation.getValue()); } return annotationsToAdd; }
Example #6
Source File: ExternalBreakpointWatcher.java From goclipse with Eclipse Public License 1.0 | 6 votes |
public ExternalBreakpointWatcher(IEditorInput input, IDocument document, IAnnotationModel annotationModel) { this.location = EditorUtils.getLocationOrNull(input); this.document = assertNotNull(document); this.annotationModel = assertNotNull(annotationModel); if(annotationModel instanceof IAnnotationModelExtension) { this.annotationModelExt = (IAnnotationModelExtension) annotationModel; } else { this.annotationModelExt = null; } if(location != null) { ResourceUtils.connectResourceListener(resourceListener, this::initializeFromResources, getWorkspaceRoot(), owned); } }
Example #7
Source File: CommonOccurrencesUpdater.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * updateAnnotations * * @param selection */ protected void updateAnnotations(ISelection selection) { if (findOccurrencesJob != null) { findOccurrencesJob.cancel(); } if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; IDocument document = getDocument(); IAnnotationModel annotationModel = getAnnotationModel(); if (document != null && annotationModel != null) { findOccurrencesJob = new FindOccurrencesJob(document, textSelection, annotationModel); findOccurrencesJob.schedule(); } } }
Example #8
Source File: LocationAnnotationManager.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Sets annotations related to selections made by remote users. * * @param newAnnotation {@link SarosAnnotation} that is set during this call. * @param position {@link Position} at which the annotation is replaced, removed, or updated. * @param model {@link IAnnotationModel} that maintains the annotations for the opened document. */ private void setAnnotationForSelection( final SarosAnnotation newAnnotation, Position position, IAnnotationModel model) { if (newAnnotation == null || position == null) { throw new IllegalArgumentException("Both newAnnotation and position must not be null"); } Predicate<Annotation> predicate = new Predicate<Annotation>() { @Override public boolean evaluate(Annotation annotation) { return annotation.getType().equals(newAnnotation.getType()) && ((SarosAnnotation) annotation).getSource().equals(newAnnotation.getSource()); } }; Map<Annotation, Position> replacement = Collections.singletonMap((Annotation) newAnnotation, position); annotationModelHelper.replaceAnnotationsInModel(model, predicate, replacement); }
Example #9
Source File: ScriptValidator.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Clears all annotations. */ private void clearAnnotations( ) { IAnnotationModel annotationModel = scriptViewer.getAnnotationModel( ); if ( annotationModel != null ) { for ( Iterator iterator = annotationModel.getAnnotationIterator( ); iterator.hasNext( ); ) { Annotation annotation = (Annotation) iterator.next( ); if ( annotation != null && IReportGraphicConstants.ANNOTATION_ERROR.equals( annotation.getType( ) ) ) { annotationModel.removeAnnotation( annotation ); } } } }
Example #10
Source File: TextEditorExt.java From goclipse with Eclipse Public License 1.0 | 6 votes |
@Override protected void doSetInput(IEditorInput input) throws CoreException { super.doSetInput(input); owned.disposeOwned(breakpointWatcher); breakpointWatcher = null; if(input == null) { return; } IAnnotationModel annotationModel = getDocumentProvider().getAnnotationModel(input); IFile file = EditorUtils.getAssociatedFile(input); if(file != null || annotationModel == null) { return; // No need for external breakpoint watching } breakpointWatcher = new ExternalBreakpointWatcher(input, getDocument(), annotationModel); owned.bind(breakpointWatcher); }
Example #11
Source File: XtextEditor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") private Annotation getAnnotation(final int offset, final int length) { final IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput()); if (model == null || length < 0) return null; Iterator iterator; if (model instanceof IAnnotationModelExtension2) { iterator = ((IAnnotationModelExtension2) model).getAnnotationIterator(offset, length, true, true); } else { iterator = model.getAnnotationIterator(); } while (iterator.hasNext()) { final Annotation a = (Annotation) iterator.next(); final Position p = model.getPosition(a); if (p != null && p.overlapsWith(offset, length)) return a; } return null; }
Example #12
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the annotation overlapping with the given range or <code>null</code>. * * @param offset the region offset * @param length the region length * @return the found annotation or <code>null</code> * @since 3.0 */ private Annotation getAnnotation(int offset, int length) { IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); if (model == null) return null; Iterator<Annotation> parent; if (model instanceof IAnnotationModelExtension2) parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(offset, length, true, true); else parent= model.getAnnotationIterator(); Iterator<Annotation> e= new JavaAnnotationIterator(parent, false); while (e.hasNext()) { Annotation a= e.next(); Position p= model.getPosition(a); if (p != null && p.overlapsWith(offset, length)) return a; } return null; }
Example #13
Source File: ProblemsLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private int getErrorTicksFromAnnotationModel(IAnnotationModel model, ISourceReference sourceElement) throws CoreException { int info= 0; Iterator<Annotation> iter= model.getAnnotationIterator(); while ((info != ERRORTICK_ERROR) && iter.hasNext()) { Annotation annot= iter.next(); IMarker marker= isAnnotationInRange(model, annot, sourceElement); if (marker != null) { int priority= marker.getAttribute(IMarker.SEVERITY, -1); if (priority == IMarker.SEVERITY_WARNING) { info= ERRORTICK_WARNING; } else if (priority == IMarker.SEVERITY_ERROR) { info= ERRORTICK_ERROR; } } } return info; }
Example #14
Source File: AnnotationModelHelper.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Removes annotations and replaces them in one step. * * @param model The {@link IAnnotationModel} that should be cleaned. * @param annotationsToRemove The annotations to remove. * @param annotationsToAdd The annotations to add. */ public void replaceAnnotationsInModel( IAnnotationModel model, Collection<? extends Annotation> annotationsToRemove, Map<? extends Annotation, Position> annotationsToAdd) { if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension extension = (IAnnotationModelExtension) model; extension.replaceAnnotations( annotationsToRemove.toArray(new Annotation[annotationsToRemove.size()]), annotationsToAdd); } else { if (log.isTraceEnabled()) log.trace("AnnotationModel " + model + " does not support IAnnotationModelExtension"); for (Annotation annotation : annotationsToRemove) { model.removeAnnotation(annotation); } for (Entry<? extends Annotation, Position> entry : annotationsToAdd.entrySet()) { model.addAnnotation(entry.getKey(), entry.getValue()); } } }
Example #15
Source File: JsonQuickAssistProcessor.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 6 votes |
protected List<IMarker> getMarkersFor(ISourceViewer sourceViewer, int lineOffset, int lineLength) { List<IMarker> result = new ArrayList<>(); 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; }
Example #16
Source File: ClassFileDocumentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates an annotation model derived from the given class file editor input. * * @param classFileEditorInput the editor input from which to query the annotations * @return the created annotation model * @exception CoreException if the editor input could not be accessed */ protected IAnnotationModel createClassFileAnnotationModel(IClassFileEditorInput classFileEditorInput) throws CoreException { IResource resource= null; IClassFile classFile= classFileEditorInput.getClassFile(); IResourceLocator locator= (IResourceLocator) classFile.getAdapter(IResourceLocator.class); if (locator != null) resource= locator.getContainingResource(classFile); if (resource != null) { ClassFileMarkerAnnotationModel model= new ClassFileMarkerAnnotationModel(resource); model.setClassFile(classFile); return model; } return null; }
Example #17
Source File: CorrectionMarkerResolutionGenerator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static IProblemLocation findProblemLocation(IEditorInput input, IMarker marker) { IAnnotationModel model= JavaPlugin.getDefault().getCompilationUnitDocumentProvider().getAnnotationModel(input); if (model != null) { // open in editor Iterator<Annotation> iter= model.getAnnotationIterator(); while (iter.hasNext()) { Annotation curr= iter.next(); if (curr instanceof JavaMarkerAnnotation) { JavaMarkerAnnotation annot= (JavaMarkerAnnotation) curr; if (marker.equals(annot.getMarker())) { Position pos= model.getPosition(annot); if (pos != null) { return new ProblemLocation(pos.getOffset(), pos.getLength(), annot); } } } } } else { // not open in editor ICompilationUnit cu= getCompilationUnit(marker); return createFromMarker(marker, cu); } return null; }
Example #18
Source File: TypeScriptEditor.java From typescript.java with MIT License | 5 votes |
private IAnnotationModel getAnnotationModel() { IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) { return null; } return documentProvider.getAnnotationModel(getEditorInput()); }
Example #19
Source File: ContributionAnnotationHistoryTest.java From saros with GNU General Public License v2.0 | 5 votes |
@Test public void testAddEntriesUntilMaxLength() { Pair<IAnnotationModel, List<ContributionAnnotation>> annotationsToRemove; for (int i = 0; i < MAX_HISTORY_LENGTH; i++) { annotationsToRemove = history.addNewEntry(createDummyAnnotation(testModel)); assertNull(annotationsToRemove); } assertEquals(MAX_HISTORY_LENGTH, history.getSize()); }
Example #20
Source File: AnnotationModelHelper.java From saros with GNU General Public License v2.0 | 5 votes |
/** Removes annotations that match a given predicate. */ public void removeAnnotationsFromEditor(IEditorPart editor, Predicate<Annotation> predicate) { IAnnotationModel model = retrieveAnnotationModel(editor); if (model == null) { return; } removeAnnotationsFromModel(model, predicate); }
Example #21
Source File: ContributionAnnotationManager.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Refreshes all contribution annotations in the model by removing and reinserting them. * * @param model the annotation model that should be refreshed */ public void refreshAnnotations(final IAnnotationModel model) { final List<Annotation> annotationsToRemove = new ArrayList<Annotation>(); final Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>(); for (final Iterator<Annotation> it = model.getAnnotationIterator(); it.hasNext(); ) { final Annotation annotation = it.next(); if (!(annotation instanceof ContributionAnnotation)) continue; final Position position = model.getPosition(annotation); if (position == null) { log.warn("annotation could not be found in the current model: " + annotation); continue; } /* * we rely on the fact the a user object is unique during a running * session so that user.equals(user) <=> user == user otherwise just * reinserting the annotations would not refresh the colors as the * color id of the user has not changed */ annotationsToRemove.add(annotation); final ContributionAnnotation annotationToReplace = (ContributionAnnotation) annotation; final User source = annotationToReplace.getSource(); final ContributionAnnotation annotationToAdd = new ContributionAnnotation(source, model); annotationsToAdd.put(annotationToAdd, position); getHistory(source).replaceInHistory(annotationToReplace, annotationToAdd); } if (annotationsToRemove.isEmpty()) return; annotationModelHelper.replaceAnnotationsInModel(model, annotationsToRemove, annotationsToAdd); }
Example #22
Source File: OverrideIndicatorModelListener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private IStatus updateAnnotationModel(IProgressMonitor monitor) { if (xtextEditor == null || xtextEditor.getDocument() == null || xtextEditor.getInternalSourceViewer().getAnnotationModel() == null) { return Status.OK_STATUS; } IXtextDocument xtextDocument = xtextEditor.getDocument(); IAnnotationModel annotationModel = xtextEditor.getInternalSourceViewer().getAnnotationModel(); Map<Annotation, Position> annotationToPosition = xtextDocument .readOnly(new CancelableUnitOfWork<Map<Annotation, Position>, XtextResource>() { @Override public Map<Annotation, Position> exec(XtextResource xtextResource, CancelIndicator cancelIndicator) { if (xtextResource == null) return Collections.emptyMap(); return createOverrideIndicatorAnnotationMap(xtextResource, cancelIndicator); } }); if (monitor.isCanceled()) return Status.CANCEL_STATUS; if (annotationModel instanceof IAnnotationModelExtension) { IAnnotationModelExtension annotationModelExtension = (IAnnotationModelExtension) annotationModel; Object lockObject = getLockObject(annotationModel); synchronized (lockObject) { annotationModelExtension.replaceAnnotations( overrideIndicatorAnnotations.toArray(new Annotation[overrideIndicatorAnnotations.size()]), annotationToPosition); } overrideIndicatorAnnotations = annotationToPosition.keySet(); } return Status.OK_STATUS; }
Example #23
Source File: ContributionAnnotationHistory.java From saros with GNU General Public License v2.0 | 5 votes |
/** * @param annotations annotations to add as one entry into the history * @return If an entry has to be removed from the history in order to add the new one, the removed * entry is returned with the corresponding {@link IAnnotationModel}. Otherwise return <code> * null</code>. */ Pair<IAnnotationModel, List<ContributionAnnotation>> addNewEntry( final List<ContributionAnnotation> annotations) { Pair<IAnnotationModel, List<ContributionAnnotation>> removedEntry = removeEntryIfFull(); queue.add(annotations); return removedEntry; }
Example #24
Source File: TexlipseAnnotationUpdater.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Removes all existing annotations * @param model AnnotationModel */ private void removeOldAnnotations(IAnnotationModel model) { for (Iterator<Annotation> it= fOldAnnotations.iterator(); it.hasNext();) { Annotation annotation= (Annotation) it.next(); model.removeAnnotation(annotation); } fOldAnnotations.clear(); }
Example #25
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void installOverrideIndicator(boolean provideAST) { uninstallOverrideIndicator(); IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); final ITypeRoot inputElement= getInputJavaElement(); if (model == null || inputElement == null) return; fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null); if (provideAST) { CompilationUnit ast= SharedASTProvider.getAST(inputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, getProgressMonitor()); fOverrideIndicatorManager.reconciled(ast, true, getProgressMonitor()); } }
Example #26
Source File: TypeScriptEditor.java From typescript.java with MIT License | 5 votes |
/** * Returns the lock object for the given annotation model. * * @param annotationModel * the annotation model * @return the annotation model's lock object * */ private Object getLockObject(IAnnotationModel annotationModel) { if (annotationModel instanceof ISynchronizable) { Object lock = ((ISynchronizable) annotationModel).getLockObject(); if (lock != null) return lock; } return annotationModel; }
Example #27
Source File: TeXSpellingReconcileStrategy.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new spelling problem collector. * * @return the collector or <code>null</code> if none is available */ protected TeXSpellingProblemCollector createSpellingProblemCollector() { IAnnotationModel model= getAnnotationModel(); if (model == null) return null; return new TeXSpellingProblemCollector(model); }
Example #28
Source File: TeXSpellingReconcileStrategy.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Initializes this collector with the given annotation model. * * @param annotationModel the annotation model */ public TeXSpellingProblemCollector(IAnnotationModel annotationModel) { Assert.isLegal(annotationModel != null); fAnnotationModel= annotationModel; if (fAnnotationModel instanceof ISynchronizable) fLockObject= ((ISynchronizable)fAnnotationModel).getLockObject(); else fLockObject= fAnnotationModel; }
Example #29
Source File: ScriptDocumentProvider.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Update the script to refesh the break point. * @param annotationModel */ public void update(IAnnotationModel annotationModel) { if (!(annotationModel instanceof DebugResourceMarkerAnnotationModel)) { return ; } DebugResourceMarkerAnnotationModel debugAnno = (DebugResourceMarkerAnnotationModel)annotationModel; debugAnno.disconnected( ); debugAnno.connected( ); }
Example #30
Source File: ProblemsLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }