View Javadoc

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.ASTMethodDeclaration;
8   import net.sourceforge.pmd.stat.DataPoint;
9   
10  /***
11   * Non-commented source statement counter for methods.
12   * 
13   * @author Jason Bennett
14   */
15  public class NcssMethodCount extends AbstractNcssCount {
16  
17    /***
18     * Count the size of all non-constructor methods.
19     */
20    public NcssMethodCount() {
21      super( ASTMethodDeclaration.class );
22    }
23  
24    public Object visit(ASTMethodDeclaration node, Object data) {
25      return super.visit( node, data );
26    }
27  
28    protected void makeViolations(RuleContext ctx, Set p) {
29      Iterator points = p.iterator();
30      while ( points.hasNext() ) {
31        DataPoint point = (DataPoint) points.next();
32        addViolation( ctx, point.getNode(), new String[] {
33            ( (ASTMethodDeclaration) point.getNode() ).getMethodName(),
34            String.valueOf( (int) point.getScore() ) } );
35      }
36    }
37  
38  }