WhitespaceAfterCheck updated to follow Cyclomatic Complexity rule. #954

This commit is contained in:
Roman Ivanov 2015-06-15 20:23:02 -07:00
parent 6475d9dc1b
commit 43e856a0df
2 changed files with 25 additions and 15 deletions

View File

@ -914,7 +914,7 @@
<regex><pattern>.*.checks.whitespace.ParenPadCheck</pattern><branchRate>86</branchRate><lineRate>95</lineRate></regex>
<regex><pattern>.*.checks.whitespace.SeparatorWrapCheck</pattern><branchRate>100</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.checks.whitespace.TypecastParenPadCheck</pattern><branchRate>87</branchRate><lineRate>88</lineRate></regex>
<regex><pattern>.*.checks.whitespace.WhitespaceAfterCheck</pattern><branchRate>90</branchRate><lineRate>90</lineRate></regex>
<regex><pattern>.*.checks.whitespace.WhitespaceAfterCheck</pattern><branchRate>86</branchRate><lineRate>90</lineRate></regex>
<regex><pattern>.*.checks.whitespace.WhitespaceAroundCheck</pattern><branchRate>96</branchRate><lineRate>98</lineRate></regex>

View File

@ -102,22 +102,32 @@ public class WhitespaceAfterCheck
&& (charAfter == ';' || charAfter == ')')) {
return;
}
if (!Character.isWhitespace(charAfter)) {
//empty FOR_ITERATOR?
if (targetAST.getType() == TokenTypes.SEMI) {
final DetailAST sibling =
targetAST.getNextSibling();
if (sibling != null
&& sibling.getType() == TokenTypes.FOR_ITERATOR
&& sibling.getChildCount() == 0) {
return;
}
}
if (!Character.isWhitespace(charAfter) && !isEmptyForIterator(targetAST)) {
log(targetAST.getLineNo(),
targetAST.getColumnNo() + targetAST.getText().length(),
WS_NOT_FOLLOWED,
message);
targetAST.getColumnNo() + targetAST.getText().length(),
WS_NOT_FOLLOWED,
message);
}
}
}
/**
* check for empty FOR_ITERATOR
* @param targetAST Ast token
* @return true if iterator is empty
*/
private boolean isEmptyForIterator(DetailAST targetAST) {
if (targetAST.getType() == TokenTypes.SEMI) {
final DetailAST sibling =
targetAST.getNextSibling();
if (sibling != null
&& sibling.getType() == TokenTypes.FOR_ITERATOR
&& sibling.getChildCount() == 0) {
return true;
}
}
return false;
}
}