diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckExamplesTest.java index 36707268b31..a335b6313f7 100644 --- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckExamplesTest.java +++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/SimplifyBooleanExpressionCheckExamplesTest.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 SimplifyBooleanExpressionCheckExamplesTest extends AbstractExamplesModuleTestSupport { @Override protected String getPackageLocation() { @@ -34,9 +32,14 @@ protected String getPackageLocation() { @Test public void testExample1() throws Exception { final String[] expected = { - + "18:9: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), + "19:11: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), + "21:11: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), + "22:13: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), + "24:12: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), + "27:23: " + getCheckMessage(SimplifyBooleanExpressionCheck.MSG_KEY), }; - verifyWithInlineConfigParser(getPath("Example1.txt"), expected); + verifyWithInlineConfigParser(getPath("Example1.java"), expected); } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.java new file mode 100644 index 00000000000..6de907c85c3 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.java @@ -0,0 +1,31 @@ +/*xml + + + + + +*/ +package com.puppycrawl.tools.checkstyle.checks.coding.simplifybooleanexpression; + +// xdoc section -- start +class Example1 { + void InvalidExample() { + boolean a=true; + boolean b=true; + Object c=null; + Object d=null; + Object e=null; + if (!false) {}; // violation, can be simplified to true + if (a == true) {}; // violation, can be simplified to a + if (a == b) {}; + if (a == false) {}; // violation, can be simplified to !a + if (!(a != true)) {}; // violation, can be simplified to a + e = (a || b) ? c : d; + e = (a || false) ? c : d; // violation, can be simplified to a + e = (a && b) ? c : d; + int s = 12; + boolean m = s > 1 ? true : false; // violation, can be simplified to s > 1 + boolean f = c == null ? false : c.equals(d); + } +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.txt deleted file mode 100644 index 406caed02c2..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.txt +++ /dev/null @@ -1,34 +0,0 @@ -/*xml - - - - - -*/ - -// xdoc section -- start -public class Test { - - public void bar() { - - boolean a, b; - Foo c, d, e; - - if (!false) {}; // violation, can be simplified to true - - if (a == true) {}; // violation, can be simplified to a - if (a == b) {}; // OK - if (a == false) {}; // violation, can be simplified to !a - if (!(a != true)) {}; // violation, can be simplified to a - - e = (a || b) ? c : d; // OK - e = (a || false) ? c : d; // violation, can be simplified to a - e = (a && b) ? c : d; // OK - - int s = 12; - boolean m = s > 1 ? true : false; // violation, can be simplified to s > 1 - boolean f = c == null ? false : c.someMethod(); // OK - } - -} -// xdoc section -- end diff --git a/src/xdocs/checks/coding/simplifybooleanexpression.xml b/src/xdocs/checks/coding/simplifybooleanexpression.xml index abd258ef26e..f3bb9956f1a 100644 --- a/src/xdocs/checks/coding/simplifybooleanexpression.xml +++ b/src/xdocs/checks/coding/simplifybooleanexpression.xml @@ -35,29 +35,25 @@

Example:

-public class Test { - - public void bar() { - - boolean a, b; - Foo c, d, e; - - if (!false) {}; // violation, can be simplified to true - - if (a == true) {}; // violation, can be simplified to a - if (a == b) {}; // OK - if (a == false) {}; // violation, can be simplified to !a +class Example1 { + void InvalidExample() { + boolean a=true; + boolean b=true; + Object c=null; + Object d=null; + Object e=null; + if (!false) {}; // violation, can be simplified to true + if (a == true) {}; // violation, can be simplified to a + if (a == b) {}; + if (a == false) {}; // violation, can be simplified to !a if (!(a != true)) {}; // violation, can be simplified to a - - e = (a || b) ? c : d; // OK + e = (a || b) ? c : d; e = (a || false) ? c : d; // violation, can be simplified to a - e = (a && b) ? c : d; // OK - + e = (a && b) ? c : d; int s = 12; boolean m = s > 1 ? true : false; // violation, can be simplified to s > 1 - boolean f = c == null ? false : c.someMethod(); // OK + boolean f = c == null ? false : c.equals(d); } - } diff --git a/src/xdocs/checks/coding/simplifybooleanexpression.xml.template b/src/xdocs/checks/coding/simplifybooleanexpression.xml.template index 98793d1c8b2..2427bd6ef94 100644 --- a/src/xdocs/checks/coding/simplifybooleanexpression.xml.template +++ b/src/xdocs/checks/coding/simplifybooleanexpression.xml.template @@ -28,13 +28,13 @@

+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.java"/>

Example:

+ value="resources/com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression/Example1.java"/>