View Javadoc

    1   package net.sourceforge.pmd.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
    10  public class JavaRuleChainVisitor extends AbstractRuleChainVisitor {
    11
    12  	protected void indexNodes(List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
    13  		JavaParserVisitor javaParserVistor = new JavaParserVisitorAdapter() {
    14  			// Perform a visitation of the AST to index nodes which need
    15  			// visiting by type
    16  			public Object visit(SimpleJavaNode node, Object data) {
    17  				indexNode(node);
    18  				return super.visit(node, data);
    19  			}
    20  		};
    21
    22  		for (int i = 0; i < astCompilationUnits.size(); i++) {
    23  			javaParserVistor.visit((ASTCompilationUnit)astCompilationUnits.get(i), ctx);
    24  		}
    25  	}
    26
    27  	protected void visit(Rule rule, SimpleNode node, RuleContext ctx) {
    28  		// Rule better either be a JavaParserVisitor, or a XPathRule
    29  		if (rule instanceof XPathRule) {
    30  			((XPathRule)rule).evaluate(node, ctx);
    31  		} else {
    32  			((SimpleJavaNode)node).jjtAccept((JavaParserVisitor)rule, ctx);
    33  		}
    34  	}
    35  }