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:
Tom Copeland
2002-10-08 16:51:29 +00:00
parent 519a8b9c4a
commit c3bae32b11
3 changed files with 34 additions and 4 deletions

View File

@ -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());
}
}

View File

@ -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) {

View File

@ -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;