01: package net.sourceforge.pmd.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:
10: public class JavaRuleChainVisitor extends AbstractRuleChainVisitor {
11:
12: protected void indexNodes(
13: List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
14: JavaParserVisitor javaParserVistor = new JavaParserVisitorAdapter() {
15: // Perform a visitation of the AST to index nodes which need
16: // visiting by type
17: public Object visit(SimpleJavaNode 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: javaParserVistor.visit(
25: (ASTCompilationUnit) astCompilationUnits.get(i),
26: ctx);
27: }
28: }
29:
30: protected void visit(Rule rule, SimpleNode node, RuleContext ctx) {
31: // Rule better either be a JavaParserVisitor, or a XPathRule
32: if (rule instanceof XPathRule) {
33: ((XPathRule) rule).evaluate(node, ctx);
34: } else {
35: ((SimpleJavaNode) node).jjtAccept((JavaParserVisitor) rule,
36: ctx);
37: }
38: }
39: }
|