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.ast;
5   
6   import java.io.Reader;
7   import java.io.StringReader;
8   import java.io.StringWriter;
9   
10  import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions;
11  
12  public abstract class EcmascriptParserTestBase {
13      public ASTAstRoot parse(String code) {
14          EcmascriptParser parser = new EcmascriptParser(new EcmascriptParserOptions());
15          Reader sourceCode = new StringReader(code);
16          return (ASTAstRoot)parser.parse(sourceCode);
17      }
18  
19      public ASTAstRoot parse18(String code) {
20          EcmascriptParserOptions parserOptions = new EcmascriptParserOptions();
21          parserOptions.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_1_8);
22          EcmascriptParser parser = new EcmascriptParser(parserOptions);
23          Reader sourceCode = new StringReader(code);
24          return (ASTAstRoot)parser.parse(sourceCode);
25      }
26  
27      public String dump(EcmascriptNode<?> node) {
28          DumpFacade dumpFacade = new DumpFacade();
29          StringWriter writer = new StringWriter();
30          dumpFacade.initializeWith(writer, "", true, node);
31          dumpFacade.visit(node, "");
32          return writer.toString();
33      }
34  }