Checks the padding of an empty for initializer; that is whether white space is required at an empty for initializer, or such white space is forbidden. No check occurs if there is a line wrap at the initializer, as in
name | description | type | default value |
---|---|---|---|
option | policy on how to pad an empty for iterator | pad policy | nospace |
To configure the check:
To configure the check to require white space at an empty for iterator:
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.whitespace
Checks the padding of an empty for iterator; that is whether white space is required at an empty for iterator, or such white space is forbidden. No check occurs if there is a line wrap at the iterator, as in
name | description | type | default value |
---|---|---|---|
option | policy on how to pad an empty for iterator | pad policy | nospace |
To configure the check:
To configure the check to require white space at an empty for iterator:
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.whitespace
Checks for empty line separators after header, package, all import declarations, fields, constructors, methods, nested classes, static initializers and instance initializers.
ATTENTION: empty line separator is required between AST siblings, not after line where token is found.
name | description | type | default value |
---|---|---|---|
allowNoEmptyLineBetweenFields | Allow no empty line between fields | Boolean | false |
allowMultipleEmptyLines | Allow multiple empty lines between class members | Boolean | true |
allowMultipleEmptyLinesInsideClassMembers | Allow multiple empty lines inside class members | Boolean | true |
tokens | tokens to check | subset of tokens PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF. | PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF. |
Example of declarations without empty line separator:
An example of how to configure the check with default parameters is:
Example of declarations with empty line separator that is expected by the Check by default:
An example how to check empty line after VARIABLE_DEF and METHOD_DEF:
An example how to allow no empty line between fields:
An example how to disallow multiple empty lines inside constructor, initialization block and method:
The check is valid only for statements that have body: CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF,
Example of declarations with multiple empty lines inside method:
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.whitespace
Checks that there are no tab characters ('\t'
) in the source code.
Rationale:
name | description | type | default value |
---|---|---|---|
eachLine | whether to report on each line containing a tab, or just the first instance | Boolean | false |
fileExtensions | file type extension of files to process | String Set | {} |
To configure the check to report on the first instance in each file:
To configure the check to report on each line in each file:
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.whitespace
Checks that the whitespace around the Generic tokens (angle brackets) "<" and ">" are correct to the typical convention. The convention is not configurable.
Left angle bracket ("<"):
Right angle bracket (">"):
Examples with correct spacing:
To configure the check:
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.whitespace
Checks the padding between the identifier of a method definition,
constructor definition, method call, or constructor invocation; and
the left parenthesis of the parameter list. That is, if the
identifier and left parenthesis are on the same line, checks whether
a space is required immediately after the identifier or such a space
is forbidden. If they are not on the same line, reports an error,
unless configured to allow line breaks. To allow linebreaks after
the identifier, set property allowLineBreaks
to
true
.
name | description | type | default value |
---|---|---|---|
allowLineBreaks | whether a line break between the identifier and left parenthesis is allowed | Boolean | false |
option | policy on how to pad method parameter | pad policy | nospace |
tokens | tokens to check | subset of tokens CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, SUPER_CTOR_CALL, ENUM_CONSTANT_DEF. | CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, SUPER_CTOR_CALL, ENUM_CONSTANT_DEF. |
To configure the check:
To configure the check to require a space after the identifier of a method definition, except if the left parenthesis occurs on a new line:
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.whitespace
Checks that chosen statements are not line-wrapped. By default this Check restricts wrapping import and package statements, but it's possible to check any statement.
name | description | type | default value |
---|---|---|---|
tokens | tokens to check | subset of tokens IMPORT, STATIC_IMPORT, PACKAGE_DEF, CLASS_DEF, METHOD_DEF, CTOR_DEF, ENUM_DEF, INTERFACE_DEF. | PACKAGE_DEF, IMPORT, STATIC_IMPORT. |
Examples of line-wrapped statements (bad case):
To configure the check to force no line-wrapping in package and import statements (default values):
To configure the check to force no line-wrapping only in import statements:
Examples of not line-wrapped statements (good case):
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.whitespace
Checks that there is no whitespace after a token. More specifically,
it checks that it is not followed by whitespace, or (if linebreaks
are allowed) all characters on the line after are whitespace. To
forbid linebreaks after a token, set property allowLineBreaks
to
false
.
The check processes ARRAY_DECLARATOR and INDEX_OP tokens specially from other tokens. Actually it is checked that there is no whitespace before this tokens, not after them.
name | description | type | default value |
---|---|---|---|
allowLineBreaks | whether whitespace is allowed if the token is at a linebreak | Boolean | true |
tokens | tokens to check | subset of tokens ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, TYPECAST, ARRAY_DECLARATOR, INDEX_OP, LITERAL_SYNCHRONIZED. | ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP. |
To configure the check:
To configure the check to forbid linebreaks after a DOT token:
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.whitespace
Checks that there is no whitespace before a token. More
specifically, it checks that it is not preceded with whitespace, or
(if linebreaks are allowed) all characters on the line before are
whitespace. To allow linebreaks before a token, set property allowLineBreaks
to
true
.
name | description | type | default value |
---|---|---|---|
allowLineBreaks | whether whitespace is allowed if the token is at a linebreak | Boolean | false |
tokens | tokens to check | subset of tokens COMMA, SEMI, POST_INC, POST_DEC, DOT, GENERIC_START, GENERIC_END, ELLIPSIS, METHOD_REF. | COMMA, SEMI, POST_INC, POST_DEC, ELLIPSIS. |
To configure the check:
To configure the check to allow linebreaks before a DOT token:
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.whitespace
Checks the policy on how to wrap lines on operators.
name | description | type | default value |
---|---|---|---|
option | policy on how to wrap lines | wrap operator policy | nl |
tokens | tokens to check | subset of tokens QUESTION, COLON, EQUAL, NOT_EQUAL, DIV, PLUS, MINUS, STAR, MOD, SR, BSR, GE, GT, SL, LE, LT, BXOR, BOR, LOR, BAND, LAND, LITERAL_INSTANCEOF, TYPE_EXTENSION_AND, ASSIGN, DIV_ASSIGN, PLUS_ASSIGN, MINUS_ASSIGN, STAR_ASSIGN, MOD_ASSIGN, SR_ASSIGN, BSR_ASSIGN, SL_ASSIGN, BXOR_ASSIGN, BOR_ASSIGN, BAND_ASSIGN, METHOD_REF. | QUESTION, COLON, EQUAL, NOT_EQUAL, DIV, PLUS, MINUS, STAR, MOD, SR, BSR, GE, GT, SL, LE, LT, BXOR, BOR, LOR, BAND, LAND, TYPE_EXTENSION_AND, LITERAL_INSTANCEOF. |
To configure the check:
To configure the check for the assignment operator, =
, at the end of a line:
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.whitespace
Checks the policy on the padding of parentheses; i.e. whether a space is required after a left parenthesis and before a right parenthesis, or such spaces are forbidden, with the exception that it does not check for padding of the right parenthesis at an empty for iterator and empty for initializer. Use Check EmptyForIteratorPad to validate empty for iterators and EmptyForInitializerPad to validate empty for initializers. Typecasts are also not checked, as there is TypecastParenPad to validate them.
name | description | type | default value |
---|---|---|---|
option | policy on how to pad parentheses | pad policy | nospace |
tokens | tokens to check | subset of tokens ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA. | ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA. |
To configure the check:
To configure the check to require spaces for the parentheses of constructor, method, and super constructor calls:
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.whitespace
Checks line wrapping with separators.
name | description | type | default value |
---|---|---|---|
option | policy on how to wrap lines | wrap operator policy | eol |
tokens | tokens to check | subset of tokens DOT, COMMA, SEMI, ELLIPSIS, AT, LPAREN, RPAREN, ARRAY_DECLARATOR, RBRACK, METHOD_REF. | DOT, COMMA. |
Code example for comma and dot at the new line:
An example of how to configure the check is:
Code example for comma and dot at the previous line:
Example for checking method reference at new line (good case and bad case):
An example of how to configure the check for METHOD_REF at new line:
An example of how to configure the check for comma at the new line is:
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.whitespace
Checks that non-whitespace characters are separated by no more than one whitespace. Separating characters by tabs or multiple spaces will be reported. Currently the check doesn't permit horizontal alignment. To inspect whitespaces before and after comments, set the property validateComments to true.
Setting validateComments to false will ignore cases like:
Sometimes, users like to space similar items on different lines to the same column position for easier reading. This feature isn't supported by this check, so both braces in the following case will be reported as violations.
name | description | type | default value |
---|---|---|---|
validateComments | If set to true, whitespaces surrounding comments will be ignored. | Boolean | false |
To configure the check:
To configure the check so that it validates comments:
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.whitespace
Checks the policy on the padding of parentheses for typecasts. That is, whether a space is required after a left parenthesis and before a right parenthesis, or such spaces are forbidden.
name | description | type | default value |
---|---|---|---|
option | policy on how to pad parentheses | pad policy | nospace |
To configure the check:
To configure the check to require spaces:
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.whitespace
Checks that a token is followed by whitespace.
name | description | type | default value |
---|---|---|---|
tokens | tokens to check | subset of tokens COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE. | COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE. |
To configure the check:
To configure the check for whitespace only after COMMA and SEMI tokens:
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.whitespace
Checks that a token is surrounded by whitespace. Empty constructor, method, class, enum, interface, loop bodies (blocks), lambdas of the form
may optionally be exempted from the policy using the
allowEmptyMethods
, allowEmptyConstructors
, allowEmptyTypes
, allowEmptyLoops
allowEmptyLambdas
and allowEmptyCatches
properties.
This check does not flag as violation double brace initialization like:
new Properties() {{
setProperty("key", "value");
}};
Parameter allowEmptyCatches allows to suppress violations when token list contains SLIST to check if beginning of block is surrounded by whitespace and catch block is empty, for example:
try {
k = 5 / i;
} catch (ArithmeticException ex) {}
With this property turned off, this raises violation because the beginning of the
catch block (left curly bracket) is not separated from the end of the catch
block (right curly bracket).
To configure the check:
To configure the check for whitespace around the assignment
operator, =
:
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.whitespace