This commit is contained in:
Robert Sösemann
2016-04-19 15:39:14 +02:00
parent 25f5399d15
commit 021c92d9a9
4 changed files with 65 additions and 8 deletions

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.rule.complexity;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.stat.DataPoint;
import net.sourceforge.pmd.util.NumericConstants;
@ -25,8 +24,13 @@ public class NcssConstructorCountRule extends AbstractNcssCountRule {
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100);
}
public Object visit(ASTMethodCallExpression node, Object data) {
return NumericConstants.ONE;
@Override
public Object visit(ASTMethod node, Object data) {
if (node.getNode().getMethodInfo().isConstructor()) {
return super.visit(node, data);
}
return NumericConstants.ZERO;
}
@Override

View File

@ -143,7 +143,7 @@ public class Foo extends Bar {
]]>
</example></rule>
<rule name="NcssConstructorCount" message="The constructor with {0} parameters has an NCSS line count of {1}"
<rule name="NcssConstructorCount" message="The constructor has an NCSS line count of {0}"
class="net.sourceforge.pmd.lang.apex.rule.complexity.NcssConstructorCountRule"
externalInfoUrl="${pmd.website.baseurl}/rules/apex/complexity.html#NcssConstructorCount">
<description>

View File

@ -37,7 +37,7 @@ public class Foo {
]]></code>
</test-code>
<code-fragment id="long method"><![CDATA[
<code-fragment id="long constructor"><![CDATA[
public class Foo {
public Foo() {
//nothing to see here
@ -65,10 +65,10 @@ public class Foo {
]]></code-fragment>
<test-code>
<description>long method</description>
<description>long constructor</description>
<rule-property name="minimum">13</rule-property>
<expected-problems>1</expected-problems>
<code-ref id="long method"/>
<code-ref id="long constructor"/>
</test-code>
<test-code>
@ -76,7 +76,35 @@ public class Foo {
<!-- obtained this value by using NCSS directly -->
<rule-property name="minimum">14</rule-property>
<expected-problems>0</expected-problems>
<code-ref id="long method"/>
<code-ref id="long constructor"/>
</test-code>
<test-code>
<description>ignore non-constructor methods</description>
<expected-problems>0</expected-problems>
<rule-property name="minimum">10</rule-property>
<code><![CDATA[
public class Foo {
public void bar() {
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
}
}
]]></code>
</test-code>
</test-data>

View File

@ -79,4 +79,29 @@ public class Foo {
<code-ref id="long method"/>
</test-code>
<test-code>
<description>ignores constructor</description>
<rule-property name="minimum">10</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public Foo() {
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
bar();
}
}
]]></code>
</test-code>
</test-data>