/** * Reads the file with the given name and returns its contents as a String. */ private String readFile(String fileName) { String text; try { Reader r = new FileReader(fileName); try { text = Kit.readReader(r); } finally { r.close(); } } catch (IOException ex) { MessageDialogWrapper.showMessageDialog(this, ex.getMessage(), "Error reading "+fileName, JOptionPane.ERROR_MESSAGE); text = null; } return text; }
public Object run(Context cx) { if (modulePath != null || mainModule != null) { require = global.installRequire(cx, modulePath, sandboxed); } if (type == PROCESS_FILES) { processFiles(cx, args); } else if (type == EVAL_INLINE_SCRIPT) { Script script = loadScriptFromSource(cx, scriptText, "<command>", 1, null); if (script != null) { evaluateScript(script, cx, getGlobal()); } } else { throw Kit.codeBug(); } return null; }
public FilePanel openFile(String filePath, boolean showDebugPane) { String source; try { Reader r = new FileReader(filePath); try { source = Kit.readReader(r); } finally { r.close(); } SourceFile sourceFile = codeModel.newFile(source, filePath); sourceFile.setNewFile(false); sourceFile.setIsModified(false); return createFilePanel(sourceFile, showDebugPane); } catch (IOException ex) { MessageDialog.show(MainWindow.this, ex.getMessage(), "Error reading " + filePath, JOptionPane.ERROR_MESSAGE); return null; } }
private static JLineShellConsoleV1 getJLineShellConsoleV1( ClassLoader classLoader, Class<?> readerClass, Scriptable scope, Charset cs) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { // ConsoleReader reader = new ConsoleReader(); Constructor<?> c = readerClass.getConstructor(); Object reader = c.newInstance(); // reader.setBellEnabled(false); tryInvoke(reader, "setBellEnabled", BOOLEAN_ARG, Boolean.FALSE); // reader.addCompletor(new FlexibleCompletor(prefixes)); Class<?> completorClass = Kit.classOrNull(classLoader, "jline.Completor"); Object completor = Proxy.newProxyInstance(classLoader, new Class[] { completorClass }, new FlexibleCompletor(completorClass, scope)); tryInvoke(reader, "addCompletor", new Class[] {completorClass}, completor); return new JLineShellConsoleV1(reader, cs); }
private static JLineShellConsoleV2 getJLineShellConsoleV2( ClassLoader classLoader, Class<?> readerClass, Scriptable scope, Charset cs) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { // ConsoleReader reader = new ConsoleReader(); Constructor<?> c = readerClass.getConstructor(); Object reader = c.newInstance(); // reader.setBellEnabled(false); tryInvoke(reader, "setBellEnabled", BOOLEAN_ARG, Boolean.FALSE); // reader.addCompleter(new FlexibleCompletor(prefixes)); Class<?> completorClass = Kit.classOrNull(classLoader, "jline.console.completer.Completer"); Object completor = Proxy.newProxyInstance(classLoader, new Class[] { completorClass }, new FlexibleCompletor(completorClass, scope)); tryInvoke(reader, "addCompleter", new Class[] {completorClass}, completor); return new JLineShellConsoleV2(reader, cs); }
public Object run(Context cx) { if (useRequire) { require = global.installRequire(cx, modulePath, sandboxed); } if (type == PROCESS_FILES) { processFiles(cx, args); } else if (type == EVAL_INLINE_SCRIPT) { evalInlineScript(cx, scriptText); } else { throw Kit.codeBug(); } return null; }
public void quit(Context cx, int exitCode) { if (type == SYSTEM_EXIT) { System.exit(exitCode); return; } throw Kit.codeBug(); }
private static int addIndex(byte[] array, int pc, int index) { if (index < 0) throw Kit.codeBug(); if (index > 0xFFFF) throw Context.reportRuntimeError("Too complex regexp"); array[pc] = (byte)(index >> 8); array[pc + 1] = (byte)(index); return pc + 2; }
public Object set(Context cx, Object value) { if (xmlObject == null) { throw ScriptRuntime.undefWriteError(Undefined.instance, toString(), value); } // Assignment to descendants causes parse error on bad reference // and this should not be called if (isDescendants) throw Kit.codeBug(); xmlObject.putXMLProperty(this, value); return value; }