1 |
| package net.sourceforge.pmd.rules.codesize; |
2 |
| |
3 |
| import java.util.Iterator; |
4 |
| import java.util.Set; |
5 |
| |
6 |
| import net.sourceforge.pmd.RuleContext; |
7 |
| import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; |
8 |
| import net.sourceforge.pmd.ast.ASTConstructorDeclaration; |
9 |
| import net.sourceforge.pmd.ast.ASTEnumDeclaration; |
10 |
| import net.sourceforge.pmd.ast.ASTExplicitConstructorInvocation; |
11 |
| import net.sourceforge.pmd.ast.ASTFieldDeclaration; |
12 |
| import net.sourceforge.pmd.ast.ASTInitializer; |
13 |
| import net.sourceforge.pmd.ast.ASTMethodDeclaration; |
14 |
| import net.sourceforge.pmd.ast.ASTTypeDeclaration; |
15 |
| import net.sourceforge.pmd.stat.DataPoint; |
16 |
| import net.sourceforge.pmd.util.NumericConstants; |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class NcssTypeCount extends AbstractNcssCount { |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
13
| public NcssTypeCount() {
|
30 |
13
| super( ASTTypeDeclaration.class );
|
31 |
| } |
32 |
| |
33 |
4
| public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
34 |
| |
35 |
4
| if ( !node.isNested() ) {
|
36 |
4
| return super.visit( node, data );
|
37 |
| } |
38 |
| |
39 |
0
| return countNodeChildren( node, data );
|
40 |
| } |
41 |
| |
42 |
0
| public Object visit(ASTConstructorDeclaration node, Object data) {
|
43 |
0
| return countNodeChildren( node, data );
|
44 |
| } |
45 |
| |
46 |
0
| public Object visit(ASTExplicitConstructorInvocation node, Object data) {
|
47 |
0
| return NumericConstants.ONE;
|
48 |
| } |
49 |
| |
50 |
0
| public Object visit(ASTEnumDeclaration node, Object data) {
|
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
0
| if ( node.jjtGetParent() instanceof ASTTypeDeclaration ) {
|
56 |
0
| Integer nodeCount = countNodeChildren( node, data );
|
57 |
0
| int count = nodeCount.intValue() - 1;
|
58 |
0
| return new Integer( count );
|
59 |
| } |
60 |
0
| return countNodeChildren( node, data );
|
61 |
| } |
62 |
| |
63 |
4
| public Object visit(ASTMethodDeclaration node, Object data) {
|
64 |
4
| return countNodeChildren( node, data );
|
65 |
| } |
66 |
| |
67 |
0
| public Object visit(ASTInitializer node, Object data) {
|
68 |
0
| return countNodeChildren( node, data );
|
69 |
| } |
70 |
| |
71 |
0
| public Object visit(ASTFieldDeclaration node, Object data) {
|
72 |
0
| return NumericConstants.ONE;
|
73 |
| } |
74 |
| |
75 |
4
| protected void makeViolations(RuleContext ctx, Set p) {
|
76 |
4
| Iterator points = p.iterator();
|
77 |
4
| while ( points.hasNext() ) {
|
78 |
1
| DataPoint point = (DataPoint) points.next();
|
79 |
1
| addViolation( ctx, point.getNode(),
|
80 |
| String.valueOf( (int) point.getScore() ) ); |
81 |
| } |
82 |
| } |
83 |
| |
84 |
| } |