LeftCurlyCheck updated to follow Cyclomatic Complexity rule. #954

This commit is contained in:
Roman Ivanov 2015-06-13 18:32:24 -07:00
parent 0868085098
commit ae0e7def77
1 changed files with 29 additions and 15 deletions

View File

@ -315,25 +315,39 @@ public class LeftCurlyCheck
}
else if (getAbstractOption() == LeftCurlyOption.NLOW
&& startToken.getLineNo() != brace.getLineNo()) {
// not on the same line
if (startToken.getLineNo() + 1 == brace.getLineNo()) {
if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_NEW, "{");
}
else if (prevLineLen + 2 <= maxLineLength) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_PREVIOUS, "{");
}
}
else if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_NEW, "{");
}
validateNewLinePosion(brace, startToken, braceLine, prevLineLen);
}
}
}
/**
* validate token on new Line position
* @param brace brace AST
* @param startToken start Token
* @param braceLine content of line with Brace
* @param prevLineLen previous Line length
*/
private void validateNewLinePosion(DetailAST brace, DetailAST startToken,
String braceLine, int prevLineLen) {
// not on the same line
if (startToken.getLineNo() + 1 == brace.getLineNo()) {
if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_NEW, "{");
}
else if (prevLineLen + 2 <= maxLineLength) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_PREVIOUS, "{");
}
}
else if (!Utils.whitespaceBefore(brace.getColumnNo(), braceLine)) {
log(brace.getLineNo(), brace.getColumnNo(),
MSG_KEY_LINE_NEW, "{");
}
}
/**
* Checks if left curly has line break after.
* @param leftCurly