01: package net.sourceforge.pmd.rules.codesize;
02:
03: import java.util.Set;
04:
05: import net.sourceforge.pmd.RuleContext;
06: import net.sourceforge.pmd.ast.ASTConstructorDeclaration;
07: import net.sourceforge.pmd.ast.ASTExplicitConstructorInvocation;
08: import net.sourceforge.pmd.stat.DataPoint;
09: 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 NcssConstructorCount extends AbstractNcssCount {
17:
18: /**
19: * Count constructor declarations. This includes any explicit super() calls.
20: */
21: public NcssConstructorCount() {
22: super (ASTConstructorDeclaration.class);
23: }
24:
25: public Object visit(ASTExplicitConstructorInvocation node,
26: Object data) {
27: return NumericConstants.ONE;
28: }
29:
30: protected void makeViolations(RuleContext ctx, Set<DataPoint> p) {
31: for (DataPoint point : p) {
32: // TODO need to put class name or constructor ID in string
33: addViolation(ctx, point.getNode(), new String[] {
34: String.valueOf(((ASTConstructorDeclaration) point
35: .getNode()).getParameterCount()),
36: String.valueOf((int) point.getScore()) });
37: }
38: }
39: }
|