Merge branch 'issue-215' into pmd/5.4.x

This commit is contained in:
Andreas Dangel
2017-02-05 17:50:57 +01:00
4 changed files with 34 additions and 4 deletions

View File

@@ -53,7 +53,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
@Override
public boolean isFinal() {
if (isInterfaceMember()) {
if (isAnnotationMember() || isInterfaceMember()) {
return true;
}
return super.isFinal();
@@ -61,7 +61,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
@Override
public boolean isPrivate() {
if (isInterfaceMember()) {
if (isAnnotationMember() || isInterfaceMember()) {
return false;
}
return super.isPrivate();
@@ -69,7 +69,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
@Override
public boolean isPackagePrivate() {
if (isInterfaceMember()) {
if (isAnnotationMember() || isInterfaceMember()) {
return false;
}
return super.isPackagePrivate();
@@ -77,12 +77,19 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
@Override
public boolean isProtected() {
if (isInterfaceMember()) {
if (isAnnotationMember() || isInterfaceMember()) {
return false;
}
return super.isProtected();
}
public boolean isAnnotationMember() {
if (jjtGetParent().jjtGetParent() instanceof ASTAnnotationTypeBody) {
return true;
}
return false;
}
public boolean isInterfaceMember() {
if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
return false;

View File

@@ -51,6 +51,15 @@ public class ASTFieldDeclarationTest extends ParserTst {
" String[] foo;" + PMD.EOL +
"}";
@Test
public void testWithAnnotation() {
ASTCompilationUnit cu = parseJava15(TEST5);
ASTFieldDeclaration node = cu.findDescendantsOfType(ASTFieldDeclaration.class).get(0);
assertFalse(node.isInterfaceMember());
assertTrue(node.isAnnotationMember());
}
private static final String TEST2 =
"class Foo {" + PMD.EOL +
" String[][][] foo;" + PMD.EOL +
@@ -67,6 +76,8 @@ public class ASTFieldDeclarationTest extends ParserTst {
" private int x;" + PMD.EOL +
"}";
private static final String TEST5 = "public @interface Foo {" + PMD.EOL + " int BAR = 6;" + PMD.EOL + "}";
@Test
public void testGetVariableName() {
int id = 0;

View File

@@ -1309,6 +1309,16 @@ public class SomeClass {
<code><![CDATA[
public class SomeClass {
private float someNumber = 0.1f;
}
]]></code>
</test-code>
<test-code>
<description>#215 - False positive for annotation fields</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public @interface SomeAnnotation {
int CONSTANT = 0;
}
]]></code>
</test-code>

View File

@@ -20,6 +20,8 @@ This is a bug fixing release, no major changes were introduced.
### Fixed Issues
* java-optimizations
* [#215](https://github.com/pmd/pmd/issues/215): \[java] RedundantFieldInitializer report for annotation field not explicitly marked as final
### API Changes