forked from phoedos/pmd
refactored, new generalized importsPackage(packageName) function in superclass
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4612 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -5,6 +5,7 @@ package net.sourceforge.pmd;
|
||||
|
||||
import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.ast.Node;
|
||||
import net.sourceforge.pmd.ast.SimpleNode;
|
||||
@ -246,4 +247,16 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
|
||||
public static boolean isQualifiedName(SimpleNode node) {
|
||||
return node.getImage().indexOf('.') != -1;
|
||||
}
|
||||
|
||||
public static boolean importsPackage(ASTCompilationUnit node, String packageName) {
|
||||
|
||||
List nodes = node.findChildrenOfType(ASTImportDeclaration.class);
|
||||
for (Iterator i = nodes.iterator(); i.hasNext();) {
|
||||
ASTImportDeclaration n = (ASTImportDeclaration) i.next();
|
||||
if (n.getPackageName().startsWith(packageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -125,16 +125,9 @@ public class CloseResource extends AbstractRule {
|
||||
addViolation(data, id, clazz.getImage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean importsJavaSqlPackage(ASTCompilationUnit node) {
|
||||
List nodes = node.findChildrenOfType(ASTImportDeclaration.class);
|
||||
for (Iterator i = nodes.iterator(); i.hasNext();) {
|
||||
ASTImportDeclaration n = (ASTImportDeclaration) i.next();
|
||||
if (n.getPackageName().startsWith("java.sql")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return importsPackage(node, "java.sql");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user