Add test case for NoPackage and Annotation

Update release notes, fixes #1782, refs #1771
This commit is contained in:
Andreas Dangel
2019-04-18 19:53:14 +02:00
parent 7542306e05
commit b55676e4d0
3 changed files with 19 additions and 15 deletions

View File

@ -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

View File

@ -1350,11 +1350,11 @@ public class Foo {
<rule name="NoPackage"
language="java"
since="3.3"
message="All classes and interfaces must belong to a named package"
message="All classes, interfaces, enums and annotations must belong to a named package"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#nopackage">
<description>
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.
</description>
<priority>3</priority>
<properties>

View File

@ -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">
<test-code>
<description><![CDATA[
bad
]]></description>
<description>bad</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -14,9 +12,7 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description><![CDATA[
good
]]></description>
<description>good</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package foo;
@ -25,9 +21,7 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description><![CDATA[
nested package
]]></description>
<description>nested package</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package foo.bar;
@ -35,10 +29,8 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
no package in top-level enum
]]></description>
<test-code>
<description>#1782 no package in top-level enum</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public enum Foo {
@ -46,4 +38,11 @@ public enum Foo {
}
]]></code>
</test-code>
<test-code>
<description>#1782 no package with annotation</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public @interface MyAnnotation {}
]]></code>
</test-code>
</test-data>