RightCurlyCheck updated to follow Cyclomatic Complexity rule. #954

This commit is contained in:
Roman Ivanov 2015-06-13 18:37:28 -07:00
parent ae0e7def77
commit c99f34002b
2 changed files with 26 additions and 12 deletions

View File

@ -22,7 +22,10 @@
<properties>
<property name="showClassesComplexity" value="false"/>
<property name="reportLevel" value="11"/>
<property name="violationSuppressXPath" value="//MethodDeclaration[@Name='validateCli' and ../../..[@Image='Main']]"/>
<!-- validateCli is not reasonbale to split as incapsulation of logic will be damaged
getDetails - huge Switch, it has to be monolitic
-->
<property name="violationSuppressXPath" value="//MethodDeclaration[@Name='validateCli' and ../../..[@Image='Main']] | //MethodDeclaration[@Name='getDetails' and ../../..[@Image='RightCurlyCheck']]"/>
</properties>
</rule>
<rule ref="rulesets/java/codesize.xml/TooManyMethods">

View File

@ -154,6 +154,28 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
}
final DetailAST lcurly = details.lcurly;
validate(details, rcurly, lcurly);
if (!shouldStartLine) {
return;
}
final boolean startsLine =
Utils.whitespaceBefore(rcurly.getColumnNo(),
getLines()[rcurly.getLineNo() - 1]);
if (!startsLine && lcurly.getLineNo() != rcurly.getLineNo()) {
log(rcurly, MSG_KEY_LINE_NEW, "}");
}
}
/**
* do general validation
* @param details details
* @param rcurly right curly token
* @param lcurly left curly token
*/
private void validate(Details details, DetailAST rcurly, DetailAST lcurly) {
final DetailAST nextToken = details.nextToken;
final boolean shouldCheckLastRcurly = details.shouldCheckLastRcurly;
@ -175,17 +197,6 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
&& !isEmptyBody(lcurly)) {
log(rcurly, MSG_KEY_LINE_ALONE, "}");
}
if (!shouldStartLine) {
return;
}
final boolean startsLine =
Utils.whitespaceBefore(rcurly.getColumnNo(),
getLines()[rcurly.getLineNo() - 1]);
if (!startsLine && lcurly.getLineNo() != rcurly.getLineNo()) {
log(rcurly, MSG_KEY_LINE_NEW, "}");
}
}
/**