1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.aludratest.codecheck.rule.pmd.page;
17
18 import org.aludratest.codecheck.rule.pmd.AbstractUsageRestrictionRule;
19 import org.aludratest.codecheck.rule.pmd.ClassMatcher;
20 import org.aludratest.codecheck.rule.pmd.UsageRestrictionCheck;
21 import org.aludratest.service.gui.web.page.Page;
22 import org.aludratest.service.gui.web.page.PageHelper;
23 import org.aludratest.service.gui.web.page.PageUtility;
24
25 import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
26
27
28
29
30
31
32
33
34 public class PageUtilityUsageRestriction extends AbstractUsageRestrictionRule {
35
36 @Override
37 protected UsageRestrictionCheck createUsageRestrictionCheck() {
38 UsageRestrictionCheck pageHelperUsageCheck = new UsageRestrictionCheck(new ClassMatcher() {
39 @Override
40 public boolean matches(Class<?> clazz) {
41 return isPageUtilityClass(clazz);
42 }
43 });
44
45 pageHelperUsageCheck.addAllowedUserClass(Page.class);
46 pageHelperUsageCheck.addAllowedUserClass(PageHelper.class);
47 pageHelperUsageCheck.addAllowedUserClass(PageUtility.class);
48 return pageHelperUsageCheck;
49 }
50
51 @Override
52 protected String getImportViolationMessage() {
53 return "PageHelper classes must only be used by Pages and other PageHelpers";
54 }
55
56 @Override
57 public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
58 if (!isPageHelperClass(node) && !isPageUtilityClass(node) && !isPageClass(node)) {
59 return super.visit(node, data);
60 }
61
62 return null;
63 }
64 }