TypeBodyPadding

Since Checkstyle 11.1

Description

Checks the padding policy for type bodies. Ensures that a blank line is present immediately after the opening brace and/or immediately before the closing brace of type definitions (class, interface, enum, record, and annotation types). Optionally, inner type definitions can be ignored via the skipInner property.

Properties

name description type default value since
allowEmpty Control whether to allow empty type bodies without padding. boolean true 11.1.0
ending Control whether padding is required at the end of the body. boolean false 11.1.0
skipInner Control whether to skip checking of inner types. boolean true 11.1.0
starting Control whether padding is required at the start of the body. boolean true 11.1.0
tokens tokens to check subset of tokens ANNOTATION_DEF , CLASS_DEF , ENUM_DEF , INTERFACE_DEF , RECORD_DEF . ANNOTATION_DEF , CLASS_DEF , ENUM_DEF , INTERFACE_DEF , RECORD_DEF . 11.1.0

Examples

Example:


public class Example1 {
  int a = 0; // violation 'A blank line is required after the opening'
}

To configure the check to require a blank line after the opening brace and before the closing brace:


<module name="Checker">
  <module name="TreeWalker">
    <module name="TypeBodyPadding">
      <property name="ending" value="true"/>
    </module>
  </module>
</module>

Example:


public class Example2 {
  int a = 0; // violation 'A blank line is required after the opening'
} // violation 'A blank line is required before the closing'

To configure the check to only require a blank line before the closing brace:


<module name="Checker">
  <module name="TreeWalker">
    <module name="TypeBodyPadding">
        <property name="starting" value="false"/>
        <property name="ending" value="true"/>
    </module>
  </module>
</module>

Example:


public class Example3 {
  int a = 0;
} // violation 'A blank line is required before the closing'

To configure the check to not allow empty type bodies without padding:


<module name="Checker">
  <module name="TreeWalker">
    <module name="TypeBodyPadding">
      <property name="allowEmpty" value="false"/>
    </module>
  </module>
</module>

Example:


public class Example5 { // violation 'A blank line is required after the opening'
}

To configure the check to not skip inner types:


<module name="Checker">
  <module name="TreeWalker">
    <module name="TypeBodyPadding">
      <property name="skipInner" value="false"/>
    </module>
  </module>
</module>

Example:


public class Example6 {
  int a = 0; // violation 'A blank line is required after the opening'
  static class Inner {
    int b = 0; // violation 'A blank line is required after the opening'
  }
}

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.

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker