KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > imports > DontImportJavaLang


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 JavaDoc visit(ASTImportDeclaration node, Object JavaDoc data) {
10         if (node.isStatic()) {
11             return data;
12         }
13         String JavaDoc 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