GenericWhitespace

Description

Checks that the whitespace around the Generic tokens < and > is correct to the typical convention. The convention is not configurable.

For example the following is legal:

List<Integer> x = new ArrayList<Integer>();
List<List<Integer>> y = new ArrayList<List<Integer>>();
        

But the following example is not:

List < Integer > x = new ArrayList < Integer > ();
List < List < Integer > > y = new ArrayList < List < Integer > > ();
        

Properties

None.

Examples

To configure the check:

<module name="GenericWhitespace"/>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

EmptyForInitializerPad

Description

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

for (
      ; i < j; i++, j--)
        

Properties

name description type default value
option policy on how to pad an empty for iterator pad policy nospace

Examples

To configure the check:

<module name="EmptyForInitializerPad"/>
        

To configure the check to require white space at an empty for iterator:

<module name="EmptyForInitializerPad">
    <property name="option" value="space"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

EmptyForIteratorPad

Description

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

for (Iterator foo = very.long.line.iterator();
      foo.hasNext();
     )
        

Properties

name description type default value
option policy on how to pad an empty for iterator pad policy nospace

Examples

To configure the check:

<module name="EmptyForIteratorPad"/>
        

To configure the check to require white space at an empty for iterator:

<module name="EmptyForIteratorPad">
    <property name="option" value="space"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

MethodParamPad

Description

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.

Properties

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

Examples

To configure the check:

<module name="MethodParamPad"/>
        

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:

<module name="MethodParamPad">
    <property name="tokens" value="METHOD_DEF"/>
    <property name="option" value="space"/>
    <property name="allowLineBreaks" value="true"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

NoWhitespaceAfter

Description

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.

Properties

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_INIT, BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS

Examples

To configure the check:

<module name="NoWhitespaceAfter"/>
        

To configure the check to forbid linebreaks after a DOT token:

<module name="NoWhitespaceAfter">
    <property name="tokens" value="DOT"/>
    <property name="allowLineBreaks" value="false"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

NoWhitespaceBefore

Description

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.

Properties

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

Examples

To configure the check:

<module name="NoWhitespaceBefore"/>
        

To configure the check to allow linebreaks before a DOT token:

<module name="NoWhitespaceBefore">
    <property name="tokens" value="DOT"/>
    <property name="allowLineBreaks" value="true"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

OperatorWrap

Description

Checks the policy on how to wrap lines on operators.

Properties

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)

Examples

To configure the check:

<module name="OperatorWrap"/>
        

To configure the check for the assignment operator, =, at the end of a line:

<module name="OperatorWrap">
    <property name="tokens" value="ASSIGN"/>
    <property name="option" value="eol"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

ParenPad

Description

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.

Properties

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

Examples

To configure the check:

<module name="ParenPad"/>
        

To configure the check to require spaces for the parentheses of constructor, method, and super constructor calls:

<module name="ParenPad">
    <property name="tokens" value="CTOR_CALL, METHOD_CALL,
    SUPER_CTOR_CALL"/>
    <property name="option" value="space"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

TypecastParenPad

Description

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.

Properties

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

Examples

To configure the check:

<module name="TypecastParenPad"/>
        

To configure the check to require spaces:

<module name="TypecastParenPad">
    <property name="option" value="space"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

FileTabCharacter

Description

Checks that there are no tab characters ('\t') in the source code.

Rationale:

  • Developers should not need to configure the tab width of their text editors in order to be able to read source code.
  • From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.

Properties

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 {}

Example

To configure the check to report on the first instance in each file:

<module name="FileTabCharacter"/>
        

To configure the check to report on each line in each file:

<module name="FileTabCharacter">
    <property name="eachLine" value="true"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

Checker

WhitespaceAfter

Description

Checks that a token is followed by whitespace.

Properties

name description type default value
tokens tokens to check subset of tokens COMMA, SEMI, TYPECAST COMMA, SEMI, TYPECAST

Examples

To configure the check:

<module name="WhitespaceAfter"/>
        

To configure the check for whitespace only after COMMA and SEMI tokens:

<module name="WhitespaceAfter">
    <property name="tokens" value="COMMA, SEMI"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker

WhitespaceAround

Description

Checks that a token is surrounded by whitespace. Empty constructor and method bodies (blocks) of the form

public MyClass() {}      // empty constructor
public void func() {}    // empty method

may optionally be exempted from the policy using the allowEmptyMethods and allowEmptyConstructors properties.

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, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, 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

Examples

To configure the check:

<module name="WhitespaceAround"/>
        

To configure the check for whitespace around the assignment operator, =:

<module name="WhitespaceAround">
    <property name="tokens" value="ASSIGN"/>
</module>
        

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker