Search in sources :

Example 1 with ErrorCollector

use of org.mozilla.javascript.ast.ErrorCollector in project hackpad by dropbox.

the class CompilerEnvirons method ideEnvirons.

/**
     * Returns a {@code CompilerEnvirons} suitable for using Rhino
     * in an IDE environment.  Most features are enabled by default.
     * The {@link ErrorReporter} is set to an {@link ErrorCollector}.
     */
public static CompilerEnvirons ideEnvirons() {
    CompilerEnvirons env = new CompilerEnvirons();
    env.setRecoverFromErrors(true);
    env.setRecordingComments(true);
    env.setStrictMode(true);
    env.setWarnTrailingComma(true);
    env.setLanguageVersion(170);
    env.setReservedKeywordAsIdentifier(true);
    env.setIdeMode(true);
    env.setErrorReporter(new ErrorCollector());
    return env;
}
Also used : ErrorCollector(org.mozilla.javascript.ast.ErrorCollector)

Example 2 with ErrorCollector

use of org.mozilla.javascript.ast.ErrorCollector in project pmd by pmd.

the class EcmascriptParser method parseEcmascript.

protected AstRoot parseEcmascript(final String sourceCode, final List<ParseProblem> parseProblems) throws ParseException {
    final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
    compilerEnvirons.setRecordingComments(parserOptions.isRecordingComments());
    compilerEnvirons.setRecordingLocalJsDocComments(parserOptions.isRecordingLocalJsDocComments());
    compilerEnvirons.setLanguageVersion(parserOptions.getRhinoLanguageVersion().getVersion());
    // Scope's don't appear to get set right without this
    compilerEnvirons.setIdeMode(true);
    compilerEnvirons.setWarnTrailingComma(true);
    // see bug #1150 "EmptyExpression" for valid statements!
    compilerEnvirons.setReservedKeywordAsIdentifier(true);
    // TODO We should do something with Rhino errors...
    final ErrorCollector errorCollector = new ErrorCollector();
    final Parser parser = new Parser(compilerEnvirons, errorCollector);
    // TODO Fix hardcode
    final String sourceURI = "unknown";
    final int beginLineno = 1;
    AstRoot astRoot = parser.parse(sourceCode, sourceURI, beginLineno);
    parseProblems.addAll(errorCollector.getErrors());
    return astRoot;
}
Also used : CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) ErrorCollector(org.mozilla.javascript.ast.ErrorCollector) Parser(org.mozilla.javascript.Parser) AstRoot(org.mozilla.javascript.ast.AstRoot)

Example 3 with ErrorCollector

use of org.mozilla.javascript.ast.ErrorCollector in project HL4A by HL4A.

the class CompilerEnvirons method ideEnvirons.

/**
 * Returns a {@code CompilerEnvirons} suitable for using Rhino
 * in an IDE environment.  Most features are enabled by default.
 * The {@link ErrorReporter} is set to an {@link ErrorCollector}.
 */
public static CompilerEnvirons ideEnvirons() {
    CompilerEnvirons env = new CompilerEnvirons();
    env.setRecoverFromErrors(true);
    env.setRecordingComments(true);
    env.setStrictMode(true);
    env.setWarnTrailingComma(true);
    env.setLanguageVersion(170);
    env.setReservedKeywordAsIdentifier(true);
    env.setIdeMode(true);
    env.setErrorReporter(new ErrorCollector());
    return env;
}
Also used : ErrorCollector(org.mozilla.javascript.ast.ErrorCollector)

Aggregations

ErrorCollector (org.mozilla.javascript.ast.ErrorCollector)3 CompilerEnvirons (org.mozilla.javascript.CompilerEnvirons)1 Parser (org.mozilla.javascript.Parser)1 AstRoot (org.mozilla.javascript.ast.AstRoot)1