1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 19 import org.eclipse.jface.text.Position; 20 import org.eclipse.jface.text.source.Annotation; 21 import org.eclipse.jface.text.source.AnnotationModelEvent; 22 import org.eclipse.jface.text.source.IAnnotationModel; 23 24 import org.eclipse.ui.texteditor.MarkerAnnotation; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 28 31 public class CompilationUnitAnnotationModelEvent extends AnnotationModelEvent { 32 33 private boolean fIncludesProblemMarkerAnnotations; 34 private IResource fUnderlyingResource; 35 36 41 public CompilationUnitAnnotationModelEvent(IAnnotationModel model, IResource underlyingResource) { 42 super(model); 43 fUnderlyingResource= underlyingResource; 44 fIncludesProblemMarkerAnnotations= false; 45 } 46 47 private void testIfProblemMarker(Annotation annotation) { 48 if (fIncludesProblemMarkerAnnotations) { 49 return; 50 } 51 if (annotation instanceof JavaMarkerAnnotation) { 52 fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem(); 53 } else if (annotation instanceof MarkerAnnotation) { 54 try { 55 IMarker marker= ((MarkerAnnotation) annotation).getMarker(); 56 if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) { 57 fIncludesProblemMarkerAnnotations= true; 58 } 59 } catch (CoreException e) { 60 JavaPlugin.log(e); 61 } 62 } 63 } 64 65 68 public void annotationAdded(Annotation annotation) { 69 super.annotationAdded(annotation); 70 testIfProblemMarker(annotation); 71 } 72 73 74 77 public void annotationRemoved(Annotation annotation) { 78 super.annotationRemoved(annotation); 79 testIfProblemMarker(annotation); 80 } 81 82 85 public void annotationRemoved(Annotation annotation, Position position) { 86 super.annotationRemoved(annotation, position); 87 testIfProblemMarker(annotation); 88 } 89 90 93 public void annotationChanged(Annotation annotation) { 94 testIfProblemMarker(annotation); 95 super.annotationChanged(annotation); 96 } 97 98 103 public boolean includesProblemMarkerAnnotationChanges() { 104 return fIncludesProblemMarkerAnnotations; 105 } 106 107 110 public IResource getUnderlyingResource() { 111 return fUnderlyingResource; 112 } 113 114 } 115 | Popular Tags |