diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckExamplesTest.java
index 4b27fa294c5..f72ca1941c4 100644
--- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckExamplesTest.java
+++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckExamplesTest.java
@@ -19,12 +19,10 @@
package com.puppycrawl.tools.checkstyle.checks.coding;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
-@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class ModifiedControlVariableCheckExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
@@ -34,18 +32,19 @@ protected String getPackageLocation() {
@Test
public void testExample1() throws Exception {
final String[] expected = {
-
+ "14:8: " + getCheckMessage(ModifiedControlVariableCheck.MSG_KEY, "i"),
+ "18:11: " + getCheckMessage(ModifiedControlVariableCheck.MSG_KEY, "arg"),
};
- verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
+ verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}
@Test
public void testExample2() throws Exception {
final String[] expected = {
-
+ "16:8: " + getCheckMessage(ModifiedControlVariableCheck.MSG_KEY, "i"),
};
- verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
+ verifyWithInlineConfigParser(getPath("Example2.java"), expected);
}
}
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.java
new file mode 100644
index 00000000000..fc3617a3358
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.java
@@ -0,0 +1,22 @@
+/*xml
+
+
+
+
+
+*/
+package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable;
+
+// xdoc section -- start
+class Example1 {
+ void InvalidExample() {
+ for(int i=0;i < 8;i++) {
+ i++; // violation, control variable modified
+ }
+ String args1[]={"Coding", "block"};
+ for (String arg: args1) {
+ arg = arg.trim(); // violation, control variable modified
+ }
+ }
+}
+// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.txt
deleted file mode 100644
index 62d7d5c4b51..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-/*xml
-
-
-
-
-
-*/
-
-// xdoc section -- start
-for(int i=0;i < 8;i++) {
- i++; // violation, control variable modified
-}
-String args1[]={"Coding", "block"};
-for (String arg: args1) {
- arg = arg.trim(); // violation, control variable modified
-}
-// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.java
new file mode 100644
index 00000000000..40a4f740f94
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.java
@@ -0,0 +1,24 @@
+/*xml
+
+
+
+
+
+
+
+*/
+package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable;
+
+// xdoc section -- start
+class Example2 {
+ void InvalidExample() {
+ for(int i=0;i < 8;i++) {
+ i++; // violation, control variable modified
+ }
+ String args1[]={"Coding", "block"};
+ for (String arg: args1) {
+ arg = arg.trim();
+ }
+ }
+}
+// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.txt
deleted file mode 100644
index c5112280cbe..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*xml
-
-
-
-
-
-
-
-*/
-
-// xdoc section -- start
-for(int i=0;i < 8;i++) {
- i++; // violation, control variable modified
-}
-String args1[]={"Coding", "block"};
-for (String arg: args1) {
- arg = arg.trim(); // ok
-}
-// xdoc section -- end
diff --git a/src/xdocs/checks/coding/modifiedcontrolvariable.xml b/src/xdocs/checks/coding/modifiedcontrolvariable.xml
index 944ef8e35d1..d237232743d 100644
--- a/src/xdocs/checks/coding/modifiedcontrolvariable.xml
+++ b/src/xdocs/checks/coding/modifiedcontrolvariable.xml
@@ -80,12 +80,16 @@ for (int a[]={0};a[0] < 10;a[0]++) {
Example:
-for(int i=0;i < 8;i++) {
- i++; // violation, control variable modified
-}
-String args1[]={"Coding", "block"};
-for (String arg: args1) {
- arg = arg.trim(); // violation, control variable modified
+class Example1 {
+ void InvalidExample() {
+ for(int i=0;i < 8;i++) {
+ i++; // violation, control variable modified
+ }
+ String args1[]={"Coding", "block"};
+ for (String arg: args1) {
+ arg = arg.trim(); // violation, control variable modified
+ }
+ }
}
@@ -111,12 +115,16 @@ for (String arg: args1) {
Example:
-for(int i=0;i < 8;i++) {
- i++; // violation, control variable modified
-}
-String args1[]={"Coding", "block"};
-for (String arg: args1) {
- arg = arg.trim(); // ok
+class Example2 {
+ void InvalidExample() {
+ for(int i=0;i < 8;i++) {
+ i++; // violation, control variable modified
+ }
+ String args1[]={"Coding", "block"};
+ for (String arg: args1) {
+ arg = arg.trim();
+ }
+ }
}
diff --git a/src/xdocs/checks/coding/modifiedcontrolvariable.xml.template b/src/xdocs/checks/coding/modifiedcontrolvariable.xml.template
index af16acc8a61..a38305562d7 100644
--- a/src/xdocs/checks/coding/modifiedcontrolvariable.xml.template
+++ b/src/xdocs/checks/coding/modifiedcontrolvariable.xml.template
@@ -58,7 +58,7 @@ for (int a[]={0};a[0] < 10;a[0]++) {
+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.java"/>
@@ -66,7 +66,7 @@ for (int a[]={0};a[0] < 10;a[0]++) {
+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example1.java"/>
@@ -83,13 +83,13 @@ for (int a[]={0};a[0] < 10;a[0]++) {
+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.java"/>
Example:
+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/Example2.java"/>