Bug 474115 - Collect annotations in reverse map only for markers and problems

Change-Id: I439bed714aacd2cf43c8e3f42289ecdaa646bc19
Signed-off-by: Dawid Pakuła <zulus@w3des.net>
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java
index 982deb3..3ee2642 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/editor/SourceModuleDocumentProvider.java
@@ -826,19 +826,21 @@
 				throws BadLocationException {
 			super.addAnnotation(annotation, position, fireModelChanged);
 
-			synchronized (getLockObject()) {
-				Object cached = fReverseMap.get(position);
-				if (cached == null)
-					fReverseMap.put(position, annotation);
-				else if (cached instanceof List<?>) {
-					@SuppressWarnings("unchecked")
-					List<Annotation> list = (List<Annotation>) cached;
-					list.add(annotation);
-				} else if (cached instanceof Annotation) {
-					List<Annotation> list = new ArrayList<>(2);
-					list.add((Annotation) cached);
-					list.add(annotation);
-					fReverseMap.put(position, list);
+			if (annotation instanceof ProblemAnnotation || annotation instanceof MarkerAnnotation) {
+				synchronized (getLockObject()) {
+					Object cached = fReverseMap.get(position);
+					if (cached == null)
+						fReverseMap.put(position, annotation);
+					else if (cached instanceof List<?>) {
+						@SuppressWarnings("unchecked")
+						List<Annotation> list = (List<Annotation>) cached;
+						list.add(annotation);
+					} else if (cached instanceof Annotation) {
+						List<Annotation> list = new ArrayList<>(2);
+						list.add((Annotation) cached);
+						list.add(annotation);
+						fReverseMap.put(position, list);
+					}
 				}
 			}
 		}
@@ -856,18 +858,20 @@
 
 		@Override
 		protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
-			Position position = getPosition(annotation);
-			synchronized (getLockObject()) {
-				Object cached = fReverseMap.get(position);
-				if (cached instanceof List<?>) {
-					List<?> list = (List<?>) cached;
-					list.remove(annotation);
-					if (list.size() == 1) {
-						fReverseMap.put(position, list.get(0));
-						list.clear();
+			if (annotation instanceof ProblemAnnotation || annotation instanceof MarkerAnnotation) {
+				Position position = getPosition(annotation);
+				synchronized (getLockObject()) {
+					Object cached = fReverseMap.get(position);
+					if (cached instanceof List<?>) {
+						List<?> list = (List<?>) cached;
+						list.remove(annotation);
+						if (list.size() == 1) {
+							fReverseMap.put(position, list.get(0));
+							list.clear();
+						}
+					} else if (cached instanceof Annotation) {
+						fReverseMap.remove(position);
 					}
-				} else if (cached instanceof Annotation) {
-					fReverseMap.remove(position);
 				}
 			}
 			super.removeAnnotation(annotation, fireModelChanged);