1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.aludratest.codecheck.rule.pmd.uimap;
17
18 import org.aludratest.codecheck.rule.pmd.AbstractAludraTestRule;
19 import org.aludratest.dict.ActionWordLibrary;
20 import org.aludratest.service.gui.web.page.PageHelper;
21 import org.aludratest.service.gui.web.page.PageUtility;
22 import org.aludratest.testcase.AludraTestCase;
23
24 import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
25 import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
26
27
28
29
30
31
32
33
34 public class UIMapHelperImportRestriction extends AbstractAludraTestRule {
35
36 private static final Class<?>[] FORBIDDEN_IMPORT_PARENTS = { PageHelper.class, PageUtility.class, AludraTestCase.class,
37 ActionWordLibrary.class };
38
39 @Override
40 public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
41 if (!isUIMapHelperClass(node) && !isUIMapUtilityClass(node)) {
42 return null;
43 }
44
45
46 for (ASTImportDeclaration impNode : getImports(node)) {
47 checkImport(impNode, data);
48 }
49
50 return null;
51 }
52
53 private void checkImport(ASTImportDeclaration importNode, Object data) {
54 Class<?> importClass = importNode.getType();
55
56 for (Class<?> clazz : FORBIDDEN_IMPORT_PARENTS) {
57 if (clazz.isAssignableFrom(importClass)) {
58 addViolationWithMessage(data, importNode, "Illegal import for a UIMapHelper or UIMapUtility class");
59 return;
60 }
61 }
62 }
63
64 }