Skip to content

Commit

Permalink
doc: update doc for EmptyBlock and extend example
Browse files Browse the repository at this point in the history
  • Loading branch information
romani committed Oct 24, 2024
1 parent 7124dad commit 023e50d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,12 @@

/**
* <div>
* Checks for empty blocks. This check does not validate sequential blocks.
* Checks for empty blocks.
* </div>
*
* <p>
* Sequential blocks won't be checked. Also, no violations for fallthrough:
* This check does not validate sequential blocks. This check does not violate fallthrough.
* </p>
* <pre>
* switch (a) {
* case 1: // no violation
* case 2: // no violation
* case 3: someMethod(); { } // no violation
* default: break;
* }
* </pre>
*
* <p>
* NOTE: This check processes LITERAL_CASE and LITERAL_DEFAULT separately.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@
name="EmptyBlock"
parent="com.puppycrawl.tools.checkstyle.TreeWalker">
<description>&lt;div&gt;
Checks for empty blocks. This check does not validate sequential blocks.
Checks for empty blocks.
&lt;/div&gt;

&lt;p&gt;
Sequential blocks won't be checked. Also, no violations for fallthrough:
This check does not validate sequential blocks. This check does not violate fallthrough.
&lt;/p&gt;
&lt;pre&gt;
switch (a) {
case 1: // no violation
case 2: // no violation
case 3: someMethod(); { } // no violation
default: break;
}
&lt;/pre&gt;

&lt;p&gt;
NOTE: This check processes LITERAL_CASE and LITERAL_DEFAULT separately.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public void testExample2() throws Exception {
public void testExample3() throws Exception {
final String[] expected = {
"19:16: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"20:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"37:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"38:18: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"22:15: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"24:15: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"27:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"44:17: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
"45:18: " + getCheckMessage(MSG_KEY_BLOCK_NO_STATEMENT, "case"),
};

verifyWithInlineConfigParser(getNonCompilablePath("Example3.java"), expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public class Example3 {
private void testBadSwitchStatement(int a) {
switch (a) {
case 1 : { } // violation, 'Must have at least one statement'
// the second empty block is 'sequential', skipped.
// violation below, 'Must have at least one statement'
case 2: {} {};
// violation below, 'Must have at least one statement'
case 3: {} {System.out.println();}
// the second empty block is 'sequential', skipped.
case 4: {System.out.println();} {}
default : { } // violation, 'Must have at least one statement'
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/xdocs/checks/blocks/emptyblock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@
<section name="EmptyBlock">
<p>Since Checkstyle 3.0</p>
<subsection name="Description" id="Description">
<div> Checks for empty blocks. This check does not validate sequential blocks. </div>
<div> Checks for empty blocks. </div>

<p> Sequential blocks won't be checked. Also, no violations for fallthrough: </p>
<source>
switch (a) {
case 1: // no violation
case 2: // no violation
case 3: someMethod(); { } // no violation
default: break;
}
</source>
<p> This check does not validate sequential blocks. This check does not violate fallthrough.
</p>

<p>
NOTE: This check processes LITERAL_CASE and LITERAL_DEFAULT separately.
Expand Down Expand Up @@ -184,6 +177,13 @@ public class Example3 {
private void testBadSwitchStatement(int a) {
switch (a) {
case 1 : { } // violation, 'Must have at least one statement'
// the second empty block is 'sequential', skipped.
// violation below, 'Must have at least one statement'
case 2: {} {};
// violation below, 'Must have at least one statement'
case 3: {} {System.out.println();}
// the second empty block is 'sequential', skipped.
case 4: {System.out.println();} {}
default : { } // violation, 'Must have at least one statement'
}
}
Expand Down
13 changes: 3 additions & 10 deletions src/xdocs/checks/blocks/emptyblock.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@
<section name="EmptyBlock">
<p>Since Checkstyle 3.0</p>
<subsection name="Description" id="Description">
<div> Checks for empty blocks. This check does not validate sequential blocks. </div>
<div> Checks for empty blocks. </div>

<p> Sequential blocks won't be checked. Also, no violations for fallthrough: </p>
<source>
switch (a) {
case 1: // no violation
case 2: // no violation
case 3: someMethod(); { } // no violation
default: break;
}
</source>
<p> This check does not validate sequential blocks. This check does not violate fallthrough.
</p>

<p>
NOTE: This check processes LITERAL_CASE and LITERAL_DEFAULT separately.
Expand Down

0 comments on commit 023e50d

Please sign in to comment.