1 11 package org.eclipse.ui.texteditor; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.jface.text.source.Annotation; 18 19 import org.eclipse.ui.internal.editors.text.EditorsPlugin; 20 import org.eclipse.ui.internal.texteditor.*; 21 22 28 public class AnnotationPreferenceLookup { 29 30 31 private Map fFragments; 32 33 36 public AnnotationPreferenceLookup() { 37 } 38 39 45 public AnnotationPreference getAnnotationPreference(Annotation annotation) { 46 return getAnnotationPreference(annotation.getType()); 47 } 48 49 55 public AnnotationPreference getAnnotationPreference(String annotationType) { 56 if (annotationType == null || annotationType == Annotation.TYPE_UNKNOWN) 57 return null; 58 59 AnnotationTypeHierarchy hierarchy= getAnnotationTypeHierarchy(); 60 AnnotationType type= hierarchy.getAnnotationType(annotationType); 61 AnnotationPreference preference= type.getPreference(); 62 if (preference == null) { 63 preference= new DelegatingAnnotationPreference(type, this); 64 type.setAnnotationPreference(preference); 65 } 66 67 return preference; 68 } 69 70 79 public AnnotationPreference getAnnotationPreferenceFragment(String annotationType) { 80 Map fragments= getPreferenceFragments(); 81 return (AnnotationPreference) fragments.get(annotationType); 82 } 83 84 89 private AnnotationTypeHierarchy getAnnotationTypeHierarchy() { 90 return EditorsPlugin.getDefault().getAnnotationTypeHierarchy(); 91 } 92 93 99 private synchronized Map getPreferenceFragments() { 100 if (fFragments == null) { 101 fFragments= new HashMap (); 102 MarkerAnnotationPreferences p= new MarkerAnnotationPreferences(); 103 Iterator e= p.getAnnotationPreferenceFragments().iterator(); 104 while (e.hasNext()) { 105 AnnotationPreference fragment= (AnnotationPreference) e.next(); 106 Object annotationType = fragment.getAnnotationType(); 107 AnnotationPreference preference= (AnnotationPreference) fFragments.get(annotationType); 108 if (preference == null) 109 fFragments.put(annotationType, fragment); 110 else 111 preference.merge(fragment); 112 } 113 } 114 return fFragments; 115 } 116 } 117 | Popular Tags |