more refactoring and tests
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1082 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Oct 8, 2002
|
||||
* Time: 12:46:04 PM
|
||||
*/
|
||||
package test.net.sourceforge.pmd.ast;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.ast.ASTName;
|
||||
|
||||
public class ASTImportDeclarationTest extends TestCase {
|
||||
|
||||
public void testBasic() {
|
||||
ASTImportDeclaration i = new ASTImportDeclaration(1);
|
||||
assertTrue(!i.isImportOnDemand());
|
||||
i.setImportOnDemand();
|
||||
assertTrue(i.isImportOnDemand());
|
||||
}
|
||||
|
||||
public void testGetImportedNameNode() {
|
||||
ASTImportDeclaration i = new ASTImportDeclaration(1);
|
||||
ASTName name = new ASTName(2);
|
||||
i.jjtAddChild(name, 0);
|
||||
assertEquals(name, i.getImportedNameNode());
|
||||
}
|
||||
}
|
@ -22,6 +22,10 @@ public class ASTImportDeclaration extends SimpleNode {
|
||||
return isImportOnDemand;
|
||||
}
|
||||
|
||||
public ASTName getImportedNameNode() {
|
||||
return (ASTName)jjtGetChild(0);
|
||||
}
|
||||
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
|
@ -13,10 +13,9 @@ import net.sourceforge.pmd.ast.ASTName;
|
||||
public class DontImportJavaLangRule extends AbstractRule {
|
||||
|
||||
public Object visit(ASTImportDeclaration node, Object data) {
|
||||
ASTName importedType = (ASTName)node.jjtGetChild(0);
|
||||
if (importedType.getImage().startsWith("java.lang")
|
||||
&& !importedType.getImage().startsWith("java.lang.ref")
|
||||
&& !importedType.getImage().startsWith("java.lang.reflect")) {
|
||||
if (node.getImportedNameNode().getImage().startsWith("java.lang")
|
||||
&& !node.getImportedNameNode().getImage().startsWith("java.lang.ref")
|
||||
&& !node.getImportedNameNode().getImage().startsWith("java.lang.reflect")) {
|
||||
((RuleContext)data).getReport().addRuleViolation(createRuleViolation((RuleContext)data, node.getBeginLine()));
|
||||
}
|
||||
return data;
|
||||
|
Reference in New Issue
Block a user