Skip to content

Commit

Permalink
Issue checkstyle#7625: Updated doc for NoWhiteSpaceBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-kumar09 authored and romani committed Mar 18, 2020
1 parent 564f939 commit 024ed78
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,78 @@
* <pre>
* &lt;module name=&quot;NoWhitespaceBefore&quot;/&gt;
* </pre>
* <p>Example:</p>
* <pre>
* int foo;
* foo ++; // violation, whitespace before '++' is not allowed
* foo++; // OK
* for (int i = 0 ; i &lt; 5; i++) {} // violation
* // ^ whitespace before ';' is not allowed
* for (int i = 0; i &lt; 5; i++) {} // OK
* int[][] array = { { 1, 2 }
* , { 3, 4 } }; // violation, whitespace before ',' is not allowed
* int[][] array2 = { { 1, 2 },
* { 3, 4 } }; // OK
* Lists.charactersOf("foo").listIterator()
* .forEachRemaining(System.out::print)
* ; // violation, whitespace before ';' is not allowed
* </pre>
* <p>To configure the check to allow linebreaks before default tokens:</p>
* <pre>
* &lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
* &lt;property name=&quot;allowLineBreaks&quot; value=&quot;true&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* int[][] array = { { 1, 2 }
* , { 3, 4 } }; // OK, linebreak is allowed before ','
* int[][] array2 = { { 1, 2 },
* { 3, 4 } }; // OK, ideal code
* void ellipsisExample(String ...params) {}; // violation, whitespace before '...' is not allowed
* void ellipsisExample2(String
* ...params) {}; //OK, linebreak is allowed before '...'
* Lists.charactersOf("foo")
* .listIterator()
* .forEachRemaining(System.out::print); // OK
* </pre>
* <p>
* To Configure the check to restrict the use of whitespace before METHOD_REF and DOT tokens:
* </p>
* <pre>
* &lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
* &lt;property name=&quot;tokens&quot; value=&quot;METHOD_REF&quot;/&gt;
* &lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* Lists.charactersOf("foo").listIterator()
* .forEachRemaining(System.out::print); // violation, whitespace before '.' is not allowed
* Lists.charactersOf("foo").listIterator().forEachRemaining(System.out ::print); // violation,
* // whitespace before '::' is not allowed ^
* Lists.charactersOf("foo").listIterator().forEachRemaining(System.out::print); // OK
* </pre>
* <p>
* To configure the check to allow linebreaks before a DOT token:
* To configure the check to allow linebreak before METHOD_REF and DOT tokens:
* </p>
* <pre>
* &lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
* &lt;property name=&quot;tokens&quot; value=&quot;METHOD_REF&quot;/&gt;
* &lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
* &lt;property name=&quot;allowLineBreaks&quot; value=&quot;true&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* Lists .charactersOf("foo") //violation, whitespace before '.' is not allowed
* .listIterator()
* .forEachRemaining(System.out ::print); // violation,
* // ^ whitespace before '::' is not allowed
* Lists.charactersOf("foo")
* .listIterator()
* .forEachRemaining(System.out::print); // OK
* </pre>
*
* @since 3.0
*/
Expand Down
70 changes: 67 additions & 3 deletions src/xdocs/config_whitespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1308,16 +1308,80 @@ public void foo(final char @NotNull [] param) {} // No violation
<source>
&lt;module name=&quot;NoWhitespaceBefore&quot;/&gt;
</source>

<p>Example:</p>
<source>
int foo;
foo ++; // violation, whitespace before '++' is not allowed
foo++; // OK
for (int i = 0 ; i &lt; 5; i++) {} // violation
// ^ whitespace before ';' is not allowed
for (int i = 0; i &lt; 5; i++) {} // OK
int[][] array = { { 1, 2 }
, { 3, 4 } }; // violation, whitespace before ',' is not allowed
int[][] array2 = { { 1, 2 },
{ 3, 4 } }; // OK
Lists.charactersOf("foo").listIterator()
.forEachRemaining(System.out::print)
; // violation, whitespace before ';' is not allowed
</source>
<p>
To configure the check to allow linebreaks before a DOT token:
To configure the check to allow linebreaks before default tokens:
</p>
<source>
&lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
&lt;property name=&quot;allowLineBreaks&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<source>
int[][] array = { { 1, 2 }
, { 3, 4 } }; // OK, linebreak is allowed before ','
int[][] array2 = { { 1, 2 },
{ 3, 4 } }; // OK, ideal code
void ellipsisExample(String ...params) {}; // violation, whitespace before '...' is not allowed
void ellipsisExample2(String
...params) {}; //OK, linebreak is allowed before '...'
Lists.charactersOf("foo")
.listIterator()
.forEachRemaining(System.out::print); // OK
</source>
<p>
To Configure the check to restrict the use of whitespace before METHOD_REF and DOT tokens:
</p>
<source>
&lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;METHOD_REF&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<source>
Lists.charactersOf("foo").listIterator()
.forEachRemaining(System.out::print); // violation, whitespace before '.' is not allowed
Lists.charactersOf("foo").listIterator().forEachRemaining(System.out ::print); // violation,
// whitespace before '::' is not allowed ^
Lists.charactersOf("foo").listIterator().forEachRemaining(System.out::print); // OK
</source>
<p>
To configure the check to allow linebreak before METHOD_REF and DOT tokens:
</p>
<source>
&lt;module name=&quot;NoWhitespaceBefore&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;METHOD_REF&quot;/&gt;
&lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
&lt;property name=&quot;allowLineBreaks&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<source>
Lists .charactersOf("foo") //violation, whitespace before '.' is not allowed
.listIterator()
.forEachRemaining(System.out ::print); // violation,
// ^ whitespace before '::' is not allowed
Lists.charactersOf("foo")
.listIterator()
.forEachRemaining(System.out::print); // OK
</source>
</subsection>

<subsection name="Example of Usage" id="NoWhitespaceBefore_Example_of_Usage">
Expand Down

0 comments on commit 024ed78

Please sign in to comment.