Since Checkstyle 3.0
Checks the policy on how to wrap lines on operators.
See the Java Language Specification for more information about {@code instanceof} operator.
name | description | type | default value | since |
---|---|---|---|---|
option | Specify policy on how to wrap lines. | WrapOption | nl |
3.0 |
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 . | 3.0 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="OperatorWrap"/> </module> </module>
Example:
class Example1 { void example() { String s = "Hello" + // violation ''\+' should be on a new line' "World"; if (10 == // violation ''==' should be on a new line' 20) { } if (10 == 20) { } int c = 10 / 5; // violation above ''/' should be on a new line' int d = c + 10; } }
To configure the check for assignment operators at the end of a line:
<module name="Checker"> <module name="TreeWalker"> <module name="OperatorWrap"> <property name="option" value="eol"/> <property name="tokens" value="ASSIGN,DIV_ASSIGN,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN, MOD_ASSIGN,SR_ASSIGN,BSR_ASSIGN,SL_ASSIGN, BXOR_ASSIGN,BOR_ASSIGN,BAND_ASSIGN"/> </module> </module> </module>
Example:
class Example2 { void example() { int b = 10; // violation ''=' should be on the previous line' int c = 10; b += 10; // violation ''\+=' should be on the previous line' b += 10; c *= 10; // violation ''*=' should be on the previous line' c -= 5; // violation ''-=' should be on the previous line' c -= 5; c /= 2; // violation ''/=' should be on the previous line' c %= 1; // violation ''%=' should be on the previous line' c >>= 1; // violation ''>>=' should be on the previous line' c >>>= 1; // violation ''>>>=' should be on the previous line' c &=1 ; // violation ''&=' should be on the previous line' c <<= 1; // violation ''<<=' should be on the previous 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