KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > codesize > NcssConstructorCount


1 package net.sourceforge.pmd.rules.codesize;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import net.sourceforge.pmd.RuleContext;
7 import net.sourceforge.pmd.ast.ASTConstructorDeclaration;
8 import net.sourceforge.pmd.ast.ASTExplicitConstructorInvocation;
9 import net.sourceforge.pmd.stat.DataPoint;
10 import net.sourceforge.pmd.util.NumericConstants;
11
12 /**
13  * Non-commented source statement counter for constructors.
14  *
15  * @author Jason Bennett
16  */

17 public class NcssConstructorCount extends AbstractNcssCount {
18
19   /**
20    * Count constructor declarations. This includes any explicit super() calls.
21    */

22   public NcssConstructorCount() {
23     super( ASTConstructorDeclaration.class );
24   }
25
26   public Object JavaDoc visit(ASTExplicitConstructorInvocation node, Object JavaDoc data) {
27     return NumericConstants.ONE;
28   }
29
30   protected void makeViolations(RuleContext ctx, Set JavaDoc p) {
31     Iterator JavaDoc points = p.iterator();
32     while ( points.hasNext() ) {
33       DataPoint point = (DataPoint) points.next();
34       // TODO need to put class name or constructor ID in string
35
addViolation(
36           ctx,
37           point.getNode(),
38           new String JavaDoc[] {
39               String.valueOf( ( (ASTConstructorDeclaration) point.getNode() ).getParameterCount() ),
40               String.valueOf( (int) point.getScore() ) } );
41     }
42   }
43 }
44
Popular Tags