Issue #46: Statements shouldn't be nested too deep.

This commit is contained in:
Ilja Dubinin 2015-08-31 22:50:13 +01:00
parent 9183d6c240
commit 6e775898e7
2 changed files with 30 additions and 22 deletions

View File

@ -303,18 +303,16 @@ public class AbbreviationAsWordInNameCheck extends Check {
beginIndex = index;
}
}
else {
if (abbrStarted) {
abbrStarted = false;
else if (abbrStarted) {
abbrStarted = false;
final int endIndex = index - 1;
// -1 as a first capital is usually beginning of next word
result = getAbbreviationIfIllegal(str, beginIndex, endIndex);
if (result != null) {
break;
}
beginIndex = -1;
final int endIndex = index - 1;
// -1 as a first capital is usually beginning of next word
result = getAbbreviationIfIllegal(str, beginIndex, endIndex);
if (result != null) {
break;
}
beginIndex = -1;
}
}
// if abbreviation at the end of name and it is not single character (example: scaleX)

View File

@ -94,18 +94,7 @@ public class MethodLengthCheck extends Check {
if (openingBrace != null) {
final DetailAST closingBrace =
openingBrace.findFirstToken(TokenTypes.RCURLY);
int length =
closingBrace.getLineNo() - openingBrace.getLineNo() + 1;
if (!countEmpty) {
final FileContents contents = getFileContents();
final int lastLine = closingBrace.getLineNo();
for (int i = openingBrace.getLineNo() - 1; i < lastLine; i++) {
if (contents.lineIsBlank(i) || contents.lineIsComment(i)) {
length--;
}
}
}
final int length = getLengthOfBlock(openingBrace, closingBrace);
if (length > max) {
log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY,
length, max);
@ -113,6 +102,27 @@ public class MethodLengthCheck extends Check {
}
}
/**
* Returns length of code only without comments and blank lines.
* @param openingBrace block opening brace
* @param closingBrace block closing brace
* @return number of lines with code for current block
*/
private int getLengthOfBlock(DetailAST openingBrace, DetailAST closingBrace) {
int length = closingBrace.getLineNo() - openingBrace.getLineNo() + 1;
if (!countEmpty) {
final FileContents contents = getFileContents();
final int lastLine = closingBrace.getLineNo();
for (int i = openingBrace.getLineNo() - 1; i < lastLine; i++) {
if (contents.lineIsBlank(i) || contents.lineIsComment(i)) {
length--;
}
}
}
return length;
}
/**
* @param length the maximum length of a method.
*/