View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.rule.codesize;
5   
6   import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
7   import net.sourceforge.pmd.lang.java.ast.ASTExplicitConstructorInvocation;
8   import net.sourceforge.pmd.stat.DataPoint;
9   import net.sourceforge.pmd.util.NumericConstants;
10  
11  /**
12   * Non-commented source statement counter for constructors.
13   * 
14   * @author Jason Bennett
15   */
16  public class NcssConstructorCountRule extends AbstractNcssCountRule {
17  
18      /**
19       * Count constructor declarations. This includes any explicit super() calls.
20       */
21      public NcssConstructorCountRule() {
22          super(ASTConstructorDeclaration.class);
23          setProperty(MINIMUM_DESCRIPTOR, 100d);
24      }
25  
26      public Object visit(ASTExplicitConstructorInvocation node, Object data) {
27          return NumericConstants.ONE;
28      }
29  
30      @Override
31      public Object[] getViolationParameters(DataPoint point) {
32          // TODO need to put class name or constructor ID in string
33          return new String[] { String.valueOf(((ASTConstructorDeclaration) point.getNode()).getParameterCount()),
34                  String.valueOf((int) point.getScore()) };
35      }
36  }