Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 46 |  | Methods: | 2
| NCLOC: | 33 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
DuplicateJspImports.java | 83.3% | 92.9% | 100% | 90.9% |

1 |  | package net.sourceforge.pmd.jsp.rules;
2 |  |
3 |  | import net.sourceforge.pmd.RuleContext;
4 |  | import net.sourceforge.pmd.jsp.ast.ASTJspDirectiveAttribute;
5 |  | import net.sourceforge.pmd.rules.ImportWrapper;
6 |  |
7 |  | import java.util.HashSet;
8 |  | import java.util.List;
9 |  | import java.util.Set;
10 |  | import java.util.StringTokenizer;
11 |  |
12 |  | public class DuplicateJspImports extends AbstractJspRule {
13 |  |
14 |  | private Set imports = new HashSet();
15 |  |
16 | 6 | public void apply(List acus, RuleContext ctx) {
17 |  | /*
18 |  | * TODO: This method is a hack! It's overriding the parent's method
19 |  | * because the JSP parsing doesn't seem to hit ASTCompilationUnit
20 |  | * properly
21 |  | */
22 | 6 | imports.clear();
23 | 6 | super.apply(acus, ctx);
24 |  | }
25 |  |
26 | 10 | public Object visit(ASTJspDirectiveAttribute node, Object data) {
27 |  |
28 | 10 | if (!"import".equals(node.getName())) {
29 | 0 | return super.visit(node, data);
30 |  | }
31 | 10 | String values = node.getValue();
32 | 10 | StringTokenizer st = new StringTokenizer(values, ",");
33 | 10 | int count = st.countTokens();
34 | 10 | for (int ix = 0; ix < count; ix++) {
35 | 13 | String token = st.nextToken();
36 | 13 | ImportWrapper wrapper = new ImportWrapper(token, token, node);
37 | 13 | if (imports.contains(wrapper)) {
38 | 5 | addViolation(data, node, node.getImage());
39 |  | } else {
40 | 8 | imports.add(wrapper);
41 |  | }
42 |  | }
43 | 10 | return super.visit(node, data);
44 |  | }
45 |  |
46 |  | }