EmptyLineWrappingInBlock

Since Checkstyle 14.4.0

Description

Checks the empty line right after the opening brace and right before the closing brace of a block.

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

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

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.

Parent Module

TreeWalker