View Javadoc

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