Add setter for 'ignoreEnums' in LeftCurlyCheck, issue #975.

This commit is contained in:
Andrei Selkin 2015-07-23 21:04:36 +03:00
parent 07d2c790d8
commit cdcddbe49e
5 changed files with 45 additions and 2 deletions

View File

@ -1113,7 +1113,7 @@
<regex><pattern>.*.checks.blocks.EmptyBlockCheck</pattern><branchRate>88</branchRate><lineRate>100</lineRate></regex>
<regex><pattern>.*.checks.blocks.LeftCurlyCheck</pattern><branchRate>87</branchRate><lineRate>94</lineRate></regex>
<regex><pattern>.*.checks.blocks.LeftCurlyCheck</pattern><branchRate>89</branchRate><lineRate>96</lineRate></regex>
<regex><pattern>.*.checks.blocks.NeedBracesCheck</pattern><branchRate>80</branchRate><lineRate>97</lineRate></regex>
<regex><pattern>.*.checks.blocks.RightCurlyCheck</pattern><branchRate>88</branchRate><lineRate>95</lineRate></regex>

View File

@ -118,6 +118,14 @@ public class LeftCurlyCheck
this.maxLineLength = maxLineLength;
}
/**
* Sets whether check should ignore enums when left curly brace policy is EOL.
* @param ignoreEnums check's option for ignoring enums.
*/
public void setIgnoreEnums(boolean ignoreEnums) {
this.ignoreEnums = ignoreEnums;
}
@Override
public int[] getDefaultTokens() {
return new int[] {

View File

@ -223,4 +223,23 @@ public class LeftCurlyCheckTest extends BaseCheckTestSupport {
};
verify(checkConfig, getPath("InputLeftCurlyLineBreakAfter.java"), expected);
}
@Test
public void testIgnoreEnumsOptionTrue() throws Exception {
checkConfig.addAttribute("option", LeftCurlyOption.EOL.toString());
checkConfig.addAttribute("ignoreEnums", "true");
final String[] expectedWhileTrue = {
};
verify(checkConfig, getPath("InputLeftCurlyEnums.java"), expectedWhileTrue);
}
@Test
public void testIgnoreEnumsOptionFalse() throws Exception {
checkConfig.addAttribute("option", LeftCurlyOption.EOL.toString());
checkConfig.addAttribute("ignoreEnums", "false");
final String[] expectedWhileFalse = {
"4:17: " + getCheckMessage(MSG_KEY_LINE_BREAK_AFTER, "{"),
};
verify(checkConfig, getPath("InputLeftCurlyEnums.java"), expectedWhileFalse);
}
}

View File

@ -0,0 +1,16 @@
package com.puppycrawl.tools.checkstyle;
public class InputLeftCurlyEnums {
enum Colors {RED,
BLUE,
GREEN
}
enum Languages {
JAVA,
PHP,
SCALA,
C,
PASCAL
}
}

View File

@ -250,7 +250,7 @@ try {
</tr>
<tr>
<td>ignoreEnums</td>
<td>If true, Check will ignore enums</td>
<td>If true, Check will ignore enums when left curly brace policy is EOL</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td>true</td>
</tr>