本文整理汇总了Java中org.mozilla.javascript.CompilerEnvirons.getErrorReporter方法的典型用法代码示例。如果您正苦于以下问题:Java CompilerEnvirons.getErrorReporter方法的具体用法?Java CompilerEnvirons.getErrorReporter怎么用?Java CompilerEnvirons.getErrorReporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.CompilerEnvirons
的用法示例。
在下文中一共展示了CompilerEnvirons.getErrorReporter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
/**
* 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;
}
示例2: parse
import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
/**
* @return a tree representation of the parsed JavaScript file
* @throws IOException
*/
public ScriptOrFnNode parse() throws IOException {
if (nodeTree == null) {
Reader reader = new FileReader(jsFile);
CompilerEnvirons compilerEnv = new CompilerEnvirons();
ErrorReporter errorReporter = compilerEnv.getErrorReporter();
Parser parser = new Parser(compilerEnv, errorReporter);
String sourceURI;
try {
sourceURI = jsFile.getCanonicalPath();
} catch (IOException e) {
sourceURI = jsFile.toString();
}
nodeTree = parser.parse(reader, sourceURI, 1);
}
return nodeTree;
}
示例3: parse
import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
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);
}
示例4: parseIntoTree
import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
protected static AstRoot parseIntoTree(String formula) {
Context cx = Context.enter();
CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.initFromContext(cx);
ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
Parser parser = new Parser(compilerEnv, compilationErrorReporter);
AstRoot tree = parser.parse(formula, "(formula being checked by unit-checker)", 0);
Context.exit();
return tree;
}
示例5: validateScript
import org.mozilla.javascript.CompilerEnvirons; //导入方法依赖的package包/类
/**
* 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 );
}
}