下面列出了org.eclipse.jface.text.source.IAnnotationModel#removeAnnotation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
}
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;
}
}
/**
* 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 );
}
}
}
}
/**
* 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());
}
}
}
/**
* 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();
}
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;
}
private void removeLightBulb(IAnnotationModel model) {
synchronized (this) {
if (fIsAnnotationShown) {
model.removeAnnotation(fAnnotation);
fIsAnnotationShown= false;
}
}
}
/**
* 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;
}
/**
* 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;
}
}
/**
* @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);
}
}