kunfei 3 лет назад
Родитель
Сommit
f66ee9ce31

+ 50 - 75
rhino/src/main/java/com/script/AbstractScriptEngine.kt

@@ -1,111 +1,86 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.io.Reader;
+import java.io.Reader
 
-@SuppressWarnings("unused")
-public abstract class AbstractScriptEngine implements ScriptEngine {
+abstract class AbstractScriptEngine(val bindings: Bindings? = null) : ScriptEngine {
 
-    protected ScriptContext context = new SimpleScriptContext();
+    override var context: ScriptContext = SimpleScriptContext()
 
-    public AbstractScriptEngine() {
-    }
-
-    public AbstractScriptEngine(Bindings n) {
-        this();
-        if (n == null) {
-            throw new NullPointerException("n is null");
-        }
-        this.context.setBindings(n, 100);
-    }
-
-    @Override
-    public void setContext(ScriptContext ctxt) {
-        if (ctxt == null) {
-            throw new NullPointerException("null context");
+    init {
+        bindings?.let {
+            context.setBindings(bindings, 100)
         }
-        this.context = ctxt;
-    }
-
-    @Override
-    public ScriptContext getContext() {
-        return this.context;
     }
 
-    @Override
-    public Bindings getBindings(int scope) {
+    override fun getBindings(scope: Int): Bindings? {
         if (scope == 200) {
-            return this.context.getBindings(200);
+            return context.getBindings(200)
         }
         if (scope == 100) {
-            return this.context.getBindings(100);
+            return context.getBindings(100)
         }
-        throw new IllegalArgumentException("Invalid scope value.");
+        throw IllegalArgumentException("Invalid scope value.")
     }
 
-    @Override
-    public void setBindings(Bindings bindings, int scope) {
-        if (scope == 200) {
-            this.context.setBindings(bindings, 200);
-        } else if (scope == 100) {
-            this.context.setBindings(bindings, 100);
-        } else {
-            throw new IllegalArgumentException("Invalid scope value.");
+    override fun setBindings(bindings: Bindings?, scope: Int) {
+        when (scope) {
+            200 -> {
+                context.setBindings(bindings, 200)
+            }
+            100 -> {
+                context.setBindings(bindings, 100)
+            }
+            else -> {
+                throw IllegalArgumentException("Invalid scope value.")
+            }
         }
     }
 
-    @Override
-    public void put(String key, Object value) {
-        Bindings nn = this.getBindings(100);
+    override fun put(key: String, value: Any?) {
+        val nn = getBindings(100)
         if (nn != null) {
-            nn.put(key, value);
+            nn[key] = value
         }
     }
 
-    @Override
-    public Object get(String key) {
-        Bindings nn = this.getBindings(100);
-        if (nn != null) {
-            return nn.get(key);
-        }
-        return null;
+    override fun get(key: String): Any? {
+        val nn = getBindings(100)
+        return nn?.get(key)
     }
 
-    @Override
-    public Object eval(Reader reader, Bindings bindings) throws ScriptException {
-        return this.eval(reader, this.getScriptContext(bindings));
+    @Throws(ScriptException::class)
+    override fun eval(reader: Reader, bindings: Bindings): Any? {
+        return this.eval(reader, getScriptContext(bindings))
     }
 
-    @Override
-    public Object eval(String script, Bindings bindings) throws ScriptException {
-        return this.eval(script, this.getScriptContext(bindings));
+    @Throws(ScriptException::class)
+    override fun eval(script: String, bindings: Bindings): Any? {
+        return this.eval(script, getScriptContext(bindings))
     }
 
-    @Override
-    public Object eval(Reader reader) throws ScriptException {
-        return this.eval(reader, this.context);
+    @Throws(ScriptException::class)
+    override fun eval(reader: Reader): Any? {
+        return this.eval(reader, context)
     }
 
-    @Override
-    public Object eval(String script) throws ScriptException {
-        return this.eval(script, this.context);
+    @Throws(ScriptException::class)
+    override fun eval(script: String): Any? {
+        return this.eval(script, context)
     }
 
-    protected ScriptContext getScriptContext(Bindings nn) {
-        SimpleScriptContext ctxt = new SimpleScriptContext();
-        Bindings gs = this.getBindings(200);
+    protected fun getScriptContext(nn: Bindings): ScriptContext {
+        val ctx = SimpleScriptContext()
+        val gs = getBindings(200)
         if (gs != null) {
-            ctxt.setBindings(gs, 200);
-        }
-        if (nn != null) {
-            ctxt.setBindings(nn, 100);
-            ctxt.setReader(this.context.getReader());
-            ctxt.setWriter(this.context.getWriter());
-            ctxt.setErrorWriter(this.context.getErrorWriter());
-            return ctxt;
+            ctx.setBindings(gs, 200)
         }
-        throw new NullPointerException("Engine scope Bindings may not be null.");
+        ctx.setBindings(nn, 100)
+        ctx.reader = context.reader
+        ctx.writer = context.writer
+        ctx.errorWriter = context.errorWriter
+        return ctx
     }
-}
+}

+ 9 - 15
rhino/src/main/java/com/script/Bindings.kt

@@ -1,24 +1,18 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.util.Map;
+interface Bindings : MutableMap<String, Any?> {
 
-@SuppressWarnings("UnnecessaryModifier")
-public interface Bindings extends Map<String, Object> {
-    @Override
-    public boolean containsKey(Object var1);
+    override fun containsKey(key: String): Boolean
 
-    @Override
-    public Object get(Object var1);
+    override operator fun get(key: String): Any?
 
-    @Override
-    public Object put(String var1, Object var2);
+    override fun put(key: String, value: Any?): Any?
 
-    @Override
-    public void putAll(Map<? extends String, ?> var1);
+    override fun putAll(from: Map<out String, *>)
 
-    @Override
-    public Object remove(Object var1);
-}
+    override fun remove(key: String): Any?
+
+}

+ 9 - 7
rhino/src/main/java/com/script/Compilable.kt

@@ -1,13 +1,15 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.io.Reader;
+import java.io.Reader
 
-@SuppressWarnings("UnnecessaryModifier")
-public interface Compilable {
-    public CompiledScript compile(Reader var1) throws ScriptException;
+interface Compilable {
 
-    public CompiledScript compile(String var1) throws ScriptException;
-}
+    @Throws(ScriptException::class)
+    fun compile(script: Reader): CompiledScript
+
+    @Throws(ScriptException::class)
+    fun compile(script: String): CompiledScript
+}

+ 21 - 17
rhino/src/main/java/com/script/CompiledScript.kt

@@ -1,28 +1,32 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-public abstract class CompiledScript {
-    public abstract Object eval(ScriptContext var1) throws ScriptException;
+abstract class CompiledScript {
 
-    public abstract ScriptEngine getEngine();
+    abstract fun getEngine(): ScriptEngine
 
-    public Object eval(Bindings bindings) throws ScriptException {
-        ScriptContext ctxt = this.getEngine().getContext();
+    @Throws(ScriptException::class)
+    abstract fun eval(context: ScriptContext): Any?
+
+    @Throws(ScriptException::class)
+    fun eval(bindings: Bindings?): Any? {
+        var ctxt = getEngine().context
         if (bindings != null) {
-            SimpleScriptContext tempctxt = new SimpleScriptContext();
-            tempctxt.setBindings(bindings, 100);
-            tempctxt.setBindings(ctxt.getBindings(200), 200);
-            tempctxt.setWriter(ctxt.getWriter());
-            tempctxt.setReader(ctxt.getReader());
-            tempctxt.setErrorWriter(ctxt.getErrorWriter());
-            ctxt = tempctxt;
+            val tempContext = SimpleScriptContext()
+            tempContext.setBindings(bindings, 100)
+            tempContext.setBindings(ctxt.getBindings(200), 200)
+            tempContext.writer = ctxt.writer
+            tempContext.reader = ctxt.reader
+            tempContext.errorWriter = ctxt.errorWriter
+            ctxt = tempContext
         }
-        return this.eval(ctxt);
+        return this.eval(ctxt)
     }
 
-    public Object eval() throws ScriptException {
-        return this.eval(this.getEngine().getContext());
+    @Throws(ScriptException::class)
+    fun eval(): Any? {
+        return this.eval(getEngine().context)
     }
-}
+}

+ 9 - 8
rhino/src/main/java/com/script/Invocable.kt

@@ -1,15 +1,16 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-@SuppressWarnings({"unused", "UnnecessaryModifier"})
-public interface Invocable {
-    public <T> T getInterface(Class<T> var1);
+interface Invocable {
+    fun <T> getInterface(clazz: Class<T>): T?
 
-    public <T> T getInterface(Object var1, Class<T> var2);
+    fun <T> getInterface(obj: Any?, paramClass: Class<T>): T?
 
-    public Object invokeFunction(String var1, Object ... var2) throws ScriptException, NoSuchMethodException;
+    @Throws(ScriptException::class, NoSuchMethodException::class)
+    fun invokeFunction(name: String, vararg args: Any): Any?
 
-    public Object invokeMethod(Object var1, String var2, Object ... var3) throws ScriptException, NoSuchMethodException;
-}
+    @Throws(ScriptException::class, NoSuchMethodException::class)
+    fun invokeMethod(obj: Any?, name: String, vararg args: Any): Any?
+}

+ 20 - 26
rhino/src/main/java/com/script/ScriptContext.kt

@@ -1,43 +1,37 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.io.Reader;
-import java.io.Writer;
-import java.util.List;
+import java.io.Reader
+import java.io.Writer
 
-@SuppressWarnings({"unused", "UnnecessaryModifier"})
-public interface ScriptContext {
+interface ScriptContext {
 
-    public static final int ENGINE_SCOPE = 100;
-    public static final int GLOBAL_SCOPE = 200;
+    var errorWriter: Writer
 
-    public Object getAttribute(String var1);
+    var reader: Reader
 
-    public Object getAttribute(String var1, int var2);
+    val scopes: List<Int>
 
-    public int getAttributesScope(String var1);
+    var writer: Writer
 
-    public Bindings getBindings(int var1);
+    fun getAttribute(name: String): Any?
 
-    public Writer getErrorWriter();
+    fun getAttribute(name: String, scope: Int): Any?
 
-    public Reader getReader();
+    fun getAttributesScope(name: String): Int
 
-    public List<Integer> getScopes();
+    fun getBindings(scope: Int): Bindings?
 
-    public Writer getWriter();
+    fun removeAttribute(name: String, scope: Int): Any?
 
-    public Object removeAttribute(String var1, int var2);
+    fun setAttribute(name: String, value: Any?, scope: Int)
 
-    public void setAttribute(String var1, Object var2, int var3);
+    fun setBindings(bindings: Bindings?, scope: Int)
 
-    public void setBindings(Bindings var1, int var2);
-
-    public void setErrorWriter(Writer var1);
-
-    public void setReader(Reader var1);
-
-    public void setWriter(Writer var1);
-}
+    companion object {
+        const val ENGINE_SCOPE = 100
+        const val GLOBAL_SCOPE = 200
+    }
+}

+ 25 - 20
rhino/src/main/java/com/script/ScriptEngine.kt

@@ -1,37 +1,42 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.io.Reader;
+import java.io.Reader
 
-@SuppressWarnings({"unused", "UnnecessaryModifier"})
-public interface ScriptEngine {
-    public static final String FILENAME = "javax.script.filename";
+interface ScriptEngine {
+    var context: ScriptContext
 
-    public Bindings createBindings();
+    fun createBindings(): Bindings?
 
-    public Object eval(Reader var1) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(reader: Reader): Any?
 
-    public Object eval(Reader var1, Bindings var2) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(reader: Reader, bindings: Bindings): Any?
 
-    public Object eval(Reader var1, ScriptContext var2) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(reader: Reader, context: ScriptContext): Any?
 
-    public Object eval(String var1) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(script: String): Any?
 
-    public Object eval(String var1, Bindings var2) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(script: String, bindings: Bindings): Any?
 
-    public Object eval(String var1, ScriptContext var2) throws ScriptException;
+    @Throws(ScriptException::class)
+    fun eval(script: String, context: ScriptContext): Any?
 
-    public Object get(String var1);
+    operator fun get(key: String): Any?
 
-    public Bindings getBindings(int var1);
+    fun getBindings(scope: Int): Bindings?
 
-    public ScriptContext getContext();
+    fun put(key: String, value: Any?)
 
-    public void put(String var1, Object var2);
+    fun setBindings(bindings: Bindings?, scope: Int)
 
-    public void setBindings(Bindings var1, int var2);
-
-    public void setContext(ScriptContext var1);
-}
+    companion object {
+        const val FILENAME = "javax.script.filename"
+    }
+}

+ 50 - 63
rhino/src/main/java/com/script/ScriptException.kt

@@ -1,67 +1,54 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
-
-@SuppressWarnings("unused")
-public class ScriptException extends Exception {
-    private int columnNumber;
-    private String fileName;
-    private int lineNumber;
-
-    public ScriptException(String s) {
-        super(s);
-        this.fileName = null;
-        this.lineNumber = -1;
-        this.columnNumber = -1;
-    }
-
-    public ScriptException(Exception e) {
-        super(e);
-        this.fileName = null;
-        this.lineNumber = -1;
-        this.columnNumber = -1;
-    }
-
-    public ScriptException(String message, String fileName2, int lineNumber2) {
-        super(message);
-        this.fileName = fileName2;
-        this.lineNumber = lineNumber2;
-        this.columnNumber = -1;
-    }
-
-    public ScriptException(String message, String fileName2, int lineNumber2, int columnNumber2) {
-        super(message);
-        this.fileName = fileName2;
-        this.lineNumber = lineNumber2;
-        this.columnNumber = columnNumber2;
-    }
-
-    @Override
-    public String getMessage() {
-        String ret = super.getMessage();
-        if (this.fileName == null) {
-            return ret;
+package com.script
+
+class ScriptException : Exception {
+    var columnNumber: Int
+        private set
+    var fileName: String?
+        private set
+    var lineNumber: Int
+        private set
+
+    constructor(s: String?) : super(s) {
+        fileName = null
+        lineNumber = -1
+        columnNumber = -1
+    }
+
+    constructor(e: Exception?) : super(e) {
+        fileName = null
+        lineNumber = -1
+        columnNumber = -1
+    }
+
+    constructor(message: String?, fileName2: String?, lineNumber2: Int) : super(message) {
+        fileName = fileName2
+        lineNumber = lineNumber2
+        columnNumber = -1
+    }
+
+    constructor(message: String?, fileName2: String?, lineNumber2: Int, columnNumber2: Int) : super(
+        message
+    ) {
+        fileName = fileName2
+        lineNumber = lineNumber2
+        columnNumber = columnNumber2
+    }
+
+    override val message: String
+        get() {
+            val ret = super.message
+            if (fileName == null) {
+                return ret!!
+            }
+            var ret2 = ret + " in " + fileName
+            if (lineNumber != -1) {
+                ret2 = ret2 + " at line number " + lineNumber
+            }
+            return if (columnNumber != -1) {
+                ret2 + " at column number " + columnNumber
+            } else ret2
         }
-        String ret2 = ret + " in " + this.fileName;
-        if (this.lineNumber != -1) {
-            ret2 = ret2 + " at line number " + this.lineNumber;
-        }
-        if (this.columnNumber != -1) {
-            return ret2 + " at column number " + this.columnNumber;
-        }
-        return ret2;
-    }
-
-    public int getLineNumber() {
-        return this.lineNumber;
-    }
-
-    public int getColumnNumber() {
-        return this.columnNumber;
-    }
-
-    public String getFileName() {
-        return this.fileName;
-    }
-}
+}

+ 40 - 77
rhino/src/main/java/com/script/SimpleBindings.kt

@@ -1,107 +1,70 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
+package com.script
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+class SimpleBindings @JvmOverloads constructor(
+    private val map: MutableMap<String, Any?> = HashMap()
+) : Bindings {
 
-public class SimpleBindings implements Bindings {
-    private Map<String, Object> map;
-
-    public SimpleBindings(Map<String, Object> m) {
-        if (m == null) {
-            throw new NullPointerException();
-        }
-        this.map = m;
-    }
-
-    public SimpleBindings() {
-        this(new HashMap<String, Object>());
-    }
-
-    @Override
-    public Object put(String name, Object value) {
-        this.checkKey(name);
-        return this.map.put(name, value);
+    override fun put(key: String, value: Any?): Any? {
+        checkKey(key)
+        return map.put(key, value)
     }
 
-    @Override
-    public void putAll(Map<? extends String, ? extends Object> toMerge) {
-        if (toMerge == null) {
-            throw new NullPointerException("toMerge map is null");
-        }
-        for (Map.Entry<? extends String, ? extends Object> entry : toMerge.entrySet()) {
-            String key = entry.getKey();
-            this.checkKey(key);
-            this.put(key, entry.getValue());
+    override fun putAll(from: Map<out String, Any?>) {
+        for ((key, value) in from) {
+            checkKey(key)
+            this[key] = value
         }
     }
 
-    @Override
-    public void clear() {
-        this.map.clear();
+    override fun clear() {
+        map.clear()
     }
 
-    @Override
-    public boolean containsKey(Object key) {
-        this.checkKey(key);
-        return this.map.containsKey(key);
+    override fun containsKey(key: String): Boolean {
+        checkKey(key)
+        return map.containsKey(key)
     }
 
-    @Override
-    public boolean containsValue(Object value) {
-        return this.map.containsValue(value);
+    override fun containsValue(value: Any?): Boolean {
+        return map.containsValue(value)
     }
 
-    @Override
-    public Set<Map.Entry<String, Object>> entrySet() {
-        return this.map.entrySet();
-    }
+    override val entries: MutableSet<MutableMap.MutableEntry<String, Any?>>
+        get() = map.entries
 
-    @Override
-    public Object get(Object key) {
-        this.checkKey(key);
-        return this.map.get(key);
+    override operator fun get(key: String): Any? {
+        checkKey(key)
+        return map[key]
     }
 
-    @Override
-    public boolean isEmpty() {
-        return this.map.isEmpty();
+    override fun isEmpty(): Boolean {
+        return map.isEmpty()
     }
 
-    @Override
-    public Set<String> keySet() {
-        return this.map.keySet();
-    }
+    override val keys: MutableSet<String>
+        get() = map.keys
 
-    @Override
-    public Object remove(Object key) {
-        this.checkKey(key);
-        return this.map.remove(key);
+    override fun remove(key: String): Any? {
+        checkKey(key)
+        return map.remove(key)
     }
 
-    @Override
-    public int size() {
-        return this.map.size();
-    }
+    override val size: Int
+        get() = map.size
 
-    @Override
-    public Collection<Object> values() {
-        return this.map.values();
-    }
+    override val values: MutableCollection<Any?>
+        get() = map.values
 
-    private void checkKey(Object key) {
+    private fun checkKey(key: Any?) {
         if (key == null) {
-            throw new NullPointerException("key can not be null");
-        }
-        if (!(key instanceof String)) {
-            throw new ClassCastException("key should be a String");
+            throw NullPointerException("key can not be null")
         }
-        if (key.equals("")) {
-            throw new IllegalArgumentException("key can not be empty");
+        if (key !is String) {
+            throw ClassCastException("key should be a String")
         }
+        require(key != "") { "key can not be empty" }
     }
-}
+}

+ 80 - 127
rhino/src/main/java/com/script/SimpleScriptContext.kt

@@ -1,166 +1,119 @@
 /*
  * Decompiled with CFR 0.152.
  */
-package com.script;
-
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class SimpleScriptContext implements ScriptContext {
-    private static List<Integer> scopes = new ArrayList<Integer>(2);
-    protected Bindings engineScope = new SimpleBindings();
-    protected Writer errorWriter = new PrintWriter(System.err, true);
-    protected Bindings globalScope = null;
-    protected Reader reader = new InputStreamReader(System.in);
-    protected Writer writer = new PrintWriter(System.out, true);
-
-    @Override
-    public void setBindings(Bindings bindings, int scope) {
-        switch (scope) {
-            case 100: {
+package com.script
+
+import java.io.InputStreamReader
+import java.io.PrintWriter
+import java.io.Reader
+import java.io.Writer
+import java.util.*
+
+open class SimpleScriptContext : ScriptContext {
+    private var engineScope: Bindings = SimpleBindings()
+    override var errorWriter: Writer = PrintWriter(System.err, true)
+    private var globalScope: Bindings? = null
+    override var reader: Reader = InputStreamReader(System.`in`)
+    override var writer: Writer = PrintWriter(System.out, true)
+    override fun setBindings(bindings: Bindings?, scope: Int) {
+        when (scope) {
+            100 -> {
                 if (bindings == null) {
-                    throw new NullPointerException("Engine scope cannot be null.");
+                    throw NullPointerException("Engine scope cannot be null.")
                 }
-                this.engineScope = bindings;
-                return;
+                engineScope = bindings
+                return
             }
-            case 200: {
-                this.globalScope = bindings;
-                return;
+            200 -> {
+                globalScope = bindings
+                return
             }
         }
-        throw new IllegalArgumentException("Invalid scope value.");
+        throw IllegalArgumentException("Invalid scope value.")
     }
 
-    @Override
-    public Object getAttribute(String name) {
-        if (this.engineScope.containsKey(name)) {
-            return this.getAttribute(name, 100);
+    override fun getAttribute(name: String): Any? {
+        if (engineScope.containsKey(name)) {
+            return this.getAttribute(name, 100)
         }
-        if (this.globalScope == null || !this.globalScope.containsKey(name)) {
-            return null;
-        }
-        return this.getAttribute(name, 200);
+        return if (globalScope == null || !globalScope!!.containsKey(name)) {
+            null
+        } else this.getAttribute(name, 200)
     }
 
-    @Override
-    public Object getAttribute(String name, int scope) {
-        switch (scope) {
-            case 100: {
-                return this.engineScope.get(name);
+    override fun getAttribute(name: String, scope: Int): Any? {
+        when (scope) {
+            100 -> {
+                return engineScope[name]
             }
-            case 200: {
-                if (this.globalScope != null) {
-                    return this.globalScope.get(name);
-                }
-                return null;
+            200 -> {
+                return if (globalScope != null) {
+                    globalScope!![name]
+                } else null
             }
         }
-        throw new IllegalArgumentException("Illegal scope value.");
+        throw IllegalArgumentException("Illegal scope value.")
     }
 
-    @Override
-    public Object removeAttribute(String name, int scope) {
-        switch (scope) {
-            case 100: {
-                if (this.getBindings(100) != null) {
-                    return this.getBindings(100).remove(name);
-                }
-                return null;
+    override fun removeAttribute(name: String, scope: Int): Any? {
+        when (scope) {
+            100 -> {
+                return if (getBindings(100) != null) {
+                    getBindings(100)!!.remove(name)
+                } else null
             }
-            case 200: {
-                if (this.getBindings(200) != null) {
-                    return this.getBindings(200).remove(name);
-                }
-                return null;
+            200 -> {
+                return if (getBindings(200) != null) {
+                    getBindings(200)!!.remove(name)
+                } else null
             }
         }
-        throw new IllegalArgumentException("Illegal scope value.");
+        throw IllegalArgumentException("Illegal scope value.")
     }
 
-    @Override
-    public void setAttribute(String name, Object value, int scope) {
-        switch (scope) {
-            case 100: {
-                this.engineScope.put(name, value);
-                return;
+    override fun setAttribute(name: String, value: Any?, scope: Int) {
+        when (scope) {
+            100 -> {
+                engineScope[name] = value
+                return
             }
-            case 200: {
-                if (this.globalScope != null) {
-                    this.globalScope.put(name, value);
-                    return;
-                }
-                return;
+            200 -> {
+                globalScope?.put(name, value)
+                return
             }
         }
-        throw new IllegalArgumentException("Illegal scope value.");
-    }
-
-    @Override
-    public Writer getWriter() {
-        return this.writer;
-    }
-
-    @Override
-    public Reader getReader() {
-        return this.reader;
+        throw IllegalArgumentException("Illegal scope value.")
     }
 
-    @Override
-    public void setReader(Reader reader2) {
-        this.reader = reader2;
-    }
-
-    @Override
-    public void setWriter(Writer writer2) {
-        this.writer = writer2;
-    }
-
-    @Override
-    public Writer getErrorWriter() {
-        return this.errorWriter;
-    }
-
-    @Override
-    public void setErrorWriter(Writer writer2) {
-        this.errorWriter = writer2;
-    }
-
-    @Override
-    public int getAttributesScope(String name) {
-        if (this.engineScope.containsKey(name)) {
-            return 100;
-        }
-        if (this.globalScope == null || !this.globalScope.containsKey(name)) {
-            return -1;
+    override fun getAttributesScope(name: String): Int {
+        if (engineScope.containsKey(name)) {
+            return 100
         }
-        return 200;
+        return if (globalScope == null || !globalScope!!.containsKey(name)) {
+            -1
+        } else 200
     }
 
-    @Override
-    public Bindings getBindings(int scope) {
+    override fun getBindings(scope: Int): Bindings? {
         if (scope == 100) {
-            return this.engineScope;
+            return engineScope
         }
         if (scope == 200) {
-            return this.globalScope;
+            return globalScope
         }
-        throw new IllegalArgumentException("Illegal scope value.");
+        throw IllegalArgumentException("Illegal scope value.")
     }
 
-    @Override
-    public List<Integer> getScopes() {
-        return scopes;
-    }
+    override val scopes: List<Int>
+        get() = Companion.scopes
+
+    companion object {
+        private var scopes: MutableList<Int> = ArrayList(2)
 
-    static {
-        scopes.add(100);
-        scopes.add(200);
-        scopes = Collections.unmodifiableList(scopes);
+        init {
+            scopes.add(100)
+            scopes.add(200)
+            scopes = Collections.unmodifiableList(scopes)
+        }
     }
-}
+}

+ 13 - 17
rhino/src/main/java/com/script/rhino/InterfaceImplementor.kt

@@ -43,17 +43,17 @@ import java.security.PrivilegedExceptionAction
 @Suppress("UNUSED_PARAMETER")
 open class InterfaceImplementor(private val engine: Invocable) {
     @Throws(ScriptException::class)
-    fun <T> getInterface(thiz: Any?, iface: Class<T>?): T? {
-        return if (iface != null && iface.isInterface) {
-            if (!isImplemented(thiz, iface)) {
+    fun <T> getInterface(obj: Any?, clazz: Class<T>?): T? {
+        return if (clazz != null && clazz.isInterface) {
+            if (!isImplemented(obj, clazz)) {
                 null
             } else {
                 val accContext = AccessController.getContext()
-                iface.cast(
+                clazz.cast(
                     Proxy.newProxyInstance(
-                        iface.classLoader,
-                        arrayOf<Class<*>>(iface),
-                        InterfaceImplementorInvocationHandler(thiz, accContext)
+                        clazz.classLoader,
+                        arrayOf<Class<*>>(clazz),
+                        InterfaceImplementorInvocationHandler(obj, accContext)
                     )
                 )
             }
@@ -62,12 +62,12 @@ open class InterfaceImplementor(private val engine: Invocable) {
         }
     }
 
-    protected open fun isImplemented(thiz: Any?, iface: Class<*>): Boolean {
+    protected open fun isImplemented(obj: Any?, clazz: Class<*>): Boolean {
         return true
     }
 
     @Throws(ScriptException::class)
-    protected open fun convertResult(method: Method?, res: Any): Any? {
+    protected open fun convertResult(method: Method?, res: Any?): Any? {
         return res
     }
 
@@ -77,7 +77,7 @@ open class InterfaceImplementor(private val engine: Invocable) {
     }
 
     private inner class InterfaceImplementorInvocationHandler(
-        private val thiz: Any?,
+        private val obj: Any?,
         private val accContext: AccessControlContext
     ) : InvocationHandler {
 
@@ -85,13 +85,9 @@ open class InterfaceImplementor(private val engine: Invocable) {
         override fun invoke(proxy: Any, method: Method, args: Array<Any>): Any? {
             val finalArgs = convertArguments(method, args)
             val result = AccessController.doPrivileged(PrivilegedExceptionAction {
-                if (thiz == null) engine.invokeFunction(
-                    method.name,
-                    *finalArgs
-                ) else engine.invokeMethod(
-                    thiz, method.name, *finalArgs
-                )
-            } as PrivilegedExceptionAction<Any>, accContext)
+                if (obj == null) engine.invokeFunction(method.name, *finalArgs)
+                else engine.invokeMethod(obj, method.name, *finalArgs)
+            }, accContext)
             return convertResult(method, result)
         }
 

+ 4 - 3
rhino/src/main/java/com/script/rhino/RhinoCompiledScript.kt

@@ -41,6 +41,10 @@ internal class RhinoCompiledScript(
     private val script: Script
 ) : CompiledScript() {
 
+    override fun getEngine(): ScriptEngine {
+        return engine
+    }
+
     @Throws(ScriptException::class)
     override fun eval(context: ScriptContext): Any? {
         val cx = Context.enter()
@@ -65,7 +69,4 @@ internal class RhinoCompiledScript(
         return result
     }
 
-    override fun getEngine(): ScriptEngine {
-        return engine
-    }
 }

+ 30 - 35
rhino/src/main/java/com/script/rhino/RhinoScriptEngine.kt

@@ -49,11 +49,11 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
     private val implementor: InterfaceImplementor
 
     @Throws(ScriptException::class)
-    override fun eval(reader: Reader, ctxt: ScriptContext): Any? {
+    override fun eval(reader: Reader, context: ScriptContext): Any? {
         val cx = Context.enter()
         val ret: Any?
         try {
-            val scope = getRuntimeScope(ctxt)
+            val scope = getRuntimeScope(context)
             var filename = this["javax.script.filename"] as? String
             filename = filename ?: "<Unknown source>"
             ret = cx.evaluateReader(scope, reader, filename, 1, null)
@@ -76,12 +76,8 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
     }
 
     @Throws(ScriptException::class)
-    override fun eval(script: String?, ctxt: ScriptContext): Any? {
-        return if (script == null) {
-            throw NullPointerException("null script")
-        } else {
-            this.eval(StringReader(script) as Reader, ctxt)
-        }
+    override fun eval(script: String, context: ScriptContext): Any? {
+        return this.eval(StringReader(script) as Reader, context)
     }
 
     override fun createBindings(): Bindings {
@@ -94,11 +90,11 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
     }
 
     @Throws(ScriptException::class, NoSuchMethodException::class)
-    override fun invokeMethod(thiz: Any?, name: String, vararg args: Any): Any? {
-        return if (thiz == null) {
+    override fun invokeMethod(obj: Any?, name: String, vararg args: Any): Any? {
+        return if (obj == null) {
             throw IllegalArgumentException("脚本对象不能为空")
         } else {
-            this.invoke(thiz, name, *args)
+            this.invoke(obj, name, *args)
         }
     }
 
@@ -136,20 +132,20 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
         return var11
     }
 
-    override fun <T> getInterface(clasz: Class<T>): T? {
+    override fun <T> getInterface(clazz: Class<T>): T? {
         return try {
-            implementor.getInterface(null, clasz)
+            implementor.getInterface(null, clazz)
         } catch (var3: ScriptException) {
             null
         }
     }
 
-    override fun <T> getInterface(thiz: Any?, clasz: Class<T>): T? {
-        return if (thiz == null) {
+    override fun <T> getInterface(obj: Any?, paramClass: Class<T>): T? {
+        return if (obj == null) {
             throw IllegalArgumentException("脚本对象不能为空")
         } else {
             try {
-                implementor.getInterface(thiz, clasz)
+                implementor.getInterface(obj, paramClass)
             } catch (var4: ScriptException) {
                 null
             }
@@ -224,27 +220,26 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
         indexedProps = HashMap()
         implementor = object : InterfaceImplementor(this) {
 
-            override fun isImplemented(thiz: Any?, iface: Class<*>): Boolean {
-                var thiz1 = thiz
+            override fun isImplemented(obj: Any?, clazz: Class<*>): Boolean {
+                var obj1 = obj
                 return try {
-                    if (thiz1 != null && thiz1 !is Scriptable) {
-                        thiz1 = Context.toObject(
-                            thiz1,
-                            topLevel
-                        )
+                    if (obj1 != null && obj1 !is Scriptable) {
+                        obj1 = Context.toObject(obj1, topLevel)
                     }
-                    val engineScope =
-                        getRuntimeScope(context)
-                    val localScope =
-                        if (thiz1 != null) thiz1 as Scriptable else engineScope
-                    val var5 = iface.methods
-                    val var6 = var5.size
-                    for (var7 in 0 until var6) {
-                        val method = var5[var7]
+                    val engineScope = getRuntimeScope(context)
+                    val localScope = if (obj1 != null) obj1 as Scriptable else engineScope
+                    val methods = clazz.methods
+                    val methodsSize = methods.size
+                    for (index in 0 until methodsSize) {
+                        val method = methods[index]
                         if (method.declaringClass != Any::class.java) {
-                            val obj =
-                                ScriptableObject.getProperty(localScope, method.name) as? Function
-                            obj ?: return false
+                            if (ScriptableObject.getProperty(
+                                    localScope,
+                                    method.name
+                                ) !is Function
+                            ) {
+                                return false
+                            }
                         }
                     }
                     true
@@ -253,7 +248,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
                 }
             }
 
-            override fun convertResult(method: Method?, res: Any): Any? {
+            override fun convertResult(method: Method?, res: Any?): Any? {
                 method ?: return null
                 val desiredType = method.returnType
                 if (desiredType == Void.TYPE) return null