org.mozilla.javascript.tools.ToolErrorReporter Java Examples
The following examples show how to use
org.mozilla.javascript.tools.ToolErrorReporter.
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: Main.java From astor with GNU General Public License v2.0 | 6 votes |
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) { try { processFile(cx, scope, filename); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", filename, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } }
Example #2
Source File: Main.java From astor with GNU General Public License v2.0 | 6 votes |
static void evalInlineScript(Context cx, String scriptText) { try { Script script = cx.compileString(scriptText, "<command>", 1, null); if (script != null) { script.exec(cx, getShellScope()); } } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } }
Example #3
Source File: Main.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Execute the given arguments, but don't System.exit at the end. */ public static int exec(String origArgs[]) { errorReporter = new ToolErrorReporter(false, global.getErr()); shellContextFactory.setErrorReporter(errorReporter); String[] args = processOptions(origArgs); if (processStdin) { fileList.add(null); } if (!global.initialized) { global.init(shellContextFactory); } IProxy iproxy = new IProxy(IProxy.PROCESS_FILES); iproxy.args = args; shellContextFactory.call(iproxy); return exitCode; }
Example #4
Source File: ScriptDialog.java From hop with Apache License 2.0 | 6 votes |
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; }
Example #5
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) { try { processFile(cx, scope, filename); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", filename, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } }
Example #6
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
/** * Execute the given arguments, but don't System.exit at the end. */ public static int exec(String origArgs[]) { errorReporter = new ToolErrorReporter(false, global.getErr()); shellContextFactory.setErrorReporter(errorReporter); String[] args = processOptions(origArgs); if (exitCode > 0) { return exitCode; } if (processStdin) { fileList.add(null); } if (!global.initialized) { global.init(shellContextFactory); } IProxy iproxy = new IProxy(IProxy.PROCESS_FILES); iproxy.args = args; shellContextFactory.call(iproxy); return exitCode; }
Example #7
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
static void evalInlineScript(Context cx, String scriptText) { try { Script script = cx.compileString(scriptText, "<command>", 1, null); if (script != null) { script.exec(cx, getShellScope()); } } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } }
Example #8
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
private void addError(String messageId, String arg) { String msg; if (arg == null) { msg = ToolErrorReporter.getMessage(messageId); } else { msg = ToolErrorReporter.getMessage(messageId, arg); } addFormatedError(msg); }
Example #9
Source File: ScriptValuesModDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; }
Example #10
Source File: ScriptDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; }
Example #11
Source File: Main.java From astor with GNU General Public License v2.0 | 5 votes |
private void addError(String messageId, String arg) { String msg; if (arg == null) { msg = ToolErrorReporter.getMessage(messageId); } else { msg = ToolErrorReporter.getMessage(messageId, arg); } addFormatedError(msg); }
Example #12
Source File: Main.java From astor with GNU General Public License v2.0 | 5 votes |
public Main() { reporter = new ToolErrorReporter(true); compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compiler = new ClassCompiler(compilerEnv); }
Example #13
Source File: Main.java From astor with GNU General Public License v2.0 | 5 votes |
static void processFiles(Context cx, String[] args) { // define "arguments" array in the top-level object: // need to allocate new array since newArray requires instances // of exactly Object[], not ObjectSubclass[] Object[] array = new Object[args.length]; System.arraycopy(args, 0, array, 0, args.length); Scriptable argsObj = cx.newArray(global, array); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); for (String file: fileList) { try { processSource(cx, file); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", file, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } } }
Example #14
Source File: Global.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Print a help message. * * This method is defined as a JavaScript function. */ public static void help(Context cx, Scriptable thisObj, Object[] args, Function funObj) { PrintStream out = getInstance(funObj).getOut(); out.println(ToolErrorReporter.getMessage("msg.help")); }
Example #15
Source File: SwitchGenerator.java From astor with GNU General Public License v2.0 | 5 votes |
private EvaluatorException on_same_pair_fail(IdValuePair a, IdValuePair b) { int line1 = a.getLineNumber(), line2 = b.getLineNumber(); if (line2 > line1) { int tmp = line1; line1 = line2; line2 = tmp; } String error_text = ToolErrorReporter.getMessage( "msg.idswitch.same_string", a.id, new Integer(line2)); return R.runtimeError(error_text, source_file, line1, null, 0); }
Example #16
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public Main() { reporter = new ToolErrorReporter(true); compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compiler = new ClassCompiler(compilerEnv); }
Example #17
Source File: ScriptValuesModDialog.java From hop with Apache License 2.0 | 5 votes |
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; }
Example #18
Source File: ScriptValuesMetaModDialog.java From hop with Apache License 2.0 | 5 votes |
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree, evn ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; }
Example #19
Source File: SwitchGenerator.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
private EvaluatorException on_same_pair_fail(IdValuePair a, IdValuePair b) { int line1 = a.getLineNumber(), line2 = b.getLineNumber(); if (line2 > line1) { int tmp = line1; line1 = line2; line2 = tmp; } String error_text = ToolErrorReporter.getMessage( "msg.idswitch.same_string", a.id, new Integer(line2)); return R.runtimeError(error_text, source_file, line1, null, 0); }
Example #20
Source File: Global.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Print a help message. * * This method is defined as a JavaScript function. */ public static void help(Context cx, Scriptable thisObj, Object[] args, Function funObj) { PrintStream out = getInstance(funObj).getOut(); out.println(ToolErrorReporter.getMessage("msg.help")); }
Example #21
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
static void processFiles(Context cx, String[] args) { // define "arguments" array in the top-level object: // need to allocate new array since newArray requires instances // of exactly Object[], not ObjectSubclass[] Object[] array = new Object[args.length]; System.arraycopy(args, 0, array, 0, args.length); Scriptable argsObj = cx.newArray(global, array); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); for (String file: fileList) { try { processSource(cx, file); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", file, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } } }
Example #22
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private void option_error(String str) { print_error( ToolErrorReporter.getMessage("msg.idswitch.bad_invocation", str)); }
Example #23
Source File: Main.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Print a usage message. */ private static void badUsage(String s) { System.err.println(ToolErrorReporter.getMessage( "msg.jsc.bad.usage", Main.class.getName(), s)); }
Example #24
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private int process_options(String[] args) { int status = 1; boolean show_usage = false; boolean show_version = false; int N = args.length; L: for (int i = 0; i != N; ++i) { String arg = args[i]; int arg_length = arg.length(); if (arg_length >= 2) { if (arg.charAt(0) == '-') { if (arg.charAt(1) == '-') { if (arg_length == 2) { args[i] = null; break; } if (arg.equals("--help")) { show_usage = true; } else if (arg.equals("--version")) { show_version = true; } else { option_error(ToolErrorReporter.getMessage( "msg.idswitch.bad_option", arg)); status = -1; break L; } } else { for (int j = 1; j != arg_length; ++j) { char c = arg.charAt(j); switch (c) { case 'h': show_usage = true; break; default: option_error( ToolErrorReporter.getMessage( "msg.idswitch.bad_option_char", String.valueOf(c))); status = -1; break L; } } } args[i] = null; } } } if (status == 1) { if (show_usage) { show_usage(); status = 0; } if (show_version) { show_version(); status = 0; } } if (status != 1) { System.exit(status); } return remove_nulls(args); }
Example #25
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private void show_usage() { System.out.println( ToolErrorReporter.getMessage("msg.idswitch.usage")); System.out.println(); }
Example #26
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private void show_version() { System.out.println( ToolErrorReporter.getMessage("msg.idswitch.version")); }
Example #27
Source File: Global.java From astor with GNU General Public License v2.0 | 4 votes |
static RuntimeException reportRuntimeError(String msgId, String msgArg) { String message = ToolErrorReporter.getMessage(msgId, msgArg); return Context.reportRuntimeError(message); }
Example #28
Source File: Global.java From astor with GNU General Public License v2.0 | 4 votes |
static RuntimeException reportRuntimeError(String msgId) { String message = ToolErrorReporter.getMessage(msgId); return Context.reportRuntimeError(message); }
Example #29
Source File: Global.java From astor with GNU General Public License v2.0 | 4 votes |
public int runDoctest(Context cx, Scriptable scope, String session, String sourceName, int lineNumber) { doctestCanonicalizations = new HashMap<String,String>(); String[] lines = session.split("[\n\r]+"); String prompt0 = this.prompts[0].trim(); String prompt1 = this.prompts[1].trim(); int testCount = 0; int i = 0; while (i < lines.length && !lines[i].trim().startsWith(prompt0)) { i++; // skip lines that don't look like shell sessions } while (i < lines.length) { String inputString = lines[i].trim().substring(prompt0.length()); inputString += "\n"; i++; while (i < lines.length && lines[i].trim().startsWith(prompt1)) { inputString += lines[i].trim().substring(prompt1.length()); inputString += "\n"; i++; } String expectedString = ""; while (i < lines.length && !lines[i].trim().startsWith(prompt0)) { expectedString += lines[i] + "\n"; i++; } PrintStream savedOut = this.getOut(); PrintStream savedErr = this.getErr(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); this.setOut(new PrintStream(out)); this.setErr(new PrintStream(err)); String resultString = ""; ErrorReporter savedErrorReporter = cx.getErrorReporter(); cx.setErrorReporter(new ToolErrorReporter(false, this.getErr())); try { testCount++; Object result = cx.evaluateString(scope, inputString, "doctest input", 1, null); if (result != Context.getUndefinedValue() && !(result instanceof Function && inputString.trim().startsWith("function"))) { resultString = Context.toString(result); } } catch (RhinoException e) { ToolErrorReporter.reportException(cx.getErrorReporter(), e); } finally { this.setOut(savedOut); this.setErr(savedErr); cx.setErrorReporter(savedErrorReporter); resultString += err.toString() + out.toString(); } if (!doctestOutputMatches(expectedString, resultString)) { String message = "doctest failure running:\n" + inputString + "expected: " + expectedString + "actual: " + resultString + "\n"; if (sourceName != null) throw Context.reportRuntimeError(message, sourceName, lineNumber+i-1, null, 0); else throw Context.reportRuntimeError(message); } } return testCount; }
Example #30
Source File: Main.java From astor with GNU General Public License v2.0 | 4 votes |
private void option_error(String str) { print_error( ToolErrorReporter.getMessage("msg.idswitch.bad_invocation", str)); }