EmptyForIteratorPad

Since Checkstyle 3.0

Description

Checks the padding of an empty for iterator; that is whether a 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 since
option Specify policy on how to pad an empty for iterator. PadOption nospace 3.0

Examples

To configure the check:

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

Example:

class Example1 {
  Map<String, String> map = new HashMap<>();
  void example() {
    for (Iterator it = map.entrySet().iterator();  it.hasNext(););
    for (Iterator it = map.entrySet().iterator();  it.hasNext(); );
    // violation above '';' is followed by whitespace'

    for (Iterator foo = map.entrySet().iterator();
         foo.hasNext();
         );
  }
}
        

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

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

Example:

class Example2 {
  Map<String, String> map = new HashMap<>();
  void example() {
    for (Iterator it = map.entrySet().iterator();  it.hasNext(););
    // violation above '';' is not followed by whitespace.'
    for (Iterator it = map.entrySet().iterator();  it.hasNext(); );

    for (Iterator foo = map.entrySet().iterator();
         foo.hasNext();
         );
  }
}
        

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