SeparatorWrap

Since Checkstyle 5.8

Description

Checks line wrapping with separators.

Properties

name description type default value since
option Specify policy on how to wrap lines. WrapOption eol 5.8
tokens tokens to check subset of tokens DOT , COMMA , SEMI , ELLIPSIS , AT , LPAREN , RPAREN , ARRAY_DECLARATOR , RBRACK , METHOD_REF . DOT , COMMA . 5.8

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="SeparatorWrap"/>
  </module>
</module>
        

Example:

import java.io.
          IOException; // OK, dot is on the previous line

class Example1 {
  String s;

  public void foo(int a,
                    int b) { // OK, comma is on the previous line
  }

  public void bar(int p
                    , int q) { // violation '',' should be on the previous line'
    if (s
          .isEmpty()) { // violation ''.' should be on the previous line'
    }
  }
}
        

To configure the check for METHOD_REF at new line:

<module name="Checker">
  <module name="TreeWalker">
    <module name="SeparatorWrap">
      <property name="tokens" value="METHOD_REF"/>
      <property name="option" value="nl"/>
    </module>
  </module>
</module>
        

Example:

import java.util.Arrays;

class Example2 {
  String[] stringArray = {"foo", "bar"};

  void fun() {
    // violation below ''::' should be on a new line'
    Arrays.sort(stringArray, String::
      compareToIgnoreCase);
    Arrays.sort(stringArray, String
      ::compareTo); // OK, because it is on a new line
  }
}
        

To configure the check for comma at the new line:

<module name="Checker">
  <module name="TreeWalker">
    <module name="SeparatorWrap">
      <property name="tokens" value="COMMA"/>
      <property name="option" value="nl"/>
    </module>
  </module>
</module>
        

Example:

class Example3 {
  String s;

  int a,
    b; // violation above '',' should be on a new line'

  void foo(int a,
                int b) { // violation above '',' should be on a new line'
    int r
      , t; // OK, because it is on a new line
  }

  void bar(int p
                , int q) { // OK, because it is on a new 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