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