WhitespaceAfterCheck updated to follow Cyclomatic Complexity rule. #954
This commit is contained in:
parent
6475d9dc1b
commit
43e856a0df
2
pom.xml
2
pom.xml
|
|
@ -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>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue