pmd: fix #1126 False positive with FieldDeclarationsShouldBeAtStartOfClass for static enums

This commit is contained in:
Andreas Dangel committed 2014-02-02 10:33:31 +01:00
1 parent bbb36686b9
commit 5b52ba642c
4 files changed
+46 -2

No files matched your search

@@ -1771,10 +1771,13 @@ Fields should be declared at the top of the class, before any method declaration
<value>
<![CDATA[
//ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
[count(../preceding-sibling::ClassOrInterfaceBodyDeclaration/child::*[1][name() != 'FieldDeclaration' and name() != 'Annotation']) > 0]
[count(../preceding-sibling::ClassOrInterfaceBodyDeclaration/child::*[1]
[name() != 'FieldDeclaration' and name() != 'Annotation' and
(name() != 'EnumDeclaration' or $ignoreEnumDeclarations = 'false')]) > 0]
]]>
</value>
</property>
<property name="ignoreEnumDeclarations" description="Ignore Enum Declarations that precede fields." type="Boolean" value="true"/>
</properties>
<example>
<![CDATA[
+2
View File
@@ -42,6 +42,7 @@
* Fixed [bug 1115]: commentRequiredRule in pmd 5.1 is not working properly
* Fixed [bug 1121]: NullPointerException when invoking XPathCLI
* Fixed [bug 1123]: failure in help examples
* Fixed [bug 1126]: False positive with FieldDeclarationsShouldBeAtStartOfClass for static enums
* Fixed [bug 1130]: CloseResource doesn't recognize custom close method
* Fixed [bug 1131]: CloseResource should complain if code betwen declaration of resource and try
* Fixed [bug 1134]: UseStringBufferLength: false positives
@@ -63,6 +64,7 @@
[bug 1115]: https://sourceforge.net/p/pmd/bugs/1115
[bug 1121]: https://sourceforge.net/p/pmd/bugs/1121
[bug 1123]: https://sourceforge.net/p/pmd/bugs/1123
[bug 1126]: https://sourceforge.net/p/pmd/bugs/1126
[bug 1130]: https://sourceforge.net/p/pmd/bugs/1130
[bug 1131]: https://sourceforge.net/p/pmd/bugs/1131
[bug 1134]: https://sourceforge.net/p/pmd/bugs/1134
@@ -47,7 +47,7 @@ public class DesignRulesTest extends SimpleAggregatorTst {
addRule(RULESET, "NonStaticInitializer");
addRule(RULESET, "NonThreadSafeSingleton");
addRule(RULESET, "OptimizableToArrayCall");
//addRule(RULESET, "PositionalIteratorRule"); This rule does not yes exist
//addRule(RULESET, "PositionalIteratorRule"); This rule does not yet exist
addRule(RULESET, "PositionLiteralsFirstInComparisons");
addRule(RULESET, "PositionLiteralsFirstInCaseInsensitiveComparisons");
addRule(RULESET, "PreserveStackTrace");
@@ -74,4 +74,43 @@ protected String _second;
]]>
</code>
</test-code>
<test-code>
<description>#1126 False positive with FieldDeclarationsShouldBeAtStartOfClass for static enums</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);
public static enum MyType {
ABC, DEF, GHI, JHK
};
private int id;
private MyType myType;
private String name;
// OK, now constructors, getters, setters, etc.
}
]]></code>
</test-code>
<test-code>
<description>#1126 Do not ignore enums</description>
<expected-problems>3</expected-problems>
<rule-property name="ignoreEnumDeclarations">false</rule-property>
<code><![CDATA[
public class Foo {
private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);
public static enum MyType {
ABC, DEF, GHI, JHK
};
private int id;
private MyType myType;
private String name;
// OK, now constructors, getters, setters, etc.
}
]]></code>
</test-code>
</test-data>