1
2
3
4 package net.sourceforge.pmd.lang.java.rule.codesize;
5
6 import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
7 import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
8 import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
9 import net.sourceforge.pmd.lang.java.ast.AccessNode;
10 import net.sourceforge.pmd.lang.java.rule.design.ExcessiveNodeCountRule;
11 import net.sourceforge.pmd.util.NumericConstants;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class ExcessivePublicCountRule extends ExcessiveNodeCountRule {
28
29 public ExcessivePublicCountRule() {
30 super(ASTCompilationUnit.class);
31 setProperty(MINIMUM_DESCRIPTOR, 45d);
32 }
33
34
35
36
37 public Object visit(ASTMethodDeclarator node, Object data) {
38 return this.getTallyOnAccessType((AccessNode) node.jjtGetParent());
39 }
40
41
42
43
44
45 public Object visit(ASTFieldDeclaration node, Object data) {
46 if (node.isFinal() && node.isStatic()) {
47 return NumericConstants.ZERO;
48 }
49 return this.getTallyOnAccessType(node);
50 }
51
52
53
54
55
56
57
58 private Integer getTallyOnAccessType(AccessNode node) {
59 if (node.isPublic()) {
60 return NumericConstants.ONE;
61 }
62 return NumericConstants.ZERO;
63 }
64 }