View Javadoc

1   package net.sourceforge.pmd.jsp.ast;
2   
3   import java.util.List;
4   
5   import net.sourceforge.pmd.AbstractRuleChainVisitor;
6   import net.sourceforge.pmd.Rule;
7   import net.sourceforge.pmd.RuleContext;
8   import net.sourceforge.pmd.rules.XPathRule;
9   import net.sourceforge.pmd.ast.CompilationUnit;
10  
11  public class JspRuleChainVisitor extends AbstractRuleChainVisitor {
12  
13      protected void indexNodes(List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
14          JspParserVisitor jspParserVisitor = new JspParserVisitorAdapter() {
15              // Perform a visitation of the AST to index nodes which need
16              // visiting by type
17              public Object visit(SimpleNode node, Object data) {
18                  indexNode(node);
19                  return super.visit(node, data);
20              }
21          };
22  
23          for (int i = 0; i < astCompilationUnits.size(); i++) {
24              jspParserVisitor.visit((ASTCompilationUnit)astCompilationUnits.get(i), ctx);
25          }
26      }
27  
28      protected void visit(Rule rule, net.sourceforge.pmd.ast.SimpleNode node, RuleContext ctx) {
29          // Rule better either be a JspParserVisitor, or a XPathRule
30          if (rule instanceof JspParserVisitor) {
31              ((SimpleNode) node).jjtAccept((JspParserVisitor) rule, ctx);
32          } else {
33              ((XPathRule) rule).evaluate(node, ctx);
34          }
35      }
36  }