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:
None.
To configure the check:
com.puppycrawl.tools.checkstyle.checks.whitespace
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:
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:
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 | CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, SUPER_CTOR_CALL |
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:
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.
| 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, BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, TYPECAST ARRAY_DECLARATOR | ARRAY_INIT, BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS ARRAY_DECLARATOR |
To configure the check:
To configure the check to forbid linebreaks after a DOT token:
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 SEMI, DOT, POST_DEC, POST_INC | SEMI, POST_DEC, POST_INC |
To configure the check:
To configure the check to allow linebreaks before a DOT token:
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 ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN | BAND, BOR, BSR, BXOR, COLON, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR (all tokens except assignment operators) |
To configure the check:
To configure the check for the assignment operator, =, at the end of a line:
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.
| name | description | type | default value |
|---|---|---|---|
| option | policy on how to pad parentheses | pad policy | nospace |
| tokens | tokens to check | subset of tokens CTOR_CALL, LPAREN, METHOD_CALL, RPAREN, SUPER_CTOR_CALL | CTOR_CALL, LPAREN, METHOD_CALL, RPAREN, SUPER_CTOR_CALL |
To configure the check:
To configure the check to require spaces for the parentheses of constructor, method, and super constructor calls:
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 |
| tokens | tokens to check | Must have tokens TYPECAST, RPAREN | TYPECAST, RPAREN |
To configure the check:
To configure the check to require spaces:
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:
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 | COMMA, SEMI, TYPECAST |
To configure the check:
To configure the check for whitespace only after COMMA and SEMI tokens:
com.puppycrawl.tools.checkstyle.checks.whitespace
Checks that a token is surrounded by whitespace. Empty constructor, method, class, enum, interface, loop bodies (blocks) of the form
may optionally be exempted from the policy using the
allowEmptyMethods, allowEmptyConstructors
, allowEmptyTypes and allowEmptyLoops properties.
| name | description | type | default value |
|---|---|---|---|
| tokens | tokens to check | subset of tokens ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND | all tokens |
| allowEmptyConstructors | allow empty constructor bodies | boolean | false |
| allowEmptyMethods | allow empty method bodies | boolean | false |
| allowEmptyTypes | allow empty class, interface and enum bodies | boolean | false |
| allowEmptyLoops | allow empty loop bodies | boolean | false |
| ignoreEnhancedForColon | ignore whitespace around colon in for-each loops | boolean | true |
To configure the check:
To configure the check for whitespace around the assignment
operator, =:
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 | assignments to check | subset of tokens PACKAGE_DEF, IMPORT, CLASS_DEF, ENUM_DEF INTERFACE_DEF, CTOR_DEF, METHOD_DEF, | PACKAGE_DEF, 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):
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.
| name | description | type | default value |
|---|---|---|---|
| tokens | assignments to check | subset of tokens PACKAGE_DEF, IMPORT, CLASS_DEF, ENUM_DEF INTERFACE_DEF, CTOR_DEF, METHOD_DEF, STATIC_INIT, INSTANCE_INIT, VARIABLE_DEF | All subset of tokens |
| allowNoEmptyLineBetweenFields | Allow no empty line between fields | boolean | false |
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:
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 | 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:
An example of how to configure the check for comma at the new line is:
com.puppycrawl.tools.checkstyle.checks.whitespace