Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7264: Adds examples to NoWhiteSpaceAfter #6

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 165 additions & 6 deletions config_whitespace.html
Original file line number Diff line number Diff line change
@@ -2005,19 +2005,178 @@ <h3><a name="Examples"></a>Examples</h3>
&lt;module name=&quot;NoWhitespaceAfter&quot;/&gt;
</pre></div>


<p>
To configure the check to forbid linebreaks after a DOT token:
</p>

To configure check to restrict use of whitespace after DOT token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
&lt;/module&gt;
</pre></div>

<p>Example:</p>

<div class="source">
<pre>
class CheckDotToken {
int a, b;
CheckDotToken(int a, int b) {
this. a = a; // violation, whitespace after '.' is not allowed
this.b = b; // OK
}

public void function() {}
public static void main(String[] args) {
CheckDotToken ob = new CheckDotToken(5, 7);
ob. function(); // violation, whitespace after '.' is not allowed
ob.function(); // OK
ob. a = 10; // violaion, whitespace after '.' is not allowed
ob.b = 17; // OK
}
}
</pre></div>

<p>
To configure check to allow line breaks after DOT token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;
&lt;property name=&quot;allowLineBreaks&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</pre></div>

</pre></div>

<p>Example:</p>

<div class="source">
<pre>
class CheckDotToken {
int a, b;
CheckDotToken(int a, int b) {
this.
a = a; // violation, linebreak after '.' is not allowed
this.b = b; // OK
}

public void function() {}
public static void main(String[] args) {
CheckDotToken ob = new CheckDotToken(5, 7);
ob.
function(); // violation, linebreak after '.' is not allowed
ob.function(); // OK
ob.
a = 10; // violation, linebreak after '.' is not allowed
ob.b = 17; // OK
}
}
</pre></div>

<p>
To configure check to restrict use of whitespace after ARRAY_DECLARATOR token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;ARRAY_DECLARATOR&quot;/&gt;
&lt;/module&gt;
</pre></div>

<p>Example:</p>

<div class="source">
<pre>
int [] array1; // violation, whitespace after 'int' is not allowed
int[] array2; // OK
int[ ] array3; // OK
int array4 []; // violation, whitespace after 'array4' is not allowed
int array5[]; // OK
int array6[ ]; // OK
</pre></div>

<p>
To configure check to allow line breaks after ARRAY_DECLARATOR token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;ARRAY_DECLARATOR&quot;/&gt;
&lt;property name=&quot;allowLineBreaks&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</pre></div>

<p>Example:</p>

<div class="source">
<pre>
int
[] array1; // violation, linebreak after 'int' is not allowed
int[
] array2; // OK
int array3
[]; // violation, linebreak after 'a' is not allowed
int array4[
]; // OK
</pre></div>

<p>
To configure check to restrict use of whitespace after ARRAY_INIT token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;ARRAY_INIT&quot;/&gt;
&lt;/module&gt;
</pre></div>

<p>Example:</p>

<div class="source">
<pre>
int[] array1 = { 1, 2, 3, 4}; // violation, whitespace after '{' is not allowed
int[] array2 = {1, 2, 3, 4 }; // OK
int[][] array3 = {{ 1,2}, {3,4}} // violation, whitespace after '{' is not allowed
int[][] array4 = {{1,2}, {3,4} } // OK
int[][] array5 = new int[]{ 1,2,3,4} // violation, whitespace after '{' is not allowed
</pre></div>

<p>
To configure check to allow line breaks after ARRAY_INIT token:
</p>

<div class="source">
<pre>
&lt;module name=&quot;NoWhitespaceAfter&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;ARRAY_INIT&quot;/&gt;
&lt;property name=&quot;allowLineBreaks&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</pre></div>

<p>Example:</p>

<div class="source">
<pre>
int[] array1 = {
1,
2
}; // violation, linebreak after '{' is not allowed
int[] array2 = {1,2
};// OK
int[] array3 = {
{1,2},
{3,4}
}; // violation, linebreak after '{' is not allowed
int[][] array4 = {{1,2},
{3,4}
}; // OK
</pre></div>

<p>
If the annotation is between the type and the array, the check will skip validation for
spaces: