OperatorWrap

Since Checkstyle 3.0

Description

Checks the policy on how to wrap lines on operators.

See the Java Language Specification for more information about {@code instanceof} operator.

Properties

Examples

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

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker