Merge branch 'bug-1480' into pmd/5.4.x
This commit is contained in:
@ -13,22 +13,36 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
public class UnusedModifierRule extends AbstractJavaRule {
|
||||
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
if (!node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) {
|
||||
ASTClassOrInterfaceDeclaration parentClassInterface = node
|
||||
.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
if (parentClassInterface != null && parentClassInterface.isInterface()) {
|
||||
addViolation(data, node, getMessage());
|
||||
}
|
||||
} else if (node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) {
|
||||
ASTClassOrInterfaceDeclaration parentClassInterface = node
|
||||
.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
ASTEnumDeclaration parentEnum = node.getFirstParentOfType(ASTEnumDeclaration.class);
|
||||
if (parentClassInterface != null
|
||||
&& (parentClassInterface.isInterface() || !parentClassInterface.isInterface() && node.isStatic())
|
||||
|| parentEnum != null) {
|
||||
if (!node.isNested()) return super.visit(node, data);
|
||||
|
||||
ASTClassOrInterfaceDeclaration parentClassOrInterface = node
|
||||
.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
ASTEnumDeclaration parentEnum = node.getFirstParentOfType(ASTEnumDeclaration.class);
|
||||
|
||||
if (node.isInterface() && node.isPublic()) {
|
||||
// a public interface
|
||||
if (parentClassOrInterface != null && parentClassOrInterface.isInterface()) {
|
||||
// within a interface
|
||||
addViolation(data, node, getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isInterface() && node.isStatic()) {
|
||||
// a static interface
|
||||
if (parentClassOrInterface != null || parentEnum != null) {
|
||||
// within a interface, class or enum
|
||||
addViolation(data, node, getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!node.isInterface() && (node.isPublic() || node.isStatic())) {
|
||||
// a public and/or static class
|
||||
if (parentClassOrInterface != null && parentClassOrInterface.isInterface()) {
|
||||
// within a interface
|
||||
addViolation(data, node, getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
|
@ -281,6 +281,18 @@ public enum MyEnum
|
||||
private static class MyInnerClass // violation detected by PMD
|
||||
{
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1480 false positive on public modifier used with inner interface in enum</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public enum TestEnum {
|
||||
;
|
||||
public interface EnumInnerInterface {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -58,6 +58,8 @@
|
||||
* [#1456](https://sourceforge.net/p/pmd/bugs/1456/): UnusedFormalParameter should ignore overriding methods
|
||||
* java-unusedcode/UnusedLocalVariable
|
||||
* [#1484](https://sourceforge.net/p/pmd/bugs/1484/): UnusedLocalVariable - false positive - parenthesis
|
||||
* java-unusedcode/UnusedModifier
|
||||
* [#1480](https://sourceforge.net/p/pmd/bugs/1480/): false positive on public modifier used with inner interface in enum
|
||||
* General
|
||||
* [#1455](https://sourceforge.net/p/pmd/bugs/1455/): PMD doesn't handle Java 8 explicit receiver parameters
|
||||
* [#1458](https://sourceforge.net/p/pmd/bugs/1458/): Performance degradation scanning large XML files with XPath custom rules
|
||||
|
Reference in New Issue
Block a user