ALT Linux repos
Group :: Development/Java
RPM: rhino
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
Patch: rhino-class-loader.patch
Download
Download
--- rhino1_7R2pre/toolsrc/org/mozilla/javascript/tools/shell/ShellLine.java.orig 2008-07-28 10:45:18.000000000 -0400
+++ rhino1_7R2pre/toolsrc/org/mozilla/javascript/tools/shell/ShellLine.java 2008-11-14 17:58:42.682535066 -0500
@@ -40,12 +40,17 @@
package org.mozilla.javascript.tools.shell;
import java.io.InputStream;
+import java.io.IOException;
import java.util.List;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationTargetException;
+import jline.ConsoleReader;
+import jline.Completor;
+import jline.ConsoleReaderInputStream;
+
import org.mozilla.javascript.Kit;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
@@ -59,39 +64,13 @@
public class ShellLine {
public static InputStream getStream(Scriptable scope) {
- // We don't want a compile-time dependency on the JLine jar, so use
- // reflection to load and reference the JLine classes.
- ClassLoader classLoader = ShellLine.class.getClassLoader();
- Class<?> readerClass = Kit.classOrNull(classLoader, "jline.ConsoleReader");
- if (readerClass == null)
- return null;
try {
- // ConsoleReader reader = new ConsoleReader();
- Constructor<?> c = readerClass.getConstructor();
- Object reader = c.newInstance();
-
- // reader.setBellEnabled(false);
- Method m = readerClass.getMethod("setBellEnabled", Boolean.TYPE);
- m.invoke(reader, Boolean.FALSE);
-
- // reader.addCompletor(new FlexibleCompletor(prefixes));
- Class<?> completorClass = Kit.classOrNull(classLoader,
- "jline.Completor");
- m = readerClass.getMethod("addCompletor", completorClass);
- Object completor = Proxy.newProxyInstance(classLoader,
- new Class[] { completorClass },
- new FlexibleCompletor(completorClass, scope));
- m.invoke(reader, completor);
-
- // return new ConsoleReaderInputStream(reader);
- Class<?> inputStreamClass = Kit.classOrNull(classLoader,
- "jline.ConsoleReaderInputStream");
- c = inputStreamClass.getConstructor(readerClass);
- return (InputStream) c.newInstance(reader);
+ ConsoleReader reader = new ConsoleReader();
+ reader.setBellEnabled(false);
+ reader.addCompletor(new FlexibleCompletor(scope));
+ return new ConsoleReaderInputStream(reader);
+ } catch (IOException e) {
} catch (NoSuchMethodException e) {
- } catch (InstantiationException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
}
return null;
}
@@ -102,29 +81,17 @@
* complete on a line that it can fully recognize (only composed of
* completed strings). This one completes whatever came before.
*/
-class FlexibleCompletor implements java.lang.reflect.InvocationHandler {
- private Method completeMethod;
+class FlexibleCompletor implements Completor {
private Scriptable global;
- FlexibleCompletor(Class<?> completorClass, Scriptable global)
+ FlexibleCompletor(Scriptable global)
throws NoSuchMethodException
{
this.global = global;
- this.completeMethod = completorClass.getMethod("complete", String.class,
- Integer.TYPE, List.class);
- }
-
- @SuppressWarnings({"unchecked"})
- public Object invoke(Object proxy, Method method, Object[] args) {
- if (method.equals(this.completeMethod)) {
- int result = complete((String)args[0], ((Integer) args[1]).intValue(),
- (List<String>) args[2]);
- return new Integer(result);
- }
- throw new NoSuchMethodError(method.toString());
}
- public int complete(String buffer, int cursor, List<String> candidates) {
+ @SuppressWarnings({"unchecked"})
+ public int complete(String buffer, int cursor, List candidates) {
// Starting from "cursor" at the end of the buffer, look backward
// and collect a list of identifiers separated by (possibly zero)
// dots. Then look up each identifier in turn until getting to the