Fixed bug 2606609 - False "UnusedImports" positive in package-info.java

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6874 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch 2009-02-23 17:45:51 +00:00
parent 2577acd87e
commit eeb8b10892
3 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,7 @@
Fixed bug 2590258 - NPE with nicerhtml output
Fixed bug 2317099 - False + in SimplifyCondition
Fixed bug 2606609 - False "UnusedImports" positive in package-info.java
New rule:
StrictExceptions : AvoidCatchingGenericException

View File

@ -203,7 +203,7 @@ public class Foo {
]]></code>
</test-code>
<test-code regressionTest="false">
<test-code>
<description><![CDATA[
Bug 2606609 : False "UnusedImports" positive in package-info.java
]]></description>
@ -212,7 +212,8 @@ Bug 2606609 : False "UnusedImports" positive in package-info.java
@DefaultAnnotation(NonNull.class)
package net.sourceforge.pmd.test;
public class Bug {}
import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull;
]]></code>
</test-code>

View File

@ -8,6 +8,7 @@ import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
import net.sourceforge.pmd.ast.ASTCompilationUnit;
import net.sourceforge.pmd.ast.ASTImportDeclaration;
import net.sourceforge.pmd.ast.ASTName;
import net.sourceforge.pmd.ast.ASTPackageDeclaration;
import net.sourceforge.pmd.ast.Comment;
import net.sourceforge.pmd.ast.FormalComment;
import net.sourceforge.pmd.ast.SimpleJavaNode;
@ -27,6 +28,14 @@ public class UnusedImportsRule extends AbstractRule {
imports.clear();
super.visit(node, data);
visitComments(node);
/* special handling for Bug 2606609 : False "UnusedImports" positive in package-info.java
* package annotations are processed before the import clauses so they need to be examined
* again later on.
*/
if (node.jjtGetNumChildren()>0 && node.jjtGetChild(0) instanceof ASTPackageDeclaration) {
visit((ASTPackageDeclaration)node.jjtGetChild(0), data);
}
for (ImportWrapper wrapper : imports) {
addViolation(data, wrapper.getNode(), wrapper.getFullName());
}