TypeBodyPadding
Since Checkstyle 13.9.0
Description
A blank line (padding) line is a line containing only whitespace characters.
Properties
| name | description | type | default value | since |
|---|---|---|---|---|
| allowEmpty | Allow empty type bodies to omit blank line padding. | boolean | true |
13.9.0 |
| atEndOfBody | Require a blank line before the type body closing brace. | boolean | true |
13.9.0 |
| atStartOfBody | Require a blank line after the type body opening brace. | boolean | true |
13.9.0 |
| skipInner | Control whether to skip checking of inner types. | boolean | true |
13.9.0 |
| skipLocal | Control whether to skip checking of local types. | boolean | true |
13.9.0 |
| tokens | tokens to check | subset of tokens CLASS_DEF , INTERFACE_DEF , ENUM_DEF , RECORD_DEF , ANNOTATION_DEF . | CLASS_DEF , INTERFACE_DEF , ENUM_DEF , RECORD_DEF , ANNOTATION_DEF . | 13.9.0 |
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding"/>
</module>
</module>
Example:
// violation below 'Blank line required after the opening brace of type definition.'
class Example1 {
int x;
} // violation 'Blank line required before the closing brace of type definition.'
class Example1b {
int x;
}
interface Empty1a {
}
interface Empty1b {
}
class InnerParent1 {
class Inner1 {
int y;
}
}
class LocalParent1 {
void method() {
class Local1 {
int z;
}
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum1 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
To configure the check to require blank lines even for empty type bodies:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="allowEmpty" value="false"/>
</module>
</module>
</module>
Example:
// violation below 'Blank line required after the opening brace of type definition.'
class Example2 {
int x;
} // violation 'Blank line required before the closing brace of type definition.'
class Example2b {
int x;
}
// violation below 'Blank line required after the opening brace of type definition.'
interface Empty2a {
} // violation 'Blank line required before the closing brace of type definition.'
interface Empty2b {
}
class InnerParent2 {
class Inner2 {
int y;
}
}
class LocalParent2 {
void method() {
class Local2 {
int z;
}
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum2 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
To configure the check to not require a blank line after the opening brace:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="atStartOfBody" value="false"/>
</module>
</module>
</module>
Example:
class Example3 {
int x;
} // violation 'Blank line required before the closing brace of type definition.'
class Example3b {
int x;
}
interface Empty3a {
}
interface Empty3b {
}
class InnerParent3 {
class Inner3 {
int y;
}
}
class LocalParent3 {
void method() {
class Local3 {
int z;
}
}
}
enum MyEnum3 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
To configure the check to not require a blank line before the closing brace:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="atEndOfBody" value="false"/>
</module>
</module>
</module>
Example:
// violation below 'Blank line required after the opening brace of type definition.'
class Example4 {
int x;
}
class Example4b {
int x;
}
interface Empty4a {
}
interface Empty4b {
}
class InnerParent4 {
class Inner4 {
int y;
}
}
class LocalParent4 {
void method() {
class Local4 {
int z;
}
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum4 {
VALUE;
}
To configure the check to require blank lines for inner classes too:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="skipInner" value="false"/>
</module>
</module>
</module>
Example:
// violation below 'Blank line required after the opening brace of type definition.'
class Example5 {
int x;
} // violation 'Blank line required before the closing brace of type definition.'
class Example5b {
int x;
}
interface Empty5a {
}
interface Empty5b {
}
class InnerParent5 {
// violation 2 lines below 'Blank line required after the opening brace of type'
// 'definition.'
class Inner5 {
int y;
} // violation 'Blank line required before the closing brace of type definition.'
}
class LocalParent5 {
void method() {
class Local5 {
int z;
}
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum5 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
To configure the check to require blank lines for local classes too:
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="skipLocal" value="false"/>
</module>
</module>
</module>
Example:
// violation below 'Blank line required after the opening brace of type definition.'
class Example6 {
int x;
} // violation 'Blank line required before the closing brace of type definition.'
class Example6b {
int x;
}
interface Empty6a {
}
interface Empty6b {
}
class InnerParent6 {
class Inner6 {
int y;
}
}
class LocalParent6 {
void method() {
// violation 2 lines below 'Blank line required after the opening brace of type'
// 'definition.'
class Local6 {
int z;
} // violation 'Blank line required before the closing brace of type definition.'
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum6 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
To configure the check to only run on interfaces, enums, annotations, and records (bypassing classes):
<module name="Checker">
<module name="TreeWalker">
<module name="TypeBodyPadding">
<property name="tokens"
value="INTERFACE_DEF, RECORD_DEF, ENUM_DEF, ANNOTATION_DEF"/>
</module>
</module>
</module>
Example:
class Example7 {
int x;
}
class Example7b {
int x;
}
interface Empty7a {
}
interface Empty7b {
}
class InnerParent7 {
class Inner7 {
int y;
}
}
class LocalParent7 {
void method() {
class Local7 {
int z;
}
}
}
// violation below 'Blank line required after the opening brace of type definition.'
enum MyEnum7 {
VALUE;
} // violation 'Blank line required before the closing brace of type definition.'
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.TypeBodyPaddingCheck
Use this fully qualified class name in configuration when an exact class reference is required.






