Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 63 |  | Methods: | 4
| NCLOC: | 27 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
ExcessivePublicCount.java | 100% | 100% | 100% | 100% |

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 |  | import net.sourceforge.pmd.util.NumericConstants;
12 |  |
13 |  | /**
14 |  | * @author aglover
15 |  | * <p/>
16 |  | * Class Name: ExcessivePublicCount
17 |  | * <p/>
18 |  | * Rule attempts to count all public methods and public attributes defined in a class.
19 |  | * <p/>
20 |  | * If a class has a high number of public operations, it might be wise to consider whether
21 |  | * it would be appropriate to divide it into subclasses.
22 |  | * <p/>
23 |  | * A large proportion of public members and operations means the class has high potential to be
24 |  | * affected by external classes. Futhermore, increased effort will be required to
25 |  | * thoroughly test the class.
26 |  | */
27 |  | public class ExcessivePublicCount extends ExcessiveNodeCountRule {
28 |  |
29 | 14 | public ExcessivePublicCount() {
30 | 14 | super(ASTCompilationUnit.class);
31 |  | }
32 |  |
33 |  | /**
34 |  | * Method counts ONLY public methods.
35 |  | */
36 | 9 | public Object visit(ASTMethodDeclarator node, Object data) {
37 | 9 | return this.getTallyOnAccessType((AccessNode) node.jjtGetParent());
38 |  | }
39 |  |
40 |  | /**
41 |  | * Method counts ONLY public class attributes which are not PUBLIC and
42 |  | * static- these usually represent constants....
43 |  | */
44 | 13 | public Object visit(ASTFieldDeclaration node, Object data) {
45 | 13 | if (node.isFinal() && node.isStatic()) {
46 | 8 | return NumericConstants.ZERO;
47 |  | }
48 | 5 | return this.getTallyOnAccessType(node);
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 | 14 | private Integer getTallyOnAccessType(AccessNode node) {
58 | 14 | if (node.isPublic()) {
59 | 11 | return NumericConstants.ONE;
60 |  | }
61 | 3 | return NumericConstants.ZERO;
62 |  | }
63 |  | }