Since Checkstyle 3.0
'{'
) for code blocks.
name | description | type | default value | since |
---|---|---|---|---|
ignoreEnums | Allow to ignore enums when left curly brace policy is EOL. | boolean | true |
6.9 |
option | Specify the policy on placement of a left curly brace ('{' ). |
LeftCurlyOption | eol |
3.0 |
tokens | tokens to check | subset of tokens ANNOTATION_DEF , CLASS_DEF , CTOR_DEF , ENUM_CONSTANT_DEF , ENUM_DEF , INTERFACE_DEF , LAMBDA , LITERAL_CASE , LITERAL_CATCH , LITERAL_DEFAULT , LITERAL_DO , LITERAL_ELSE , LITERAL_FINALLY , LITERAL_FOR , LITERAL_IF , LITERAL_SWITCH , LITERAL_SYNCHRONIZED , LITERAL_TRY , LITERAL_WHILE , METHOD_DEF , OBJBLOCK , STATIC_INIT , RECORD_DEF , COMPACT_CTOR_DEF . | ANNOTATION_DEF , CLASS_DEF , CTOR_DEF , ENUM_CONSTANT_DEF , ENUM_DEF , INTERFACE_DEF , LAMBDA , LITERAL_CASE , LITERAL_CATCH , LITERAL_DEFAULT , LITERAL_DO , LITERAL_ELSE , LITERAL_FINALLY , LITERAL_FOR , LITERAL_IF , LITERAL_SWITCH , LITERAL_SYNCHRONIZED , LITERAL_TRY , LITERAL_WHILE , METHOD_DEF , OBJBLOCK , STATIC_INIT , RECORD_DEF , COMPACT_CTOR_DEF . | 3.0 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="LeftCurly"/> </module> </module>
Example:
class Example1 { // violation, ''{' at column 1 should be on the previous line.' private interface TestInterface { // violation, ''{' at column 3 should be on the previous line.' } private class MyClass { // OK } enum Colors {RED, // OK BLUE, GREEN; } }
To configure the check to apply the nl
policy to
type blocks:
<module name="Checker"> <module name="TreeWalker"> <module name="LeftCurly"> <property name="option" value="nl"/> <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/> </module> </module> </module>
Example:
class Example2 { // OK private interface TestInterface { // OK } private class MyClass { // violation, ''{' at column 13 should be on a new line.' } enum Colors {RED, // OK BLUE, GREEN; } }
To configure the check to apply the nlow
policy to
type blocks:
<module name="Checker"> <module name="TreeWalker"> <module name="LeftCurly"> <property name="option" value="nlow"/> <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/> </module> </module> </module>
Example:
class Example3 { // violation, ''{' at column 1 should be on the previous line.' private interface TestInterface { // OK } private class MyClass { // violation, ''{' at column 13 should be on a new line.' } enum Colors {RED, // OK BLUE, GREEN; } }
An example of how to configure the check to validate enum definitions:
<module name="Checker"> <module name="TreeWalker"> <module name="LeftCurly"> <property name="ignoreEnums" value="false"/> </module> </module> </module>
Example:
class Example4 { // violation, ''{' at column 1 should be on the previous line.' private interface TestInterface { // violation, ''{' at column 3 should be on the previous line.' } private class MyClass { // OK } enum Colors {RED, // violation, ''{' at column 15 should have line break after.' BLUE, GREEN; } }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.blocks