Merge branch 'pr-2593'

[java] NPathComplexity should mention the expected NPath complexity #2593
This commit is contained in:
Andreas Dangel
2020-06-18 15:09:35 +02:00
4 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/**
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
@ -78,7 +78,9 @@ public class NPathComplexityRule extends AbstractJavaMetricsRule {
int npath = (int) MetricsUtil.computeMetric(JavaOperationMetricKey.NPATH, node);
if (npath >= reportLevel) {
addViolation(data, node, new String[] {node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node), "" + npath, });
PrettyPrintingUtil.displaySignature(node),
String.valueOf(npath),
String.valueOf(reportLevel)});
}
return data;

View File

@ -1111,7 +1111,7 @@ public class Foo extends Bar {
<rule name="NPathComplexity"
since="3.9"
message="The {0} ''{1}'' has an NPath complexity of {2}"
message="The {0} ''{1}'' has an NPath complexity of {2}, current threshold is {3}"
class="net.sourceforge.pmd.lang.java.rule.design.NPathComplexityRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#npathcomplexity">
<description>

View File

@ -55,7 +55,7 @@ public class Foo {
<description>Full example</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>The method 'bar()' has an NPath complexity of 2016</message>
<message>The method 'bar()' has an NPath complexity of 2016, current threshold is 200</message>
</expected-messages>
<code-ref id="full-example"/>
</test-code>
@ -65,7 +65,7 @@ public class Foo {
<rule-property name="reportLevel">0</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>The method 'bar()' has an NPath complexity of 200</message>
<message>The method 'bar()' has an NPath complexity of 200, current threshold is 0</message>
</expected-messages>
<code><![CDATA[
public class Foo {
@ -131,7 +131,7 @@ class Foo {
<rule-property name="reportLevel">2</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>The method 'bar()' has an NPath complexity of 4</message>
<message>The method 'bar()' has an NPath complexity of 4, current threshold is 2</message>
</expected-messages>
<code><![CDATA[
class Foo {
@ -163,8 +163,8 @@ class Bar {
<rule-property name="reportLevel">4</rule-property>
<expected-problems>2</expected-problems>
<expected-messages>
<message>The method 'x(boolean, boolean)' has an NPath complexity of 4</message>
<message>The method 'y(boolean, boolean)' has an NPath complexity of 4</message>
<message>The method 'x(boolean, boolean)' has an NPath complexity of 4, current threshold is 4</message>
<message>The method 'y(boolean, boolean)' has an NPath complexity of 4, current threshold is 4</message>
</expected-messages>
<code-ref id="bug3484404"/>
</test-code>
@ -174,7 +174,7 @@ class Bar {
<rule-property name="reportLevel">6</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>The constructor 'Foo()' has an NPath complexity of 7</message>
<message>The constructor 'Foo()' has an NPath complexity of 7, current threshold is 6</message>
</expected-messages>
<code><![CDATA[
class Foo {