1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd.jsp.rules; |
5 |
| |
6 |
| import net.sourceforge.pmd.PropertyDescriptor; |
7 |
| import net.sourceforge.pmd.Rule; |
8 |
| import net.sourceforge.pmd.RuleContext; |
9 |
| import net.sourceforge.pmd.RuleViolation; |
10 |
| import net.sourceforge.pmd.ast.Node; |
11 |
| import net.sourceforge.pmd.jsp.ast.JspParserVisitorAdapter; |
12 |
| import net.sourceforge.pmd.jsp.ast.SimpleNode; |
13 |
| |
14 |
| import java.text.MessageFormat; |
15 |
| import java.util.Iterator; |
16 |
| import java.util.List; |
17 |
| import java.util.Properties; |
18 |
| |
19 |
| public abstract class AbstractJspRule extends JspParserVisitorAdapter implements Rule { |
20 |
| |
21 |
| protected String name = getClass().getName(); |
22 |
| protected Properties properties = new Properties(); |
23 |
| protected String message; |
24 |
| protected String description; |
25 |
| protected String example; |
26 |
| protected String ruleSetName; |
27 |
| protected boolean include; |
28 |
| protected boolean usesDFA; |
29 |
| protected boolean usesTypeResolution; |
30 |
| protected int priority = LOWEST_PRIORITY; |
31 |
| protected String externalInfoUrl; |
32 |
| |
33 |
0
| public String getRuleSetName() {
|
34 |
0
| return ruleSetName;
|
35 |
| } |
36 |
| |
37 |
18
| public void setRuleSetName(String ruleSetName) {
|
38 |
18
| this.ruleSetName = ruleSetName;
|
39 |
| } |
40 |
| |
41 |
0
| public String getDescription() {
|
42 |
0
| return description;
|
43 |
| } |
44 |
| |
45 |
16
| public void setDescription(String description) {
|
46 |
16
| this.description = description;
|
47 |
| } |
48 |
| |
49 |
0
| public String getExample() {
|
50 |
0
| return example;
|
51 |
| } |
52 |
| |
53 |
16
| public void setExample(String example) {
|
54 |
16
| this.example = example;
|
55 |
| } |
56 |
| |
57 |
0
| public boolean hasProperty(String name) {
|
58 |
0
| return properties.containsKey(name);
|
59 |
| } |
60 |
| |
61 |
0
| public void addProperty(String name, String value) {
|
62 |
0
| properties.setProperty(name, value);
|
63 |
| } |
64 |
| |
65 |
0
| public void addProperties(Properties properties) {
|
66 |
0
| this.properties.putAll(properties);
|
67 |
| } |
68 |
| |
69 |
0
| public double getDoubleProperty(String name) {
|
70 |
0
| return Double.parseDouble(properties.getProperty(name));
|
71 |
| } |
72 |
| |
73 |
0
| public int getIntProperty(String name) {
|
74 |
0
| return Integer.parseInt(properties.getProperty(name));
|
75 |
| } |
76 |
| |
77 |
0
| public boolean getBooleanProperty(String name) {
|
78 |
0
| return Boolean.valueOf(properties.getProperty(name)).booleanValue();
|
79 |
| } |
80 |
| |
81 |
0
| public String getStringProperty(String name) {
|
82 |
0
| return properties.getProperty(name);
|
83 |
| } |
84 |
| |
85 |
11
| public String getName() {
|
86 |
11
| return name;
|
87 |
| } |
88 |
| |
89 |
16
| public void setName(String name) {
|
90 |
16
| this.name = name;
|
91 |
| } |
92 |
| |
93 |
8
| public String getMessage() {
|
94 |
8
| return message;
|
95 |
| } |
96 |
| |
97 |
16
| public void setMessage(String message) {
|
98 |
16
| this.message = message;
|
99 |
| } |
100 |
| |
101 |
0
| public String getExternalInfoUrl() {
|
102 |
0
| return externalInfoUrl;
|
103 |
| } |
104 |
| |
105 |
16
| public void setExternalInfoUrl(String url) {
|
106 |
16
| this.externalInfoUrl = url;
|
107 |
| } |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
0
| public boolean equals(Object o) {
|
117 |
0
| if (o == null) {
|
118 |
0
| return false;
|
119 |
| } |
120 |
| |
121 |
0
| if (this == o) {
|
122 |
0
| return true;
|
123 |
| } |
124 |
| |
125 |
0
| Rule rule = null;
|
126 |
0
| boolean equality = this.getClass().getName().equals(o.getClass().getName());
|
127 |
| |
128 |
0
| if (equality) {
|
129 |
0
| rule = (Rule) o;
|
130 |
0
| equality = this.getName().equals(rule.getName())
|
131 |
| && this.getPriority() == rule.getPriority() |
132 |
| && this.getProperties().equals(rule.getProperties()); |
133 |
| } |
134 |
| |
135 |
0
| return equality;
|
136 |
| } |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
0
| public int hashCode() {
|
142 |
0
| String s = this.getClass().getName() + this.getName() + this.getPriority() + this.getProperties().toString();
|
143 |
0
| return s.hashCode();
|
144 |
| } |
145 |
| |
146 |
9
| public void apply(List acus, RuleContext ctx) {
|
147 |
9
| visitAll(acus, ctx);
|
148 |
| } |
149 |
| |
150 |
| |
151 |
9
| public Properties getProperties() {
|
152 |
9
| return properties;
|
153 |
| } |
154 |
| |
155 |
0
| public boolean include() {
|
156 |
0
| return include;
|
157 |
| } |
158 |
| |
159 |
0
| public void setInclude(boolean include) {
|
160 |
0
| this.include = include;
|
161 |
| } |
162 |
| |
163 |
16
| public int getPriority() {
|
164 |
16
| return priority;
|
165 |
| } |
166 |
| |
167 |
0
| public String getPriorityName() {
|
168 |
0
| return PRIORITIES[getPriority() - 1];
|
169 |
| } |
170 |
| |
171 |
16
| public void setPriority(int priority) {
|
172 |
16
| this.priority = priority;
|
173 |
| } |
174 |
| |
175 |
0
| public void setUsesDFA() {
|
176 |
0
| this.usesDFA = true;
|
177 |
| } |
178 |
| |
179 |
9
| public boolean usesDFA() {
|
180 |
9
| return this.usesDFA;
|
181 |
| } |
182 |
| |
183 |
0
| public void setUsesTypeResolution() {
|
184 |
| } |
185 |
| |
186 |
9
| public boolean usesTypeResolution() {
|
187 |
9
| return false;
|
188 |
| } |
189 |
| |
190 |
9
| protected void visitAll(List acus, RuleContext ctx) {
|
191 |
9
| for (Iterator i = acus.iterator(); i.hasNext();) {
|
192 |
9
| SimpleNode node = (SimpleNode) i.next();
|
193 |
9
| visit(node, ctx);
|
194 |
| } |
195 |
| } |
196 |
| |
197 |
| |
198 |
| |
199 |
| |
200 |
| |
201 |
| |
202 |
| |
203 |
3
| protected final void addViolation(Object data, SimpleNode node) {
|
204 |
3
| RuleContext ctx = (RuleContext) data;
|
205 |
3
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node));
|
206 |
| } |
207 |
| |
208 |
| |
209 |
| |
210 |
| |
211 |
| |
212 |
| |
213 |
| |
214 |
| |
215 |
0
| protected final void addViolationWithMessage(Object data, SimpleNode node, String msg) {
|
216 |
0
| RuleContext ctx = (RuleContext) data;
|
217 |
0
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, msg));
|
218 |
| } |
219 |
| |
220 |
| |
221 |
| |
222 |
| |
223 |
| |
224 |
| |
225 |
| |
226 |
| |
227 |
5
| protected final void addViolation(Object data, SimpleNode node, String embed) {
|
228 |
5
| RuleContext ctx = (RuleContext) data;
|
229 |
5
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
|
230 |
| } |
231 |
| |
232 |
| |
233 |
| |
234 |
| |
235 |
| |
236 |
| |
237 |
| |
238 |
| |
239 |
0
| protected final void addViolation(Object data, Node node, Object[] args) {
|
240 |
0
| RuleContext ctx = (RuleContext) data;
|
241 |
0
| ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, (SimpleNode) node, MessageFormat.format(getMessage(), args)));
|
242 |
| } |
243 |
| |
244 |
0
| public PropertyDescriptor propertyDescriptorFor(String name) {
|
245 |
0
| return null;
|
246 |
| } |
247 |
| } |