Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 63 |  | Methods: | 4
| NCLOC: | 27 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ExcessivePublicCount.java

50%

62.5%

75%

62.5%

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
4 |  | package net.sourceforge.pmd.rules;
5 |  |
6 |  | import net.sourceforge.pmd.ast.ASTCompilationUnit;
7 |  | import net.sourceforge.pmd.ast.ASTFieldDeclaration;
8 |  | import net.sourceforge.pmd.ast.ASTMethodDeclarator;
9 |  | import net.sourceforge.pmd.ast.AccessNode;
10 |  | import net.sourceforge.pmd.rules.design.ExcessiveNodeCountRule;
11 |  |
12 |  | /**
13 |  | * @author aglover
14 |  | * <p/>
15 |  | * Class Name: ExcessivePublicCount
16 |  | * <p/>
17 |  | * Rule attempts to count all public methods and public attributes defined in a class.
18 |  | * <p/>
19 |  | * If a class has a high number of public operations, it might be wise to consider whether
20 |  | * it would be appropriate to divide it into subclasses.
21 |  | * <p/>
22 |  | * A large proportion of public members and operations means the class has high potential to be
23 |  | * affected by external classes. Futhermore, increased effort will be required to
24 |  | * thoroughly test the class.
25 |  | */
26 |  | public class ExcessivePublicCount extends ExcessiveNodeCountRule {
27 |  |
28 | 15 | public ExcessivePublicCount() {
29 | 15 | super(ASTCompilationUnit.class);
30 |  | }
31 |  |
32 |  | /**
33 |  | * Method counts ONLY public methods.
34 |  | */
35 | 0 | public Object visit(ASTMethodDeclarator node, Object data) {
36 | 0 | return this.getTallyOnAccessType((AccessNode) node.jjtGetParent());
37 |  | }
38 |  |
39 |  | /**
40 |  | * Method counts ONLY public class attributes which are not PUBLIC and
41 |  | * static- these usually represent constants....
42 |  | */
43 | 5 | public Object visit(ASTFieldDeclaration node, Object data) {
44 | 5 | if (node.isFinal() && node.isStatic()) {
45 | 0 | return new Integer(0);
46 |  | } else {
47 | 5 | return this.getTallyOnAccessType(node);
48 |  | }
49 |  | }
50 |  |
51 |  | /**
52 |  | * Method counts a node if it is public
53 |  | *
54 |  | * @param AccessNode node
55 |  | * @return Integer 1 if node is public 0 otherwise
56 |  | */
57 | 5 | private Integer getTallyOnAccessType(AccessNode node) {
58 | 5 | if (node.isPublic()) {
59 | 5 | return new Integer(1);
60 |  | }
61 | 0 | return new Integer(0);
62 |  | }
63 |  | }