View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.ecmascript;
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.ecmascript.ast.DumpFacade;
17  import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptNode;
18  import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory;
19  import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
20  
21  /**
22   * Implementation of LanguageVersionHandler for the ECMAScript Version 3.
23   */
24  public class Ecmascript3Handler extends AbstractLanguageVersionHandler {
25  
26      @Override
27      public XPathHandler getXPathHandler() {
28  	return new AbstractASTXPathHandler() {
29  	    public void initialize() {
30  	    }
31  
32  	    public void initialize(IndependentContext context) {
33  	    }
34  	};
35      }
36  
37      public RuleViolationFactory getRuleViolationFactory() {
38  	return EcmascriptRuleViolationFactory.INSTANCE;
39      }
40  
41      @Override
42      public ParserOptions getDefaultParserOptions() {
43  	return new EcmascriptParserOptions();
44      }
45  
46      public Parser getParser(ParserOptions parserOptions) {
47  	return new Ecmascript3Parser(parserOptions);
48      }
49  
50      @Override
51      public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
52  	return new VisitorStarter() {
53  	    public void start(Node rootNode) {
54  		new DumpFacade().initializeWith(writer, prefix, recurse, (EcmascriptNode) rootNode);
55  	    }
56  	};
57      }
58  }