View Javadoc

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