Since Checkstyle 3.0
for (Iterator foo = very.long.line.iterator();
foo.hasNext();
)
| name | description | type | default value | since |
|---|---|---|---|---|
| option | Specify policy on how to pad an empty for iterator. | PadOption | nospace |
3.0 |
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();
);
}
}
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