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 ;
28- import net .sourceforge .pmd .eclipse .ui .PMDMarkerImageProvider ;
2925import net .sourceforge .pmd .eclipse .ui .Shape ;
3026import net .sourceforge .pmd .eclipse .ui .ShapeDescriptor ;
3127import net .sourceforge .pmd .eclipse .ui .nls .StringKeys ;
@@ -46,32 +42,16 @@ private UISettings() {
4642
4743 private static String [] priorityLabels ;
4844
49- private static Map <Object , ShapeDescriptor > shapesByPriority ;
50- private static Map <Integer , RulePriority > prioritiesByIntValue ;
5145 private static Map <RulePriority , String > labelsByPriority = new HashMap <RulePriority , String >();
5246
5347 private static final int MAX_MARKER_DIMENSION = 9 ;
5448 private static IPreferencesManager preferencesManager = PMDPlugin .getDefault ().getPreferencesManager ();
55- private static final Map <RulePriority , PriorityDescriptor > UI_DESCRIPTORS_BY_PRIORITY = new HashMap <RulePriority , PriorityDescriptor >(
56- 5 );
5749
5850 public static final FontBuilder CODE_FONT_BUILDER = new FontBuilder ("Courier" , 11 , SWT .NORMAL );
5951
52+ @ Deprecated
6053 public static void reloadPriorities () {
61- UI_DESCRIPTORS_BY_PRIORITY .clear ();
62- uiDescriptorsByPriority (); // cause a reload
63- }
64-
65- private static Map <RulePriority , PriorityDescriptor > uiDescriptorsByPriority () {
66-
67- if (UI_DESCRIPTORS_BY_PRIORITY .isEmpty ()) {
68- IPreferences preferences = preferencesManager .loadPreferences ();
69- for (RulePriority rp : currentPriorities (true )) {
70- UI_DESCRIPTORS_BY_PRIORITY .put (rp , preferences .getPriorityDescriptor (rp ));
71- }
72- }
73-
74- return UI_DESCRIPTORS_BY_PRIORITY ;
54+ // no-op - nothing to be done anymore. The priority descriptor are cached by PriorityDescriptorCache and not here.
7555 }
7656
7757 public static Shape [] allShapes () {
@@ -104,34 +84,37 @@ public static Map<Shape, ShapeDescriptor> shapeSet(RGB color, int size) {
10484 return shapes ;
10585 }
10686
87+ /**
88+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
89+ */
90+ @ Deprecated
10791 public static String markerFilenameFor (RulePriority priority ) {
10892 String fileDir = PMDPlugin .getPluginFolder ().getAbsolutePath ();
10993 return fileDir + "/" + relativeMarkerFilenameFor (priority );
11094 }
11195
96+ /**
97+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
98+ */
99+ @ Deprecated
112100 public static String relativeMarkerFilenameFor (RulePriority priority ) {
113101 return "icons/markerP" + priority .getPriority () + ".png" ;
114102 }
115103
116- private static ImageDescriptor getImageDescriptor (final String fileName ) {
117-
118- URL installURL = PMDPlugin .getDefault ().getBundle ().getEntry ("/" );
119- try {
120- URL url = new URL (installURL , fileName );
121- return ImageDescriptor .createFromURL (url );
122- } catch (MalformedURLException mue ) {
123- mue .printStackTrace ();
124- return null ;
125- }
126- }
127-
104+ /**
105+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
106+ */
107+ @ Deprecated
128108 public static ImageDescriptor markerDescriptorFor (RulePriority priority ) {
129- String path = relativeMarkerFilenameFor (priority );
130- return getImageDescriptor ( path );
109+ PriorityDescriptor pd = PriorityDescriptorCache . INSTANCE . descriptorFor (priority );
110+ return pd . getAnnotationImageDescriptor ( );
131111 }
132112
113+ /**
114+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
115+ */
116+ @ Deprecated
133117 public static Map <Integer , ImageDescriptor > markerImgDescriptorsByPriority () {
134-
135118 RulePriority [] priorities = currentPriorities (true );
136119 Map <Integer , ImageDescriptor > overlaysByPriority = new HashMap <Integer , ImageDescriptor >(priorities .length );
137120 for (RulePriority priority : priorities ) {
@@ -140,21 +123,24 @@ public static Map<Integer, ImageDescriptor> markerImgDescriptorsByPriority() {
140123 return overlaysByPriority ;
141124 }
142125
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
143131 public static void createRuleMarkerIcons (Display display ) {
144-
145132 ImageLoader loader = new ImageLoader ();
146133
147134 PriorityDescriptorCache pdc = PriorityDescriptorCache .INSTANCE ;
148135
149136 for (RulePriority priority : currentPriorities (true )) {
150- Image image = pdc .descriptorFor (priority ).getImage ( display , MAX_MARKER_DIMENSION );
137+ Image image = pdc .descriptorFor (priority ).getAnnotationImage ( );
151138 loader .data = new ImageData [] { image .getImageData () };
152139 String fullPath = markerFilenameFor (priority );
153140 PMDPlugin .getDefault ().logInformation ("Writing marker icon to: " + fullPath );
154141 loader .save (fullPath , SWT .IMAGE_PNG );
155142 image .dispose ();
156143 }
157- PMDMarkerImageProvider .removeCachedImages ();
158144 }
159145
160146 private static String pLabelFor (RulePriority priority , boolean useCustom ) {
@@ -176,12 +162,20 @@ public static void useCustomPriorityLabels(boolean flag) {
176162 }
177163 }
178164
165+ /**
166+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor#description}.
167+ */
168+ @ Deprecated
179169 public static String descriptionFor (RulePriority priority ) {
180170 return descriptorFor (priority ).description ;
181171 }
182172
173+ /**
174+ * @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
175+ */
176+ @ Deprecated
183177 public static PriorityDescriptor descriptorFor (RulePriority priority ) {
184- return uiDescriptorsByPriority (). get (priority );
178+ return PriorityDescriptorCache . INSTANCE . descriptorFor (priority );
185179 }
186180
187181 public static String labelFor (RulePriority priority ) {
@@ -192,36 +186,27 @@ public static String labelFor(RulePriority priority) {
192186 }
193187
194188 public static Map <Object , ShapeDescriptor > shapesByPriority () {
195-
196- if (shapesByPriority != null ) {
197- return shapesByPriority ;
198- }
199-
200- Map <Object , ShapeDescriptor > shapesByPriority = new HashMap <Object , ShapeDescriptor >(
201- uiDescriptorsByPriority ().size ());
202- for (Map .Entry <RulePriority , PriorityDescriptor > entry : uiDescriptorsByPriority ().entrySet ()) {
203- 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 );
204192 }
205-
206193 return shapesByPriority ;
207194 }
208195
196+ /**
197+ * @deprecated Use {@link RulePriority#valueOf(int)} directly.
198+ */
199+ @ Deprecated
209200 public static RulePriority priorityFor (int value ) {
210-
211- if (prioritiesByIntValue == null ) {
212- prioritiesByIntValue = new HashMap <Integer , RulePriority >(uiDescriptorsByPriority ().size ());
213- for (Map .Entry <RulePriority , PriorityDescriptor > entry : uiDescriptorsByPriority ().entrySet ()) {
214- prioritiesByIntValue .put (entry .getKey ().getPriority (), entry .getKey ());
215- }
216- }
217- return prioritiesByIntValue .get (value );
201+ return RulePriority .valueOf (value );
218202 }
219203
220204 /**
221205 * Return the priority labels
222206 *
223207 * @deprecated - not referenced in the modern UI
224208 */
209+ @ Deprecated
225210 public static String [] getPriorityLabels () {
226211 if (priorityLabels == null ) {
227212 final StringTable stringTable = PMDPlugin .getDefault ().getStringTable ();
0 commit comments