01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.rules.imports;
04:
05: import net.sourceforge.pmd.AbstractRule;
06: import net.sourceforge.pmd.ast.ASTImportDeclaration;
07:
08: public class ImportFromSamePackageRule extends AbstractRule {
09:
10: public Object visit(ASTImportDeclaration importDecl, Object data) {
11: String packageName = importDecl.getScope()
12: .getEnclosingSourceFileScope().getPackageName();
13:
14: if (packageName != null
15: && packageName.equals(importDecl.getPackageName())) {
16: addViolation(data, importDecl);
17: }
18:
19: // special case
20: if (packageName == null
21: && importDecl.getPackageName().equals("")) {
22: addViolation(data, importDecl);
23: }
24: return data;
25: }
26: }
|