From b55676e4d0956ae5da5ed1b4eecb21fba6e02dfa Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 18 Apr 2019 19:53:14 +0200 Subject: [PATCH] Add test case for NoPackage and Annotation Update release notes, fixes #1782, refs #1771 --- docs/pages/release_notes.md | 5 ++++ .../resources/category/java/codestyle.xml | 4 +-- .../java/rule/codestyle/xml/NoPackage.xml | 25 +++++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 0494e03a2e..edf8ae5b63 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -30,6 +30,9 @@ Being based on a proper Antlr grammar, CPD can: assignment made within a constructor rather than on the field declaration. This makes it easier for developers to find the offending statements. +* The Java rule {% rule "java/codestyle/NoPackage" %} (`java-codestyle`) will now report additionally enums + and annotations that do not have a package declaration. + ### Fixed Issues * go @@ -38,6 +41,8 @@ Being based on a proper Antlr grammar, CPD can: * [#1729](https://github.com/pmd/pmd/issues/1729): \[java] JavaRuleViolation loses information in `className` field when class has package-private access level * java-bestpractices * [#1720](https://github.com/pmd/pmd/issues/1720): \[java] UnusedImports false positive for Javadoc link with array type +* java-codestyle + * [#1782](https://github.com/pmd/pmd/issues/1782): \[java] NoPackage: False Negative for enums * java-design * [#1760](https://github.com/pmd/pmd/issues/1760): \[java] UseObjectForClearerAPI flags private methods diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 9643356624..05bd9f803b 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -1350,11 +1350,11 @@ public class Foo { -Detects when a class or interface does not have a package definition. +Detects when a class, interface, enum or annotation does not have a package definition. 3 diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/NoPackage.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/NoPackage.xml index 95b3f865b7..a851baee5f 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/NoPackage.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/NoPackage.xml @@ -4,9 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - + bad 1 - + good 0 - + nested package 0 - - + + #1782 no package in top-level enum 1 + + #1782 no package with annotation + 1 + +