From 3d08dbb48087c93c993dd1ea4367b617718b1ee5 Mon Sep 17 00:00:00 2001 From: oowekyala Date: Sun, 13 Aug 2017 19:18:25 +0200 Subject: [PATCH 1/4] Fix #357 --- .../src/main/resources/rulesets/java/design.xml | 6 ++++-- .../design/xml/UncommentedEmptyConstructor.xml | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/resources/rulesets/java/design.xml b/pmd-java/src/main/resources/rulesets/java/design.xml index 56ac9b6fce..513c15469f 100644 --- a/pmd-java/src/main/resources/rulesets/java/design.xml +++ b/pmd-java/src/main/resources/rulesets/java/design.xml @@ -1425,8 +1425,10 @@ and unintentional empty constructors. +//ConstructorDeclaration[@Private='false'] + [count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false'] + [not(../Annotation/MarkerAnnotation/Name[@Image='Inject'])] +]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml index 48bc28e55a..08a95d5204 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml @@ -170,4 +170,19 @@ public class WebAgent { } ]]> + + + #357 UncommentedEmptyConstructor consider annotations on Constructor + 0 + + + From 41123508bc7ebad814f024232d5b894a69c6365e Mon Sep 17 00:00:00 2001 From: oowekyala Date: Sun, 13 Aug 2017 23:28:39 +0200 Subject: [PATCH 2/4] Use typeresolution in UncommentedEmptyConstructorRule --- pmd-java/src/main/resources/rulesets/java/design.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/resources/rulesets/java/design.xml b/pmd-java/src/main/resources/rulesets/java/design.xml index 513c15469f..0fe5d0bf1c 100644 --- a/pmd-java/src/main/resources/rulesets/java/design.xml +++ b/pmd-java/src/main/resources/rulesets/java/design.xml @@ -1413,6 +1413,7 @@ public void doSomething() { since="3.4" message="Document empty constructor" class="net.sourceforge.pmd.lang.rule.XPathRule" + typeResolution="true" externalInfoUrl="${pmd.website.baseurl}/rules/java/design.html#UncommentedEmptyConstructor"> Uncommented Empty Constructor finds instances where a constructor does not @@ -1427,7 +1428,7 @@ and unintentional empty constructors. From 93c3393999fd1a2c73be28ecb6ec1f78ebe0dec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Wed, 16 Aug 2017 15:16:35 -0300 Subject: [PATCH 3/4] Add fully qualified test case --- .../rule/design/xml/UncommentedEmptyConstructor.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml index 08a95d5204..c598374200 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UncommentedEmptyConstructor.xml @@ -185,4 +185,17 @@ public class WebAgent { ]]> + + + #357 UncommentedEmptyConstructor consider fully qualified annotations on Constructor + 0 + + + From ddc9fcacbc563932ceb3e4da0e6011862d0ab286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Wed, 16 Aug 2017 15:16:44 -0300 Subject: [PATCH 4/4] Update changelog, refs #556 --- src/site/markdown/overview/changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 5e45ae798c..7f8fc6ff79 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -76,6 +76,9 @@ and include them to such reports. It will now flag anonymous class' methods marked as final (can't be overridden, so it's pointless), along with final methods overridden / defined within enum instances. +* The rule `UncommentedEmptyConstructor` (ruleset `java-design`) will now ignore empty constructors annotated with + `javax.inject.Inject`. + #### Removed Rules * The deprecated rule `UseSingleton` has been removed from the ruleset `java-design`. The rule has been renamed @@ -119,6 +122,8 @@ Al existing rules have been updated to reflect these changes. If you have custom * [#536](https://github.com/pmd/pmd/issues/536): \[java] CommentDefaultAccessModifierRule ignores constructors * java-controversial * [#408](https://github.com/pmd/pmd/issues/408): \[java] DFA not analyzing asserts +* java-design + * [#357](https://github.com/pmd/pmd/issues/357): \[java] UncommentedEmptyConstructor consider annotations on Constructor * java-sunsecure * [#468](https://github.com/pmd/pmd/issues/468): \[java] ArrayIsStoredDirectly false positive * java-unusedcode @@ -162,4 +167,5 @@ Al existing rules have been updated to reflect these changes. If you have custom * [#535](https://github.com/pmd/pmd/pull/535): \[apex] Fix broken Apex visitor adapter - [Clément Fournier](https://github.com/oowekyala) * [#542](https://github.com/pmd/pmd/pull/542): \[java] Metrics abstraction - [Clément Fournier](https://github.com/oowekyala) * [#548](https://github.com/pmd/pmd/pull/548): \[java] Metrics documentation - [Clément Fournier](https://github.com/oowekyala) +* [#556](https://github.com/pmd/pmd/pull/556): \[java] Fix #357: UncommentedEmptyConstructor consider annotations on Constructor - [Clément Fournier](https://github.com/oowekyala)