1 package net.sourceforge.pmd.rules.imports; 2 3 import net.sourceforge.pmd.AbstractRule; 4 import net.sourceforge.pmd.ast.ASTImportDeclaration; 5 import net.sourceforge.pmd.ast.SimpleNode; 6 7 public class DontImportJavaLang extends AbstractRule { 8 9 public Object visit(ASTImportDeclaration node, Object data) { 10 if (node.isStatic()) { 11 return data; 12 } 13 String img = ((SimpleNode) node.jjtGetChild(0)).getImage(); 14 if (img.startsWith("java.lang")) { 15 if (img.startsWith("java.lang.ref") 16 || img.startsWith("java.lang.reflect") 17 || img.startsWith("java.lang.annotation") 18 || img.startsWith("java.lang.instrument") 19 || img.startsWith("java.lang.management")) { 20 return data; 21 } 22 23 addViolation(data, node); 24 } 25 return data; 26 } 27 28 } 29 | Popular Tags |