LeftCurlyCheck updated to follow Cyclomatic Complexity rule. #954

This commit is contained in:
Roman Ivanov 2015-06-13 18:49:45 -07:00
parent cefc92307e
commit 2b32b003ab
1 changed files with 19 additions and 8 deletions

View File

@ -304,14 +304,8 @@ public class LeftCurlyCheck
}
}
else if (getAbstractOption() == LeftCurlyOption.EOL) {
if (Utils.whitespaceBefore(brace.getColumnNo(), braceLine)
&& prevLineLen + 2 <= maxLineLength) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_PREVIOUS, "{");
}
if (!hasLineBreakAfter(brace)) {
log(brace.getLineNo(), brace.getColumnNo(), MSG_KEY_LINE_BREAK_AFTER);
}
validateEol(brace, braceLine, prevLineLen);
}
else if (getAbstractOption() == LeftCurlyOption.NLOW
&& startToken.getLineNo() != brace.getLineNo()) {
@ -322,6 +316,23 @@ public class LeftCurlyCheck
}
}
/**
* validate EOL case
* @param brace brase AST
* @param braceLine line content
* @param prevLineLen previous line length
*/
private void validateEol(DetailAST brace, String braceLine, int prevLineLen) {
if (Utils.whitespaceBefore(brace.getColumnNo(), braceLine)
&& prevLineLen + 2 <= maxLineLength) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_PREVIOUS, "{");
}
if (!hasLineBreakAfter(brace)) {
log(brace.getLineNo(), brace.getColumnNo(), MSG_KEY_LINE_BREAK_AFTER);
}
}
/**
* validate token on new Line position
* @param brace brace AST