Coverage has been increased to 100% in EmptyBlockCheck. Issue #1291
This commit is contained in:
parent
eb29e863de
commit
b219e2ff88
1
pom.xml
1
pom.xml
|
|
@ -1102,7 +1102,6 @@
|
|||
<regex><pattern>.*.checks.UniquePropertiesCheck\$.*</pattern><branchRate>75</branchRate><lineRate>90</lineRate></regex>
|
||||
|
||||
|
||||
<regex><pattern>.*.checks.blocks.EmptyBlockCheck</pattern><branchRate>88</branchRate><lineRate>100</lineRate></regex>
|
||||
<regex><pattern>.*.checks.blocks.LeftCurlyCheck</pattern><branchRate>89</branchRate><lineRate>96</lineRate></regex>
|
||||
<regex><pattern>.*.checks.blocks.RightCurlyCheck</pattern><branchRate>88</branchRate><lineRate>95</lineRate></regex>
|
||||
|
||||
|
|
|
|||
|
|
@ -141,8 +141,7 @@ public class EmptyBlockCheck
|
|||
ast.getText());
|
||||
}
|
||||
}
|
||||
else if (getAbstractOption() == BlockOption.TEXT
|
||||
&& !hasText(leftCurly)) {
|
||||
else if (!hasText(leftCurly)) {
|
||||
log(leftCurly.getLineNo(),
|
||||
leftCurly.getColumnNo(),
|
||||
MSG_KEY_BLOCK_EMPTY,
|
||||
|
|
@ -161,35 +160,33 @@ public class EmptyBlockCheck
|
|||
final DetailAST rightCurly = slistAST.findFirstToken(TokenTypes.RCURLY);
|
||||
final DetailAST rcurlyAST = rightCurly != null
|
||||
? rightCurly : slistAST.getParent().findFirstToken(TokenTypes.RCURLY);
|
||||
if (rcurlyAST != null) {
|
||||
final int slistLineNo = slistAST.getLineNo();
|
||||
final int slistColNo = slistAST.getColumnNo();
|
||||
final int rcurlyLineNo = rcurlyAST.getLineNo();
|
||||
final int rcurlyColNo = rcurlyAST.getColumnNo();
|
||||
final String[] lines = getLines();
|
||||
if (slistLineNo == rcurlyLineNo) {
|
||||
// Handle braces on the same line
|
||||
final String txt = lines[slistLineNo - 1]
|
||||
final int slistLineNo = slistAST.getLineNo();
|
||||
final int slistColNo = slistAST.getColumnNo();
|
||||
final int rcurlyLineNo = rcurlyAST.getLineNo();
|
||||
final int rcurlyColNo = rcurlyAST.getColumnNo();
|
||||
final String[] lines = getLines();
|
||||
if (slistLineNo == rcurlyLineNo) {
|
||||
// Handle braces on the same line
|
||||
final String txt = lines[slistLineNo - 1]
|
||||
.substring(slistColNo + 1, rcurlyColNo);
|
||||
if (StringUtils.isNotBlank(txt)) {
|
||||
retVal = true;
|
||||
}
|
||||
if (StringUtils.isNotBlank(txt)) {
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check only whitespace of first & last lines
|
||||
if (lines[slistLineNo - 1]
|
||||
.substring(slistColNo + 1).trim().length() != 0
|
||||
|| lines[rcurlyLineNo - 1]
|
||||
.substring(0, rcurlyColNo).trim().length() != 0) {
|
||||
retVal = true;
|
||||
}
|
||||
else {
|
||||
// check only whitespace of first & last lines
|
||||
if (lines[slistLineNo - 1]
|
||||
.substring(slistColNo + 1).trim().length() != 0
|
||||
|| lines[rcurlyLineNo - 1]
|
||||
.substring(0, rcurlyColNo).trim().length() != 0) {
|
||||
retVal = true;
|
||||
}
|
||||
else {
|
||||
// check if all lines are also only whitespace
|
||||
for (int i = slistLineNo; i < rcurlyLineNo - 1; i++) {
|
||||
if (lines[i].trim().length() > 0) {
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
// check if all lines are also only whitespace
|
||||
for (int i = slistLineNo; i < rcurlyLineNo - 1; i++) {
|
||||
if (lines[i].trim().length() > 0) {
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class EmptyBlockCheckTest
|
|||
"178:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"206:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"208:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"219:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
};
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
|
@ -57,6 +58,7 @@ public class EmptyBlockCheckTest
|
|||
"77:17: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "finally"),
|
||||
"178:5: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "INSTANCE_INIT"),
|
||||
"206:29: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "synchronized"),
|
||||
"219:12: " + getCheckMessage(MSG_KEY_BLOCK_EMPTY, "STATIC_INIT"),
|
||||
};
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
|
@ -75,6 +77,7 @@ public class EmptyBlockCheckTest
|
|||
"178:5: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"206:29: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"208:41: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
"219:12: " + getCheckMessage(MSG_KEY_BLOCK_NO_STMT),
|
||||
};
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,4 +210,13 @@ class InputSemantic
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
|
||||
int a = 0;}
|
||||
|
||||
static {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue