EmptyLineWrappingInBlock
Since Checkstyle 14.4.0
Description
topSeparator controls the line after the opening brace and bottomSeparator controls the line before the closing brace. Both accept the following values:
empty_line- exactly one empty line is required;empty_line_allowed- not validated, an empty line may be present or absent;no_empty_line- an empty line is forbidden.
Properties
| name | description | type | default value | since |
|---|---|---|---|---|
| bottomSeparator | Specify the policy for the empty line before the closing brace. | SeparatorOption | empty_line |
14.4.0 |
| topSeparator | Specify the policy for the empty line after the opening brace. | SeparatorOption | empty_line |
14.4.0 |
| tokens | tokens to check | subset of tokens ANNOTATION_ARRAY_INIT , ANNOTATION_DEF , ARRAY_INIT , CASE_GROUP , CLASS_DEF , CTOR_DEF , ENUM_CONSTANT_DEF , ENUM_DEF , INSTANCE_INIT , INTERFACE_DEF , LAMBDA , LITERAL_CASE , LITERAL_CATCH , LITERAL_DEFAULT , LITERAL_DO , LITERAL_ELSE , LITERAL_FINALLY , LITERAL_FOR , LITERAL_IF , LITERAL_NEW , LITERAL_SWITCH , LITERAL_SYNCHRONIZED , LITERAL_TRY , LITERAL_WHILE , METHOD_DEF , SLIST , STATIC_INIT . | CLASS_DEF , INTERFACE_DEF , ANNOTATION_DEF , ENUM_DEF , ENUM_CONSTANT_DEF . | 14.4.0 |
Examples
To configure the check with default, both separators required:
<module name="Checker">
<module name="TreeWalker">
<module name="EmptyLineWrappingInBlock"/>
</module>
</module>
Example:
class Example1 { // violation ''{' must have exactly one empty line after.'
private int field;
void method() {
int local = 1;
}
} // violation ''}' must have exactly one empty line before.'
To configure the check with top empty line required, bottom not validated:
<module name="Checker">
<module name="TreeWalker">
<module name="EmptyLineWrappingInBlock">
<property name="topSeparator" value="empty_line"/>
<property name="bottomSeparator" value="empty_line_allowed"/>
</module>
</module>
</module>
Example:
class Example2 { // violation ''{' must have exactly one empty line after.'
private int field;
void method() {
int local = 1;
}
}
To configure the check with top not validated, bottom empty line required:
<module name="Checker">
<module name="TreeWalker">
<module name="EmptyLineWrappingInBlock">
<property name="topSeparator" value="empty_line_allowed"/>
<property name="bottomSeparator" value="empty_line"/>
</module>
</module>
</module>
Example:
class Example3 {
private int field;
void method() {
int local = 1;
}
} // violation ''}' must have exactly one empty line before.'
To configure the check for method bodies only, top not validated, bottom empty line forbidden:
<module name="Checker">
<module name="TreeWalker">
<module name="EmptyLineWrappingInBlock">
<property name="tokens" value="METHOD_DEF"/>
<property name="topSeparator" value="empty_line_allowed"/>
<property name="bottomSeparator" value="no_empty_line"/>
</module>
</module>
</module>
Example:
class Example4 {
private int field;
void method() {
int local = 1;
} // violation ''}' can not have empty line before.'
}
Example of Usage
Violation Messages
- empty.line.wrapping.bottom.no
- empty.line.wrapping.bottom.one
- empty.line.wrapping.top.no
- empty.line.wrapping.top.one
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Fully Qualified Name
com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineWrappingInBlockCheck
Use this fully qualified class name in configuration when an exact class reference is required.






