Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 84 |  | Methods: | 9
| NCLOC: | 56 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
NcssTypeCount.java | 50% | 44.4% | 44.4% | 45.5% |

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 |  | * Non-commented source statement counter for type declarations.
20 |  | *
21 |  | * @author Jason Bennett
22 |  | */
23 |  | public class NcssTypeCount extends AbstractNcssCount {
24 |  |
25 |  | /**
26 |  | * Count type declarations. This includes classes as well as enums and
27 |  | * annotations.
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 |  | * If the enum is a type in and of itself, don't count its declaration
53 |  | * twice.
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 |  | }