Java Code Examples for org.eclipse.jface.text.source.IAnnotationModel#removeAnnotation()

The following examples show how to use org.eclipse.jface.text.source.IAnnotationModel#removeAnnotation() . 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: TypeScriptEditor.java    From typescript.java with MIT License 6 votes vote down vote up
private void removeOccurrenceAnnotations() {
	// fMarkOccurrenceModificationStamp=
	// IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
	// fMarkOccurrenceTargetRegion= null;

	IDocumentProvider documentProvider = getDocumentProvider();
	if (documentProvider == null)
		return;

	IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
	if (annotationModel == null || fOccurrenceAnnotations == null)
		return;

	synchronized (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;
	}
}
 
Example 2
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
void removeOccurrenceAnnotations() {
	fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
	fMarkOccurrenceTargetRegion= null;

	IDocumentProvider documentProvider= getDocumentProvider();
	if (documentProvider == null)
		return;

	IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
	if (annotationModel == null || fOccurrenceAnnotations == null)
		return;

	synchronized (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;
	}
}
 
Example 3
Source File: ScriptValidator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 4
Source File: AnnotationModelHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 5
Source File: TexlipseAnnotationUpdater.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 6
Source File: QuickAssistLightBulbUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) {
	boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context);
	if (fIsAnnotationShown) {
		model.removeAnnotation(fAnnotation);
	}
	if (needsAnnotation) {
		model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength()));
	}
	fIsAnnotationShown= needsAnnotation;
}
 
Example 7
Source File: QuickAssistLightBulbUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void removeLightBulb(IAnnotationModel model) {
	synchronized (this) {
		if (fIsAnnotationShown) {
			model.removeAnnotation(fAnnotation);
			fIsAnnotationShown= false;
		}
	}
}
 
Example 8
Source File: XMLEditor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Given the offset, tries to determine if we're on an HTML close/start tag, and if so it will find the matching
 * open/close and highlight the pair.
 * 
 * @param offset
 */
private void highlightTagPair(int offset)
{
	IDocumentProvider documentProvider = getDocumentProvider();
	if (documentProvider == null)
	{
		return;
	}
	IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
	if (annotationModel == null)
	{
		return;
	}

	if (fTagPairOccurrences != null)
	{
		// if the offset is included by one of these two positions, we don't need to wipe and re-calculate!
		for (Position pos : fTagPairOccurrences.values())
		{
			if (pos.includes(offset))
			{
				return;
			}
		}
		// New position, wipe the existing annotations in preparation for re-calculating...
		for (Annotation a : fTagPairOccurrences.keySet())
		{
			annotationModel.removeAnnotation(a);
		}
		fTagPairOccurrences = null;
	}

	// Calculate current pair
	Map<Annotation, Position> occurrences = new HashMap<Annotation, Position>();
	IDocument document = getSourceViewer().getDocument();

	IParseNode node = getASTNodeAt(offset, getAST());
	if (node instanceof XMLElementNode)
	{
		XMLElementNode en = (XMLElementNode) node;
		if (!en.isSelfClosing())
		{
			IRegion match = TagUtil.findMatchingTag(document, offset, tagPartitions);
			if (match != null)
			{
				// TODO Compare versus last positions, if they're the same don't wipe out the old ones and add new
				// ones!
				occurrences.put(new Annotation(IXMLEditorConstants.TAG_PAIR_OCCURRENCE_ID, false, null),
						new Position(match.getOffset(), match.getLength()));

				try
				{
					// The current tag we're in!
					ITypedRegion partition = document.getPartition(offset);
					occurrences.put(new Annotation(IXMLEditorConstants.TAG_PAIR_OCCURRENCE_ID, false, null),
							new Position(partition.getOffset(), partition.getLength()));
				}
				catch (BadLocationException e)
				{
					IdeLog.logError(XMLPlugin.getDefault(), e);
				}
				for (Map.Entry<Annotation, Position> entry : occurrences.entrySet())
				{
					annotationModel.addAnnotation(entry.getKey(), entry.getValue());
				}
				fTagPairOccurrences = occurrences;
				return;
			}
		}
	}
	// no new pair, so don't highlight anything
	fTagPairOccurrences = null;
}
 
Example 9
Source File: HTMLEditor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Given the offset, tries to determine if we're on an HTML close/start tag, and if so it will find the matching
 * open/close and highlight the pair.
 * 
 * @param offset
 */
private void highlightTagPair(int offset)
{
	IDocumentProvider documentProvider = getDocumentProvider();
	if (documentProvider == null)
	{
		return;
	}
	IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
	if (annotationModel == null)
	{
		return;
	}

	if (fTagPairOccurrences != null)
	{
		// if the offset is included by one of these two positions, we don't need to wipe and re-calculate!
		for (Position pos : fTagPairOccurrences.values())
		{
			if (pos.includes(offset))
			{
				return;
			}
		}
		// New position, wipe the existing annotations in preparation for re-calculating...
		for (Annotation a : fTagPairOccurrences.keySet())
		{
			annotationModel.removeAnnotation(a);
		}
		fTagPairOccurrences = null;
	}

	// Calculate current pair
	Map<Annotation, Position> occurrences = new HashMap<Annotation, Position>();
	IDocument document = getSourceViewer().getDocument();
	IRegion match = TagUtil.findMatchingTag(document, offset, tagPartitions);
	if (match != null)
	{
		// TODO Compare versus last positions, if they're the same don't wipe out the old ones and add new ones!
		occurrences.put(new Annotation(IHTMLConstants.TAG_PAIR_OCCURRENCE_ID, false, null),
				new Position(match.getOffset(), match.getLength()));

		try
		{
			// The current tag we're in!
			ITypedRegion partition = document.getPartition(offset);
			occurrences.put(new Annotation(IHTMLConstants.TAG_PAIR_OCCURRENCE_ID, false, null), new Position(
					partition.getOffset(), partition.getLength()));
		}
		catch (BadLocationException e)
		{
			IdeLog.logError(HTMLPlugin.getDefault(), e);
		}
		for (Map.Entry<Annotation, Position> entry : occurrences.entrySet())
		{
			annotationModel.addAnnotation(entry.getKey(), entry.getValue());
		}
		fTagPairOccurrences = occurrences;
	}
	else
	{
		// no new pair, so don't highlight anything
		fTagPairOccurrences = null;
	}
}
 
Example 10
Source File: BaseMarkOccurrencesJob.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param annotationModel
 */
protected synchronized void removeOccurenceAnnotations(IAnnotationModel annotationModel, BaseEditor pyEdit) {
    //remove the annotations
    Map<String, Object> cache = pyEdit.cache;
    if (cache == null) {
        return;
    }

    //let other threads execute before getting the lock on the annotation model
    Thread.yield();

    Thread thread = Thread.currentThread();
    int initiaThreadlPriority = thread.getPriority();
    //before getting the lock, let's execute with normal priority, to optimize the time that we'll 
    //retain that object locked (the annotation model is used on lots of places, so, retaining the lock
    //on it on a minimum priority thread is not a good thing.
    thread.setPriority(Thread.NORM_PRIORITY);

    try {
        synchronized (getLockObject(annotationModel)) {
            List<Annotation> annotationsToRemove = getOccurrenceAnnotationsInEditor(pyEdit);

            if (annotationModel instanceof IAnnotationModelExtension) {
                //replace those 
                ((IAnnotationModelExtension) annotationModel).replaceAnnotations(
                        annotationsToRemove.toArray(new Annotation[annotationsToRemove.size()]),
                        new HashMap<Annotation, Position>());
            } else {
                Iterator<Annotation> annotationIterator = annotationsToRemove.iterator();

                while (annotationIterator.hasNext()) {
                    annotationModel.removeAnnotation(annotationIterator.next());
                }
            }
            cache.put(getOccurrenceAnnotationsCacheKey(), null);
        }
        //end remove the annotations
    } finally {
        thread.setPriority(initiaThreadlPriority);
    }
}