Java Code Examples for org.mozilla.javascript.CompilerEnvirons#getErrorReporter()

The following examples show how to use org.mozilla.javascript.CompilerEnvirons#getErrorReporter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug708801Test.java    From rhino-android with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final String scriptClassName = "Main";

    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv
            .getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    AstRoot ast = p.parse(source.toString(), "<eval>", 1);
    IRFactory irf = new IRFactory(compilerEnv);
    ScriptNode tree = irf.transformTree(ast);

    Codegen codegen = new Codegen();
    codegen.setMainMethodClass(mainMethodClassName);
    codegen.compileToClassFile(compilerEnv, scriptClassName, tree,
            tree.getEncodedSource(), false);

    return tree;
}
 
Example 2
Source File: Bug689314Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 3
Source File: Bug688021Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 4
Source File: Bug688018Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 5
Source File: Bug687669Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 6
Source File: Bug688023Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 7
Source File: Bug689308Test.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 8
Source File: Bug689314Test.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 9
Source File: Bug688021Test.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 10
Source File: Bug688018Test.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 11
Source File: Bug687669Test.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 12
Source File: Bug689308Test.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private AstRoot parse(CharSequence cs) {
    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    return p.parse(cs.toString(), "<eval>", 1);
}
 
Example 13
Source File: ScriptValidator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validates the specified script.
 * 
 * @param script
 *            the script to validate.
 * @throws ParseException
 *             if an syntax error is found.
 */
protected void validateScript( String script ) throws ParseException
{
	if ( script == null )
	{
		return;
	}

	CompilerEnvirons compilerEnv = new CompilerEnvirons( );
	Parser jsParser = new Parser( compilerEnv,
			compilerEnv.getErrorReporter( ) );

	try
	{
		jsParser.parse( script, null, 0 );
	}
	catch ( EvaluatorException e )
	{
		int offset = -1;

		if ( scriptViewer != null )
		{
			String[] lines = script.split( "\n" ); //$NON-NLS-1$

			for ( int i = 0; i < e.lineNumber( ); i++ )
			{
				offset += lines[i].length( ) + 1;
			}
			offset += e.columnNumber( );
		}
		throw new ParseException( e.getLocalizedMessage( ), offset );
	}
}