coverage has been increased to 100% in RughtCurlyCheck. Issue #1291
This commit is contained in:
parent
2282f82cb7
commit
f1dc9b205d
4
pom.xml
4
pom.xml
|
|
@ -1101,10 +1101,6 @@
|
|||
<regex><pattern>.*.checks.UncommentedMainCheck</pattern><branchRate>83</branchRate><lineRate>88</lineRate></regex>
|
||||
<regex><pattern>.*.checks.UniquePropertiesCheck\$.*</pattern><branchRate>75</branchRate><lineRate>90</lineRate></regex>
|
||||
|
||||
|
||||
<regex><pattern>.*.checks.blocks.RightCurlyCheck</pattern><branchRate>88</branchRate><lineRate>95</lineRate></regex>
|
||||
|
||||
|
||||
<regex><pattern>.*.checks.coding.AbstractIllegalMethodCheck</pattern><branchRate>100</branchRate><lineRate>93</lineRate></regex>
|
||||
<regex><pattern>.*.checks.coding.AbstractSuperCheck</pattern><branchRate>78</branchRate><lineRate>89</lineRate></regex>
|
||||
<regex><pattern>.*.checks.coding.DeclarationOrderCheck</pattern><branchRate>82</branchRate><lineRate>93</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -260,10 +260,12 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
|
|||
rcurly = lcurly.getLastChild();
|
||||
nextToken = ast;
|
||||
break;
|
||||
case TokenTypes.METHOD_DEF:
|
||||
case TokenTypes.LITERAL_FOR:
|
||||
case TokenTypes.LITERAL_WHILE:
|
||||
case TokenTypes.LITERAL_DO:
|
||||
default:
|
||||
// ATTENTION! We have default here, but we expect case TokenTypes.METHOD_DEF,
|
||||
// TokenTypes.LITERAL_FOR, TokenTypes.LITERAL_WHILE, TokenTypes.LITERAL_DO only.
|
||||
// It has been done to improve coverage to 100%. I couldn't replace it with
|
||||
// if-else-if block because code was ugly and didn't pass pmd check.
|
||||
|
||||
lcurly = ast.findFirstToken(TokenTypes.SLIST);
|
||||
if (lcurly != null) {
|
||||
// SLIST could be absent if method is abstract,
|
||||
|
|
@ -272,9 +274,6 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
|
|||
}
|
||||
nextToken = lcurly;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected token type ("
|
||||
+ Utils.getTokenName(ast.getType()) + ")");
|
||||
}
|
||||
|
||||
final Details details = new Details();
|
||||
|
|
@ -312,7 +311,7 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
|
|||
private static DetailAST getNextToken(DetailAST ast) {
|
||||
DetailAST next = null;
|
||||
DetailAST parent = ast;
|
||||
while (parent != null && next == null) {
|
||||
while (next == null) {
|
||||
next = parent.getNextSibling();
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
|
@ -325,14 +324,9 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption> {
|
|||
* @return true, if right curly has line break before.
|
||||
*/
|
||||
private static boolean hasLineBreakBefore(DetailAST rightCurly) {
|
||||
if (rightCurly != null) {
|
||||
final DetailAST previousToken = rightCurly.getPreviousSibling();
|
||||
if (previousToken != null
|
||||
&& rightCurly.getLineNo() == previousToken.getLineNo()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
final DetailAST previousToken = rightCurly.getPreviousSibling();
|
||||
return previousToken == null
|
||||
|| rightCurly.getLineNo() != previousToken.getLineNo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -154,4 +154,22 @@ public class RightCurlyCheckTest extends BaseCheckTestSupport {
|
|||
};
|
||||
verify(checkConfig, getPath("InputRightCurlyAnnotations.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCatchWithoutFinally() throws Exception {
|
||||
final String[] expected = {
|
||||
"15:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}"),
|
||||
};
|
||||
verify(checkConfig, getPath("InputRightCurly.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleLineClass() throws Exception {
|
||||
checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
|
||||
checkConfig.addAttribute("tokens", "CLASS_DEF");
|
||||
final String[] expected = {
|
||||
"24:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}"),
|
||||
};
|
||||
verify(checkConfig, getPath("InputRightCurly.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Test case file for checkstyle.
|
||||
// Created: 2001
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
class InputRightCurly
|
||||
{
|
||||
void foo() throws InterruptedException
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
class UniqEmptyClass {private int a;}
|
||||
Loading…
Reference in New Issue