View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.vm;
5   
6   import java.io.Writer;
7   
8   import net.sf.saxon.sxpath.IndependentContext;
9   import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
10  import net.sourceforge.pmd.lang.Parser;
11  import net.sourceforge.pmd.lang.ParserOptions;
12  import net.sourceforge.pmd.lang.VisitorStarter;
13  import net.sourceforge.pmd.lang.XPathHandler;
14  import net.sourceforge.pmd.lang.ast.Node;
15  import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler;
16  import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
17  import net.sourceforge.pmd.lang.vm.ast.AbstractVmNode;
18  import net.sourceforge.pmd.lang.vm.rule.VmRuleViolationFactory;
19  
20  /**
21   * Implementation of LanguageVersionHandler for the VM parser.
22   * 
23   */
24  public class VmHandler extends AbstractLanguageVersionHandler {
25  
26      @Override
27      public XPathHandler getXPathHandler() {
28          return new AbstractASTXPathHandler() {
29              public void initialize() {
30              }
31  
32              public void initialize(final IndependentContext context) {
33              }
34          };
35      }
36  
37      public RuleViolationFactory getRuleViolationFactory() {
38          return VmRuleViolationFactory.INSTANCE;
39      }
40  
41      public Parser getParser(final ParserOptions parserOptions) {
42          return new VmParser(parserOptions);
43      }
44  
45      @Override
46      public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
47          return new VisitorStarter() {
48              public void start(final Node rootNode) {
49              	((AbstractVmNode) rootNode).dump(prefix, recurse, writer);
50              }
51          };
52      }
53  }