From dd4b2b9112ad1d2a8f4c1249e3470c2f9125fec7 Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Thu, 14 Feb 2008 09:06:49 +0000 Subject: [PATCH] Small upgrade to CyclomaticComplexity. By default, the rule add two kind of violation (method violation, but also a class average complexity). Some user find that troublesome and it maybe messy if an aggregated report. So i had a simple configuration to the rule. I also had a couple of unit test to ensure proper behavior of this modification. Code cleaning, switching inheritance to AbstractJavaRule. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5773 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 2 + .../codesize/xml/CyclomaticComplexity.xml | 38 +++++++-- pmd/rulesets/codesize.xml | 71 +++++++++-------- .../pmd/rules/CyclomaticComplexity.java | 78 ++++++++++--------- 4 files changed, 116 insertions(+), 73 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 179e52d2b2..a1911c5a06 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -14,6 +14,8 @@ New rules: StrictExceptions : DoNotThrowExceptionInFinally Strings : AvoidStringBufferField +Rule upgrade: + CyclomaticComplexity now can be configure to display only classes average complexity or methods complexity, or both. 1.7 added as a valid option for targetjdk. New elements under : to match files exclude from processing, with to override. diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/codesize/xml/CyclomaticComplexity.xml b/pmd/regress/test/net/sourceforge/pmd/rules/codesize/xml/CyclomaticComplexity.xml index 281a8118cc..50ffb005bc 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/codesize/xml/CyclomaticComplexity.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/codesize/xml/CyclomaticComplexity.xml @@ -11,12 +11,8 @@ public class Foo { } ]]> - - - 2 - + + ]]> + + + + 2 + + + + + + false + 1 + + + + + + + false + 1 + + + \ No newline at end of file diff --git a/pmd/rulesets/codesize.xml b/pmd/rulesets/codesize.xml index 9976d0b14a..f7cec7e22a 100644 --- a/pmd/rulesets/codesize.xml +++ b/pmd/rulesets/codesize.xml @@ -112,19 +112,28 @@ public class Foo { - + + 3 + + + This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines -of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, +of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 3 @@ -239,11 +248,11 @@ lines of code that are split are counted as one. public class Foo extends Bar { public int methd() { super.methd(); - - - - - + + + + + //this method only has 1 NCSS lines return 1; } @@ -253,11 +262,11 @@ public class Foo extends Bar { This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines -of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, +of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 3 @@ -270,11 +279,11 @@ public class Foo extends Bar { public Foo() { //this class only has 6 NCSS lines super(); - - - - - + + + + + super.foo(); } } @@ -282,11 +291,11 @@ public class Foo extends Bar { This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines -of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, +of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 3 @@ -298,11 +307,11 @@ lines of code that are split are counted as one. public class Foo extends Bar { public Foo() { super(); - - - - - + + + + + //this constructor only has 1 NCSS lines super.foo(); } @@ -327,16 +336,16 @@ have more fine grained objects. -