44
55package net .sourceforge .pmd .eclipse .plugin ;
66
7- import java .net .MalformedURLException ;
8- import java .net .URL ;
97import java .util .ArrayList ;
108import java .util .Arrays ;
119import java .util .Comparator ;
2321import org .eclipse .swt .widgets .Display ;
2422
2523import net .sourceforge .pmd .RulePriority ;
26- import net .sourceforge .pmd .eclipse .runtime .preferences .IPreferences ;
2724import net .sourceforge .pmd .eclipse .runtime .preferences .IPreferencesManager ;
2825import net .sourceforge .pmd .eclipse .ui .Shape ;
2926import net .sourceforge .pmd .eclipse .ui .ShapeDescriptor ;
@@ -45,32 +42,16 @@ private UISettings() {
4542
4643 private static String [] priorityLabels ;
4744
48- private static Map <Object , ShapeDescriptor > shapesByPriority ;
49- private static Map <Integer , RulePriority > prioritiesByIntValue ;
5045 private static Map <RulePriority , String > labelsByPriority = new HashMap <RulePriority , String >();
5146
5247 private static final int MAX_MARKER_DIMENSION = 9 ;
5348 private static IPreferencesManager preferencesManager = PMDPlugin .getDefault ().getPreferencesManager ();
54- private static final Map <RulePriority , PriorityDescriptor > UI_DESCRIPTORS_BY_PRIORITY = new HashMap <RulePriority , PriorityDescriptor >(
55- 5 );
5649
5750 public static final FontBuilder CODE_FONT_BUILDER = new FontBuilder ("Courier" , 11 , SWT .NORMAL );
5851
52+ @ Deprecated
5953 public static void reloadPriorities () {
60- UI_DESCRIPTORS_BY_PRIORITY .clear ();
61- uiDescriptorsByPriority (); // cause a reload
62- }
63-
64- private static Map <RulePriority , PriorityDescriptor > uiDescriptorsByPriority () {
65-
66- if (UI_DESCRIPTORS_BY_PRIORITY .isEmpty ()) {
67- IPreferences preferences = preferencesManager .loadPreferences ();
68- for (RulePriority rp : currentPriorities (true )) {
69- UI_DESCRIPTORS_BY_PRIORITY .put (rp , preferences .getPriorityDescriptor (rp ));
70- }
71- }
72-
73- return UI_DESCRIPTORS_BY_PRIORITY ;
54+ // no-op - nothing to be done anymore. The priority descriptor are cached by PriorityDescriptorCache and not here.
7455 }
7556
7657 public static Shape [] allShapes () {
@@ -103,34 +84,37 @@ public static Map<Shape, ShapeDescriptor> shapeSet(RGB color, int size) {
10384 return shapes ;
10485 }
10586
87+ /**
88+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
89+ */
90+ @ Deprecated
10691 public static String markerFilenameFor (RulePriority priority ) {
10792 String fileDir = PMDPlugin .getPluginFolder ().getAbsolutePath ();
10893 return fileDir + "/" + relativeMarkerFilenameFor (priority );
10994 }
11095
96+ /**
97+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
98+ */
99+ @ Deprecated
111100 public static String relativeMarkerFilenameFor (RulePriority priority ) {
112101 return "icons/markerP" + priority .getPriority () + ".png" ;
113102 }
114103
115- private static ImageDescriptor getImageDescriptor (final String fileName ) {
116-
117- URL installURL = PMDPlugin .getDefault ().getBundle ().getEntry ("/" );
118- try {
119- URL url = new URL (installURL , fileName );
120- return ImageDescriptor .createFromURL (url );
121- } catch (MalformedURLException mue ) {
122- mue .printStackTrace ();
123- return null ;
124- }
125- }
126-
104+ /**
105+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
106+ */
107+ @ Deprecated
127108 public static ImageDescriptor markerDescriptorFor (RulePriority priority ) {
128- String path = relativeMarkerFilenameFor (priority );
129- return getImageDescriptor ( path );
109+ PriorityDescriptor pd = PriorityDescriptorCache . INSTANCE . descriptorFor (priority );
110+ return pd . getAnnotationImageDescriptor ( );
130111 }
131112
113+ /**
114+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
115+ */
116+ @ Deprecated
132117 public static Map <Integer , ImageDescriptor > markerImgDescriptorsByPriority () {
133-
134118 RulePriority [] priorities = currentPriorities (true );
135119 Map <Integer , ImageDescriptor > overlaysByPriority = new HashMap <Integer , ImageDescriptor >(priorities .length );
136120 for (RulePriority priority : priorities ) {
@@ -139,19 +123,22 @@ public static Map<Integer, ImageDescriptor> markerImgDescriptorsByPriority() {
139123 return overlaysByPriority ;
140124 }
141125
126+ /**
127+ * Marker Icons are not stored to files anymore. They are generated on the fly and cached by {@link PriorityDescriptorCache}.
128+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
129+ */
130+ @ Deprecated
142131 public static void createRuleMarkerIcons (Display display ) {
143-
144132 ImageLoader loader = new ImageLoader ();
145133
146134 PriorityDescriptorCache pdc = PriorityDescriptorCache .INSTANCE ;
147135
148136 for (RulePriority priority : currentPriorities (true )) {
149- Image image = pdc .descriptorFor (priority ).getImage ( display , MAX_MARKER_DIMENSION );
137+ Image image = pdc .descriptorFor (priority ).getAnnotationImage ( );
150138 loader .data = new ImageData [] { image .getImageData () };
151139 String fullPath = markerFilenameFor (priority );
152140 PMDPlugin .getDefault ().logInformation ("Writing marker icon to: " + fullPath );
153141 loader .save (fullPath , SWT .IMAGE_PNG );
154-
155142 image .dispose ();
156143 }
157144 }
@@ -175,12 +162,20 @@ public static void useCustomPriorityLabels(boolean flag) {
175162 }
176163 }
177164
165+ /**
166+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor#description}.
167+ */
168+ @ Deprecated
178169 public static String descriptionFor (RulePriority priority ) {
179170 return descriptorFor (priority ).description ;
180171 }
181172
173+ /**
174+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
175+ */
176+ @ Deprecated
182177 public static PriorityDescriptor descriptorFor (RulePriority priority ) {
183- return uiDescriptorsByPriority (). get (priority );
178+ return PriorityDescriptorCache . INSTANCE . descriptorFor (priority );
184179 }
185180
186181 public static String labelFor (RulePriority priority ) {
@@ -191,36 +186,27 @@ public static String labelFor(RulePriority priority) {
191186 }
192187
193188 public static Map <Object , ShapeDescriptor > shapesByPriority () {
194-
195- if (shapesByPriority != null ) {
196- return shapesByPriority ;
197- }
198-
199- Map <Object , ShapeDescriptor > shapesByPriority = new HashMap <Object , ShapeDescriptor >(
200- uiDescriptorsByPriority ().size ());
201- for (Map .Entry <RulePriority , PriorityDescriptor > entry : uiDescriptorsByPriority ().entrySet ()) {
202- shapesByPriority .put (entry .getKey (), entry .getValue ().shape );
189+ Map <Object , ShapeDescriptor > shapesByPriority = new HashMap <Object , ShapeDescriptor >(RulePriority .values ().length );
190+ for (RulePriority priority : RulePriority .values ()) {
191+ shapesByPriority .put (priority , PriorityDescriptorCache .INSTANCE .descriptorFor (priority ).shape );
203192 }
204-
205193 return shapesByPriority ;
206194 }
207195
196+ /**
197+ * @deprecated Use {@link RulePriority#valueOf(int)} directly.
198+ */
199+ @ Deprecated
208200 public static RulePriority priorityFor (int value ) {
209-
210- if (prioritiesByIntValue == null ) {
211- prioritiesByIntValue = new HashMap <Integer , RulePriority >(uiDescriptorsByPriority ().size ());
212- for (Map .Entry <RulePriority , PriorityDescriptor > entry : uiDescriptorsByPriority ().entrySet ()) {
213- prioritiesByIntValue .put (entry .getKey ().getPriority (), entry .getKey ());
214- }
215- }
216- return prioritiesByIntValue .get (value );
201+ return RulePriority .valueOf (value );
217202 }
218203
219204 /**
220205 * Return the priority labels
221206 *
222207 * @deprecated - not referenced in the modern UI
223208 */
209+ @ Deprecated
224210 public static String [] getPriorityLabels () {
225211 if (priorityLabels == null ) {
226212 final StringTable stringTable = PMDPlugin .getDefault ().getStringTable ();
0 commit comments