Skip to content

Commit 629ee5b

Browse files
committed
Add annotation types for each PMD priority. These annotations
now appear by default on the overview ruler. Add a image provider, which can be used to provide different images
1 parent f5d6e96 commit 629ee5b

File tree

5 files changed

+215
-32
lines changed

5 files changed

+215
-32
lines changed

net.sourceforge.pmd.eclipse.plugin/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Require-Bundle: org.apache.commons.logging;bundle-version="1.0.4",
1616
org.eclipse.search,
1717
org.eclipse.help,
1818
org.eclipse.help.ui,
19-
org.eclipse.wst.xml.core
19+
org.eclipse.wst.xml.core,
20+
org.eclipse.ui.workbench.texteditor
2021
Bundle-ActivationPolicy: lazy
2122
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
2223
Bundle-Vendor: %plugin.provider

net.sourceforge.pmd.eclipse.plugin/plugin.xml

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
name="%marker.pmd"
1818
point="org.eclipse.core.resources.markers">
1919
<super type="org.eclipse.core.resources.textmarker"></super>
20-
<super type="org.eclipse.core.resources.problemmarker"></super>
2120
<persistent value="true"></persistent>
2221
<attribute name="rulename"></attribute>
2322
</extension>
@@ -26,6 +25,7 @@
2625
id="pmdMarker1"
2726
name="%marker.pmd.prio1"
2827
point="org.eclipse.core.resources.markers">
28+
<super type="org.eclipse.core.resources.problemmarker"></super>
2929
<super type="net.sourceforge.pmd.eclipse.plugin.pmdMarker"></super>
3030
<persistent value="true"></persistent>
3131
</extension>
@@ -34,6 +34,7 @@
3434
id="pmdMarker2"
3535
name="%marker.pmd.prio2"
3636
point="org.eclipse.core.resources.markers">
37+
<super type="org.eclipse.core.resources.problemmarker"></super>
3738
<super type="net.sourceforge.pmd.eclipse.plugin.pmdMarker"></super>
3839
<persistent value="true"></persistent>
3940
</extension>
@@ -42,6 +43,7 @@
4243
id="pmdMarker3"
4344
name="%marker.pmd.prio3"
4445
point="org.eclipse.core.resources.markers">
46+
<super type="org.eclipse.core.resources.problemmarker"></super>
4547
<super type="net.sourceforge.pmd.eclipse.plugin.pmdMarker"></super>
4648
<persistent value="true"></persistent>
4749
</extension>
@@ -50,6 +52,7 @@
5052
id="pmdMarker4"
5153
name="%marker.pmd.prio4"
5254
point="org.eclipse.core.resources.markers">
55+
<super type="org.eclipse.core.resources.problemmarker"></super>
5356
<super type="net.sourceforge.pmd.eclipse.plugin.pmdMarker"></super>
5457
<persistent value="true"></persistent>
5558
</extension>
@@ -58,6 +61,7 @@
5861
id="pmdMarker5"
5962
name="%marker.pmd.prio5"
6063
point="org.eclipse.core.resources.markers">
64+
<super type="org.eclipse.core.resources.problemmarker"></super>
6165
<super type="net.sourceforge.pmd.eclipse.plugin.pmdMarker"></super>
6266
<persistent value="true"></persistent>
6367
</extension>
@@ -75,6 +79,159 @@
7579
</markerTypeCategory>
7680
</extension>
7781

82+
<extension
83+
point="org.eclipse.ui.editors.annotationTypes">
84+
<type
85+
name="net.sourceforge.pmd.eclipse.plugin.annotation.prio1"
86+
markerType="net.sourceforge.pmd.eclipse.plugin.pmdMarker1"/>
87+
<type
88+
name="net.sourceforge.pmd.eclipse.plugin.annotation.prio2"
89+
markerType="net.sourceforge.pmd.eclipse.plugin.pmdMarker2"/>
90+
<type
91+
name="net.sourceforge.pmd.eclipse.plugin.annotation.prio3"
92+
markerType="net.sourceforge.pmd.eclipse.plugin.pmdMarker3"/>
93+
<type
94+
name="net.sourceforge.pmd.eclipse.plugin.annotation.prio4"
95+
markerType="net.sourceforge.pmd.eclipse.plugin.pmdMarker4"/>
96+
<type
97+
name="net.sourceforge.pmd.eclipse.plugin.annotation.prio5"
98+
markerType="net.sourceforge.pmd.eclipse.plugin.pmdMarker5"/>
99+
</extension>
100+
101+
<extension
102+
point="org.eclipse.ui.editors.markerAnnotationSpecification">
103+
<specification
104+
annotationType="net.sourceforge.pmd.eclipse.plugin.annotation.prio1"
105+
colorPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.color"
106+
overviewRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.overviewruler"
107+
verticalRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.verticalruler"
108+
textPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.text"
109+
label="PMD Violation Prio 1"
110+
highlightPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.highlight"
111+
colorPreferenceValue="255,0,0"
112+
presentationLayer="5"
113+
overviewRulerPreferenceValue="true"
114+
verticalRulerPreferenceValue="true"
115+
textPreferenceValue="false"
116+
highlightPreferenceValue="true"
117+
contributesToHeader="true"
118+
showInNextPrevDropdownToolbarActionKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.dropdown"
119+
showInNextPrevDropdownToolbarAction="true"
120+
isGoToNextNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.next"
121+
isGoToNextNavigationTarget="true"
122+
isGoToPreviousNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.previous"
123+
isGoToPreviousNavigationTarget="true"
124+
icon="icons/markerP1.png"
125+
annotationImageProvider="net.sourceforge.pmd.eclipse.ui.PMDMarkerImageProvider"
126+
textStylePreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio1.text.style"
127+
textStylePreferenceValue="BOX"
128+
includeOnPreferencePage="true" />
129+
<specification
130+
annotationType="net.sourceforge.pmd.eclipse.plugin.annotation.prio2"
131+
colorPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.color"
132+
overviewRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.overviewruler"
133+
verticalRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.verticalruler"
134+
textPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.text"
135+
label="PMD Violation Prio 2"
136+
highlightPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.highlight"
137+
colorPreferenceValue="0,255,255"
138+
presentationLayer="5"
139+
overviewRulerPreferenceValue="true"
140+
verticalRulerPreferenceValue="true"
141+
textPreferenceValue="false"
142+
highlightPreferenceValue="true"
143+
contributesToHeader="true"
144+
showInNextPrevDropdownToolbarActionKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.dropdown"
145+
showInNextPrevDropdownToolbarAction="true"
146+
isGoToNextNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.next"
147+
isGoToNextNavigationTarget="true"
148+
isGoToPreviousNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.previous"
149+
isGoToPreviousNavigationTarget="true"
150+
icon="icons/markerP2.png"
151+
annotationImageProvider="net.sourceforge.pmd.eclipse.ui.PMDMarkerImageProvider"
152+
textStylePreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio2.text.style"
153+
textStylePreferenceValue="BOX"
154+
includeOnPreferencePage="true" />
155+
<specification
156+
annotationType="net.sourceforge.pmd.eclipse.plugin.annotation.prio3"
157+
colorPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.color"
158+
overviewRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.overviewruler"
159+
verticalRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.verticalruler"
160+
textPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.text"
161+
label="PMD Violation Prio 3"
162+
highlightPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.highlight"
163+
colorPreferenceValue="0,255,0"
164+
presentationLayer="4"
165+
overviewRulerPreferenceValue="true"
166+
verticalRulerPreferenceValue="true"
167+
textPreferenceValue="false"
168+
highlightPreferenceValue="true"
169+
contributesToHeader="true"
170+
showInNextPrevDropdownToolbarActionKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.dropdown"
171+
showInNextPrevDropdownToolbarAction="true"
172+
isGoToNextNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.next"
173+
isGoToNextNavigationTarget="true"
174+
isGoToPreviousNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.previous"
175+
isGoToPreviousNavigationTarget="true"
176+
icon="icons/markerP3.png"
177+
annotationImageProvider="net.sourceforge.pmd.eclipse.ui.PMDMarkerImageProvider"
178+
textStylePreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio3.text.style"
179+
textStylePreferenceValue="BOX"
180+
includeOnPreferencePage="true" />
181+
<specification
182+
annotationType="net.sourceforge.pmd.eclipse.plugin.annotation.prio4"
183+
colorPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.color"
184+
overviewRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.overviewruler"
185+
verticalRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.verticalruler"
186+
textPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.text"
187+
label="PMD Violation Prio 4"
188+
highlightPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.highlight"
189+
colorPreferenceValue="255,0,255"
190+
presentationLayer="4"
191+
overviewRulerPreferenceValue="true"
192+
verticalRulerPreferenceValue="true"
193+
textPreferenceValue="false"
194+
highlightPreferenceValue="true"
195+
contributesToHeader="true"
196+
showInNextPrevDropdownToolbarActionKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.dropdown"
197+
showInNextPrevDropdownToolbarAction="true"
198+
isGoToNextNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.next"
199+
isGoToNextNavigationTarget="true"
200+
isGoToPreviousNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.previous"
201+
isGoToPreviousNavigationTarget="true"
202+
icon="icons/markerP4.png"
203+
annotationImageProvider="net.sourceforge.pmd.eclipse.ui.PMDMarkerImageProvider"
204+
textStylePreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio4.text.style"
205+
textStylePreferenceValue="BOX"
206+
includeOnPreferencePage="true" />
207+
<specification
208+
annotationType="net.sourceforge.pmd.eclipse.plugin.annotation.prio5"
209+
colorPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.color"
210+
overviewRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.overviewruler"
211+
verticalRulerPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.verticalruler"
212+
textPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.text"
213+
label="PMD Violation Prio 5"
214+
highlightPreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.highlight"
215+
colorPreferenceValue="0,0,255"
216+
presentationLayer="3"
217+
overviewRulerPreferenceValue="true"
218+
verticalRulerPreferenceValue="true"
219+
textPreferenceValue="false"
220+
highlightPreferenceValue="true"
221+
contributesToHeader="true"
222+
showInNextPrevDropdownToolbarActionKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.dropdown"
223+
showInNextPrevDropdownToolbarAction="true"
224+
isGoToNextNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.next"
225+
isGoToNextNavigationTarget="true"
226+
isGoToPreviousNavigationTargetKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.previous"
227+
isGoToPreviousNavigationTarget="true"
228+
icon="icons/markerP5.png"
229+
annotationImageProvider="net.sourceforge.pmd.eclipse.ui.PMDMarkerImageProvider"
230+
textStylePreferenceKey="net.sourceforge.pmd.eclipse.plugin.annotation.prio5.text.style"
231+
textStylePreferenceValue="BOX"
232+
includeOnPreferencePage="true" />
233+
</extension>
234+
78235
<extension point="org.eclipse.ui.ide.markerImageProviders">
79236
<imageprovider
80237
id="PMD.imageProvider1"

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public static PMDPlugin getDefault() {
388388
* @return the image descriptor
389389
*/
390390
public static ImageDescriptor getImageDescriptor(String path) {
391-
return AbstractUIPlugin.imageDescriptorFromPlugin("net.sourceforge.pmd.eclipse.plugin", path);
391+
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
392392
}
393393

394394
/**

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -482,19 +482,16 @@ private int maxAllowableViolationsFor(Rule rule) {
482482
}
483483

484484
public static String markerTypeFor(RuleViolation violation) {
485-
486-
int priorityId = violation.getRule().getPriority().getPriority();
487-
488-
switch (priorityId) {
489-
case 1:
485+
switch (violation.getRule().getPriority()) {
486+
case HIGH:
490487
return PMDRuntimeConstants.PMD_MARKER_1;
491-
case 2:
488+
case MEDIUM_HIGH:
492489
return PMDRuntimeConstants.PMD_MARKER_2;
493-
case 3:
490+
case MEDIUM:
494491
return PMDRuntimeConstants.PMD_MARKER_3;
495-
case 4:
492+
case MEDIUM_LOW:
496493
return PMDRuntimeConstants.PMD_MARKER_4;
497-
case 5:
494+
case LOW:
498495
return PMDRuntimeConstants.PMD_MARKER_5;
499496
default:
500497
return PMDRuntimeConstants.PMD_MARKER;
@@ -647,35 +644,23 @@ private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type) throws P
647644
info.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2, violation.getEndLine());
648645
info.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME, rule.getName());
649646
info.add(PMDRuntimeConstants.KEY_MARKERATT_PRIORITY, rule.getPriority().getPriority());
647+
info.add(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
650648

651-
switch (rule.getPriority().getPriority()) {
652-
case 1:
653-
info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
649+
switch (rule.getPriority()) {
650+
case HIGH:
651+
case MEDIUM_HIGH:
654652
info.add(IMarker.SEVERITY,
655653
projectProperties.violationsAsErrors() ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING);
656654
break;
657-
case 2:
658-
if (projectProperties.violationsAsErrors()) {
659-
info.add(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
660-
} else {
661-
info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
662-
info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
663-
}
664-
break;
665655

666-
case 5:
667-
info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
668-
break;
669-
670-
case 3:
671-
info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
656+
case MEDIUM:
657+
case MEDIUM_LOW:
672658
info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
673659
break;
674660

675-
case 4:
661+
case LOW:
676662
default:
677-
info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
678-
info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
663+
info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
679664
break;
680665
}
681666

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package net.sourceforge.pmd.eclipse.ui;
3+
4+
import org.eclipse.jface.resource.ImageDescriptor;
5+
import org.eclipse.jface.text.source.Annotation;
6+
import org.eclipse.swt.graphics.Image;
7+
import org.eclipse.ui.texteditor.IAnnotationImageProvider;
8+
9+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
10+
11+
public class PMDMarkerImageProvider implements IAnnotationImageProvider {
12+
13+
@Override
14+
public ImageDescriptor getImageDescriptor(String imageDescriptorId) {
15+
return null;
16+
}
17+
18+
@Override
19+
public String getImageDescriptorId(Annotation annotation) {
20+
return null;
21+
}
22+
23+
@Override
24+
public Image getManagedImage(Annotation annotation) {
25+
PMDPlugin plugin = PMDPlugin.getDefault();
26+
String type = annotation.getType();
27+
if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio1".equals(type)) {
28+
return plugin.getImage(type, "icons/markerP1.png");
29+
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio2".equals(type)) {
30+
return plugin.getImage(type, "icons/markerP2.png");
31+
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio3".equals(type)) {
32+
return plugin.getImage(type, "icons/markerP3.png");
33+
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio4".equals(type)) {
34+
return plugin.getImage(type, "icons/markerP4.png");
35+
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio5".equals(type)) {
36+
return plugin.getImage(type, "icons/markerP5.png");
37+
}
38+
return null;
39+
}
40+
}

0 commit comments

Comments
 (0)