1 |
| |
2 |
| |
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 |
7
| public Object visit(ASTImportDeclaration importDecl, Object data) {
|
12 |
7
| String packageName = importDecl.getScope().getEnclosingSourceFileScope().getPackageName();
|
13 |
| |
14 |
7
| if (packageName != null && packageName.equals(importDecl.getPackageName())) {
|
15 |
3
| addViolation(data, importDecl);
|
16 |
| } |
17 |
| |
18 |
| |
19 |
7
| if (packageName == null && importDecl.getPackageName().equals("")) {
|
20 |
0
| addViolation(data, importDecl);
|
21 |
| } |
22 |
7
| return data;
|
23 |
| } |
24 |
| } |