Package org.mozilla.javascript

Examples of org.mozilla.javascript.CompilerEnvirons


        }       
        return buffer.toString();
    }
   
    private static Parser createParser() {
        CompilerEnvirons env = new CompilerEnvirons();
        env.setIdeMode(true);
        env.setRecoverFromErrors(true);
        env.setStrictMode(false);
        env.setErrorReporter(new ErrorReporter() {

            public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
            }

            public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) {
View Full Code Here


  /**
   *
   */
  public WinkParser() {
    compilerEnv = new CompilerEnvirons();
    errorReporter = compilerEnv.getErrorReporter();
    parser = new Parser(compilerEnv, errorReporter);
    jsFiles = Common.newArrayList(1);
  }
View Full Code Here

        }


        private Class<?> compileClass( final Context pContext, final String pSourceName, final String pClassName, final Class<?> pSuperClass, final Class<?>[] pInterfaces) {

            final CompilerEnvirons environments = new CompilerEnvirons();
            environments.initFromContext(pContext);
            final ClassCompiler compiler = new ClassCompiler(environments);

            if (pSuperClass != null) {
                compiler.setTargetExtends(pSuperClass);
            }
View Full Code Here

public class JQueryScanner {

  public JQueryScanner(FileReader in) {
    final ErrorReporter reporter = new ToolErrorReporter(true);
    final CompilerEnvirons env = new CompilerEnvirons();
    final Parser parser = new Parser(env, reporter);

    try {
      parser.parse(in, null, 0);
    } catch (IOException e) {
View Full Code Here

   * @throws Exception
   *           压缩过程中的错误
   */
  public void compress(Reader reader, Writer writer, boolean keepLineno,
      int mode) throws Exception {
    Parser parser = new Parser(new CompilerEnvirons(), reporter);
    ScriptOrFnNode root = parser.parse(reader, null, 1);

    Environment env = new Environment(keepLineno, mode);
    GlobalScope globalScope = new GlobalScope();
    StatementList statements = new StatementList();
View Full Code Here

    }

    private AstRoot parse(
        String string, final String [] errors, final String [] warnings,
        boolean jsdoc) {
        CompilerEnvirons environment = new CompilerEnvirons();
        environment.setAllowKeywordAsObjectPropertyName(
            allowKeywordsAsObjectLiteralsKeys);

        TestErrorReporter testErrorReporter =
            new TestErrorReporter(errors, warnings) {
          @Override
          public EvaluatorException runtimeError(
               String message, String sourceName, int line, String lineSource,
               int lineOffset) {
             if (errors == null) {
               throw new UnsupportedOperationException();
             }
             return new EvaluatorException(
               message, sourceName, line, lineSource, lineOffset);
           }
        };
        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(jsdoc);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = null;
        try {
          script = p.parse(string, null, 0);
View Full Code Here

        return script;
    }

    private AstRoot parseAsReader(String string) throws IOException {
        CompilerEnvirons environment = new CompilerEnvirons();

        TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(true);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = p.parse(new StringReader(string), null, 0);

        assertTrue(testErrorReporter.hasEncounteredAllErrors());
View Full Code Here

   * @throws EvaluatorException - Fatal exception thrown while
   * parsing JavaScript source
   */
  protected void parse() throws EvaluatorException {
    // Parse script source
    CompilerEnvirons ce = new CompilerEnvirons();
    ScriptParserErrorReporter errorReporter = new ScriptParserErrorReporter();
   
    ce.setGenerateDebugInfo(true);   
    ce.initFromContext(ContextFactory.getGlobal().enterContext());
    ce.setErrorReporter(errorReporter);
   
    Parser p = new Parser(ce, errorReporter);
    ScriptOrFnNode ast = p.parse(this.scriptSource, "script", 0);
   
    searchAstForNodes(ast);
View Full Code Here

public class ArrayLiteralTest {
 
  private static ArrayLiteral getLiteralNode(String literalStr) throws InvalidLiteralNode {
    String scriptSource = "var lit = " + literalStr;
   
    CompilerEnvirons ce = new CompilerEnvirons();
    ScriptParserErrorReporter errorReporter = new ScriptParserErrorReporter();
   
    ce.setGenerateDebugInfo(true);   
    ce.initFromContext(ContextFactory.getGlobal().enterContext());
    ce.setErrorReporter(errorReporter);
   
    Parser p = new Parser(ce, errorReporter);
    ScriptOrFnNode ast = p.parse(scriptSource, "script", 0);
   
    return new ArrayLiteral(ast.getFirstChild().getFirstChild().getFirstChild());
View Full Code Here

  }
 
 
  protected void parse() throws EvaluatorException {
    // Parse script source
    CompilerEnvirons ce = new CompilerEnvirons();
    ScriptParserErrorReporter errorReporter = new ScriptParserErrorReporter();
   
    ce.setGenerateDebugInfo(true);   
    ce.initFromContext(ContextFactory.getGlobal().enterContext());
    ce.setErrorReporter(errorReporter);
   
    Parser p = new Parser(ce, errorReporter);
    ScriptOrFnNode ast = p.parse(this.scriptSource, "script", 0);
   
    recursiveParse(ast);
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.CompilerEnvirons

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.