KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.rules.imports;
5
6 import net.sourceforge.pmd.AbstractRule;
7 import net.sourceforge.pmd.ast.ASTImportDeclaration;
8
9 public class ImportFromSamePackageRule extends AbstractRule {
10
11     public Object JavaDoc visit(ASTImportDeclaration importDecl, Object JavaDoc data) {
12         String JavaDoc packageName = importDecl.getScope().getEnclosingSourceFileScope().getPackageName();
13
14         if (packageName != null && packageName.equals(importDecl.getPackageName())) {
15             addViolation(data, importDecl);
16         }
17
18         // special case
19
if (packageName == null && importDecl.getPackageName().equals("")) {
20             addViolation(data, importDecl);
21         }
22         return data;
23     }
24 }
25
Popular Tags