From 38708754639278abe108c37bef025e76c38e7882 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Thu, 7 Mar 2024 23:25:10 -0800 Subject: [PATCH] Issue #13345: enable test for AvoidNoArgumentSuperConstructorCallCheck --- ...SuperConstructorCallCheckExamplesTest.java | 8 +++--- .../Example1.java | 28 +++++++++++++++++++ .../Example1.txt | 23 --------------- .../avoidnoargumentsuperconstructorcall.xml | 24 +++++++++------- ...oargumentsuperconstructorcall.xml.template | 4 +-- 5 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.java delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.txt diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/AvoidNoArgumentSuperConstructorCallCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/AvoidNoArgumentSuperConstructorCallCheckExamplesTest.java index dc7239b28a5..9be471ba98c 100644 --- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/AvoidNoArgumentSuperConstructorCallCheckExamplesTest.java +++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/coding/AvoidNoArgumentSuperConstructorCallCheckExamplesTest.java @@ -19,12 +19,12 @@ package com.puppycrawl.tools.checkstyle.checks.coding; -import org.junit.jupiter.api.Disabled; +import static com.puppycrawl.tools.checkstyle.checks.coding.AvoidNoArgumentSuperConstructorCallCheck.MSG_CTOR; + import org.junit.jupiter.api.Test; import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport; -@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345") public class AvoidNoArgumentSuperConstructorCallCheckExamplesTest extends AbstractExamplesModuleTestSupport { @Override @@ -35,9 +35,9 @@ protected String getPackageLocation() { @Test public void testExample1() throws Exception { final String[] expected = { - + "17:5: " + getCheckMessage(MSG_CTOR), }; - verifyWithInlineConfigParser(getPath("Example1.txt"), expected); + verifyWithInlineConfigParser(getPath("Example1.java"), expected); } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.java new file mode 100644 index 00000000000..202d865f806 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.java @@ -0,0 +1,28 @@ +/*xml + + + + + +*/ +package com.puppycrawl.tools.checkstyle.checks.coding.avoidnoargumentsuperconstructorcall; + +// xdoc section -- start +class SuperClass { + public SuperClass() {} + public SuperClass(int arg) {} +} +class Example1 extends SuperClass { + Example1() { + super(); // violation + } + + Example1(int arg) { + super(arg); // ok, explicit constructor invocation with argument + } + + Example1(long arg) { + // ok, no explicit constructor invocation + } +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.txt deleted file mode 100644 index feacc639af5..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/coding/avoidnoargumentsuperconstructorcall/Example1.txt +++ /dev/null @@ -1,23 +0,0 @@ -/*xml - - - - - -*/ - -// xdoc section -- start -class MyClass extends SomeOtherClass { - MyClass() { - super(); // violation - } - - MyClass(int arg) { - super(arg); // OK, call with argument have to be explicit - } - - MyClass(long arg) { - // OK, call is implicit - } -} -// xdoc section -- end diff --git a/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml b/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml index cf7dfb94d2f..39548865034 100644 --- a/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml +++ b/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml @@ -33,18 +33,22 @@ Example of violations

-class MyClass extends SomeOtherClass { - MyClass() { - super(); // violation - } +class SuperClass { + public SuperClass() {} + public SuperClass(int arg) {} +} +class Example1 extends SuperClass { + Example1() { + super(); // violation + } - MyClass(int arg) { - super(arg); // OK, call with argument have to be explicit - } + Example1(int arg) { + super(arg); // ok, explicit constructor invocation with argument + } - MyClass(long arg) { - // OK, call is implicit - } + Example1(long arg) { + // ok, no explicit constructor invocation + } } diff --git a/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml.template b/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml.template index 2288a203300..b9858966563 100644 --- a/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml.template +++ b/src/xdocs/checks/coding/avoidnoargumentsuperconstructorcall.xml.template @@ -24,7 +24,7 @@

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

@@ -32,7 +32,7 @@

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