forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#13345: Enable examples tests for CyclomaticComplexit…
…yCheck
- Loading branch information
1 parent
c0c1fe0
commit bc02282
Showing
9 changed files
with
298 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...sources/com/puppycrawl/tools/checkstyle/checks/metrics/cyclomaticcomplexity/Example1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*xml | ||
<module name="Checker"> | ||
<module name="TreeWalker"> | ||
<module name="CyclomaticComplexity"/> | ||
</module> | ||
</module> | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.metrics.cyclomaticcomplexity; | ||
|
||
// xdoc section -- start | ||
class Example1 { | ||
int a, b, c, d, e, n; | ||
|
||
public void testMethod1() { | ||
while (a < b && a > c) { | ||
fun1(); | ||
} | ||
if (a == b) { | ||
do { | ||
fun1(); | ||
} while (d==a); | ||
} else if (c == d) { | ||
while (c > 0) { | ||
fun1(); | ||
} | ||
do { | ||
fun1(); | ||
} while (a==d); | ||
} | ||
} | ||
// violation below, 'Cyclomatic Complexity is 13 (max allowed is 10)' | ||
public void testMethod2() { // 1, function declaration | ||
if (a == b) { // 2, if | ||
fun1(); | ||
} else if (a == 0 // 3, if | ||
&& b == c) { // 4, && operator | ||
if (c == -1) { // 5, if | ||
fun1(); | ||
} | ||
} else if (a == c // 6, if | ||
|| a == d) { // 7, || operator | ||
fun1(); | ||
} else if (d == e) { //8, if | ||
try { | ||
fun1(); | ||
} catch (Exception e) { // 9, catch | ||
} | ||
} else { | ||
switch(n) { | ||
case 1: // 10, case | ||
fun1(); | ||
break; | ||
case 2: // 11, case | ||
fun1(); | ||
break; | ||
case 3: // 12, case | ||
fun1(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
a = a > 0 ? b : c; // 13, ternary operator | ||
} | ||
private void fun1() {} | ||
} | ||
// xdoc section -- end |
44 changes: 0 additions & 44 deletions
44
...esources/com/puppycrawl/tools/checkstyle/checks/metrics/cyclomaticcomplexity/Example1.txt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...sources/com/puppycrawl/tools/checkstyle/checks/metrics/cyclomaticcomplexity/Example2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*xml | ||
<module name="Checker"> | ||
<module name="TreeWalker"> | ||
<module name="CyclomaticComplexity"> | ||
<property name="max" value="4"/> | ||
<property name="tokens" value="LITERAL_WHILE, LITERAL_DO"/> | ||
</module> | ||
</module> | ||
</module> | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.metrics.cyclomaticcomplexity; | ||
|
||
// xdoc section -- start | ||
class Example2 { | ||
int a, b, c, d, e, n; | ||
// violation below, 'Cyclomatic Complexity is 5 (max allowed is 4)' | ||
public void testMethod1() { // 1, function declaration | ||
while (a < b && a > c) { // 2, while | ||
fun1(); | ||
} | ||
if (a == b) { | ||
do { // 3, do | ||
fun1(); | ||
} while (d==a); | ||
} else if (c == d) { | ||
while (c > 0) { // 4, while | ||
fun1(); | ||
} | ||
do { // 5, do-while | ||
fun1(); | ||
} while (a==d); | ||
} | ||
} | ||
|
||
public void testMethod2() { | ||
if (a == b) { | ||
fun1(); | ||
} else if (a == 0 | ||
&& b == c) { | ||
if (c == -1) { | ||
fun1(); | ||
} | ||
} else if (a == c | ||
|| a == d) { | ||
fun1(); | ||
} else if (d == e) { | ||
try { | ||
fun1(); | ||
} catch (Exception e) { | ||
} | ||
} else { | ||
switch(n) { | ||
case 1: | ||
fun1(); | ||
break; | ||
case 2: | ||
fun1(); | ||
break; | ||
case 3: | ||
fun1(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
a = a > 0 ? b : c; | ||
} | ||
private void fun1() {} | ||
} | ||
// xdoc section -- end |
35 changes: 0 additions & 35 deletions
35
...esources/com/puppycrawl/tools/checkstyle/checks/metrics/cyclomaticcomplexity/Example2.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.