Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 234 |  | Methods: | 35
| NCLOC: | 150 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
AbstractJspRule.java | 25% | 37.3% | 42.9% | 38.3% |

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