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--)
name | description | type | default value |
---|---|---|---|
option | policy on how to pad an empty for iterator | pad policy | nospace |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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(); )
name | description | type | default value |
---|---|---|---|
option | policy on how to pad an empty for iterator | pad policy | nospace |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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 |
---|---|---|---|
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:
/////////////////////////////////////////////////// //HEADER /////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.whitespace; import java.io.Serializable; class Foo { public static final int FOO_CONST = 1; public void foo() {} //should be separated from previous statement. }
An example of how to configure the check with default parameters is:
<module name="EmptyLineSeparator"/>
Example of declarations with empty line separator that is expected by the Check by default:
/////////////////////////////////////////////////// //HEADER /////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.whitespace; import java.io.Serializable; class Foo { public static final int FOO_CONST = 1; public void foo() {} //should be separated from previous statement. }
An example how to check empty line after VARIABLE_DEF and METHOD_DEF:
<module name="EmptyLineSeparator"> <property name="tokens" value="VARIABLE_DEF, METHOD_DEF"/> </module>
An example how to allow no empty line between fields:
<module name="EmptyLineSeparator"> <property name="allowNoEmptyLineBetweenFields" value="true"/> </module>
An example how to disallow multiple empty lines inside constructor, initialization block and method:
<module name="EmptyLineSeparator"> <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/> </module>
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:
/////////////////////////////////////////////////// //HEADER /////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.whitespace; class Foo { public void foo() { System.out.println(1); // violation since method has 2 empty lines subsequently } }
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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:
<module name="FileTabCharacter"/>
To configure the check to report on each line in each file:
<module name="FileTabCharacter"> <property name="eachLine" value="true"/> </module>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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:
public void <K, V extends Number> boolean foo(K, V) {} // Generic methods definitions class name<T1, T2, ..., Tn> {} // Generic type definition OrderedPair<String, Box<Integer>> p; // Generic type reference boolean same = Util.<Integer, String>compare(p1, p2); // Generic preceded method name Pair<Integer, String> p1 = new Pair<>(1, "apple"); // Diamond operator List<T> list = ImmutableList.Builder<T>::new; // Method reference sort(list, Comparable::<String>compareTo); // Method reference
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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:
<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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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, PACKAGE_DEF, CLASS_DEF, METHOD_DEF, CTOR_DEF, ENUM_DEF, INTERFACE_DEF. | PACKAGE_DEF, IMPORT. |
Examples of line-wrapped statements (bad case):
package com.puppycrawl. tools.checkstyle.checks; import com.puppycrawl.tools. checkstyle.api.AbstractCheck;
To configure the check to force no line-wrapping in package and import statements (default values):
<module name="NoLineWrap"/>
To configure the check to force no line-wrapping only in import statements:
<module name="NoLineWrap"> <property name="tokens" value="IMPORT"/> </module>
Examples of not line-wrapped statements (good case):
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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. | ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP. |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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. | COMMA, SEMI, POST_INC, POST_DEC. |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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. | 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:
<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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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, 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. | ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, 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. |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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:
s .isEmpty(); foo(i ,s);
An example of how to configure the check is:
<module name="SeparatorWrap"/>
Code example for comma and dot at the previous line:
s. isEmpty(); foo(i, s);
An example of how to configure the check for comma at the new line is:
<module name="SeparatorWrap"> <property name="tokens" value="COMMA"/> <property name="option" value="nl"/> </module>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
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:
<module name="TypecastParenPad"/>
To configure the check to require spaces:
<module name="TypecastParenPad"> <property name="option" value="space"/> </module>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
name | description | type | default value |
---|---|---|---|
tokens | tokens to check | subset of tokens COMMA, SEMI, TYPECAST. | COMMA, SEMI, TYPECAST. |
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.
Checks that a token is surrounded by whitespace. Empty constructor, method, class, enum, interface, loop bodies (blocks), lambdas of the form
public MyClass() {} // empty constructor public void func() {} // empty method public interface Foo {} // empty interface public class Foo {} // empty class public enum Foo {} // empty enum MyClass c = new MyClass() {}; // empty anonymous class while (i = 1) {} // empty while loop for (int i = 1; i > 1; i++) {} // empty for loop do {} while (i = 1); // empty do-while loop Runnable noop = () -> {}; // empty lambda public @interface Beta {} // empty annotation type
may optionally be exempted from the policy using the allowEmptyMethods, allowEmptyConstructors , allowEmptyTypes, allowEmptyLoops and allowEmptyLambdas properties.
This check does not flag as violation double brace initialization like:
new Properties() {{ setProperty("key", "value"); }};
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>
All messages can be customized if the default message doesn't suite you. Please see the documentation to learn how to.