IScriptEvaluator that utilizes the JANINO Java compiler.
This implementation implements the concept of "Local methods", i.e. statements may be freely intermixed with
method declarations. These methods are typically called by the "main code" of the script evaluator. One limitation
exists: When cooking multiple scripts in one ScriptEvaluator, then local method signatures
(names and parameter types) must not collide between scripts.
A plethora of "convenience constructors" exist that execute the setup steps instantly. Their use is discouraged,
in favor of using the default constructor, plus calling a number of setters, and then one of the cook()
methods.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | ScriptEvaluator.Script
Represents one script that this |
| Modifier and Type | Field and Description |
|---|---|
| private final ClassBodyEvaluator | |
| private Class | |
| private Method[] | |
| private ScriptEvaluator. | scripts
The scripts to compile. |
| private int | |
| private WarningHandler |
| Access | Constructor and Description |
|---|---|
| public | ScriptEvaluator(String script)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.cook(script);
|
| public | ScriptEvaluator(String script, Class<?> returnType)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.cook(script);
|
| public | ScriptEvaluator(String script, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.cook(script);
|
| public | ScriptEvaluator(String script, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.cook(script);
|
| public | ScriptEvaluator(String fileName, InputStream is, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(fileName, is);
|
| public | ScriptEvaluator(String fileName, Reader reader, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(reader);
|
| public | ScriptEvaluator(Scanner scanner, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(scanner);
|
| public | ScriptEvaluator(Scanner scanner, Class<?> extendedType, Class<?>[] implementedTypes, Class<?> returnType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setExtendedType(extendedType);
se.setImplementedTypes(implementedTypes);
se.setReturnType(returnType);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(scanner);
|
| public | ScriptEvaluator(Scanner scanner, String className, Class<?> extendedType, Class<?>[] implementedTypes, boolean staticMethod, Class<?> returnType, String methodName, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)
Equivalent to
ScriptEvaluator se = new ScriptEvaluator();
se.setClassName(className);
se.setExtendedType(extendedType);
se.setImplementedTypes(implementedTypes);
se.setStaticMethod(staticMethod);
se.setReturnType(returnType);
se.setMethodName(methodName);
se.setParameters(parameterNames, parameterTypes);
se.setThrownExceptions(thrownExceptions);
se.setParentClassLoader(parentClassLoader);
se.cook(scanner);
|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static <T> T[] | |
| protected Java. | |
| protected Java. | |
| public void | cook(String
Used when reporting errors and warnings fileName, Reader reader)Implements abstract org. Implements org. Reader.
|
| public final void | cook(String[] fileNames, Reader[] readers)
Implements abstract org. Implements org. |
| public final void | |
| public final void | |
| pack-priv void | cook(String fileName, Java.
|
| public final void | |
| protected void | cook(Java.
Compiles the given compilationUnit, defines it into a |
| private void | |
| public <T> T | createFastEvaluator(Reader
Produces the stream of script tokens reader, Class<T> Must declare exactly one method interfaceToImplement, String[] The names of the parameters of that method parameterNames)Implements org. |
| public <T> T | createFastEvaluator(String
Contains the sequence of script tokens script, Class<T> interfaceToImplement, String[] parameterNames)Implements org. |
| public <T> T | createFastEvaluator(Scanner
Source of tokens to read scanner, Class<?> interfaceToImplement, String[] parameterNames)Notice: This method is not declared in |
| public static Object | createFastScriptEvaluator(String script, Class<?> interfaceToImplement, String[] parameterNames)
Deprecated
Use
createFastEvaluator(Scanner, Class, String[]) instead
|
| public static Object | createFastScriptEvaluator(Scanner scanner, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)
Deprecated
Use
createFastEvaluator(Scanner, Class, String[]) instead
|
| public static Object | createFastScriptEvaluator(Scanner scanner, String className, Class<?> extendedType, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)
Deprecated
Use
createFastEvaluator(Scanner, Class, String[]) instead
|
| public static Object | createFastScriptEvaluator(Scanner scanner, String[] defaultImports, String className, Class<?> extendedClass, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)
Deprecated
Use
createFastEvaluator(Scanner, Class, String[]) instead:
|
| public Object | evaluate()
Implements org. evaluate(new Object[0]).
|
| public Object | evaluate(Object[]
The actual parameter values arguments)Implements org. |
| public Object | evaluate(int idx, Object[] arguments)
Implements org. evaluate(Object[]), but for multiple scripts.
|
| public Map | |
| public Class | |
| public String[] | |
| public Class | |
| public Method | |
| public Method | getMethod(int idx)
Implements org. getMethod(), but for multiple scripts.
|
| pack-priv Method[] | |
| public Method[] | |
| protected final Class | |
| private ScriptEvaluator. | |
| public static String[] | guessParameterNames(Scanner scanner)
Guesses the names of the parameters used in the given expression. |
| private static String[] | |
| private Java. | makeMethodDeclaration(Location location, Java.
|
| protected void | makeStatements(int idx, Parser parser, List<Java.
Is filled with the generated statements resultStatements,Is filled with any local methods that the script declares resultMethodsParses statements from the parser until end-of-input. |
| private static Object | |
| protected Java. | |
| public EnumSet | Returns: A reference to the currently effective compilation options; changes to it take effect immediately
|
| public ScriptEvaluator | |
| pack-priv Java. | |
| private static void | parseScriptStatement(Parser parser, List<Java.
Filled with the methods that the script declares localMethods
ScriptStatement :=
Statement (1)
| 'class' ...
|
| public void | setClassName(String className)
Implements org. |
| public void | setCompileErrorHandler(ErrorHandler
null to restore the default behavior (throwing a CompileException)Implements org. ErrorHandler which is invoked during compilation on each error.
|
| public void | setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)
Implements org. |
| public void | setDefaultImports(String... defaultImports)
Implements org. |
| public void | setDefaultReturnType(Class<?> defaultReturnType)
Implements org. IScriptEvaluator is coooked, then the defaultReturnType applies to all scripts for
which no explicit return type was configured.
|
| public void | setExtendedClass(Class<?> extendedType)
Implements org. |
| public void | setImplementedInterfaces(Class<?>[] implementedTypes)
Implements org. |
| public void | setMethodName(String
null means reset to default nameImplements org. |
| public void | setMethodNames(String[] methodNames)
Implements org. setMethodName(String), but for multiple scripts.
|
| public void | setOverrideMethod(boolean overrideMethod)
Implements org. |
| public void | setOverrideMethod(boolean[] overrideMethod)
Implements org. setOverrideMethod(boolean), but for multiple scripts.
|
| public void | setParameters(String[] parameterNames, Class<?>[] parameterTypes)
Implements org. |
| public void | setParameters(String[][] parameterNames, Class<?>[][] parameterTypes)
Implements org. setParameters(String[], Class[]), but for multiple scripts.
|
| public void | setParentClassLoader(ClassLoader parentClassLoader)
Implements org. |
| public void | setReturnType(Class<?> returnType)
Implements org. |
| public void | setReturnTypes(Class<?>[]
The methods' return types; returnTypes)null elements mean "use the default return
type"Implements org. |
| public void | |
| public void | setSourceVersion(int version)
Implements org. -source command line option.
|
| public void | setStaticMethod(boolean staticMethod)
Implements org. |
| public void | setStaticMethod(boolean[] staticMethod)
Implements org. setStaticMethod(boolean), but for multiple scripts.
|
| public void | setTargetVersion(int version)
Implements org. -target command line option.
|
| public void | setThrownExceptions(Class<?>[] thrownExceptions)
Implements org. |
| public void | setThrownExceptions(Class<?>[][] thrownExceptions)
Implements org. setThrownExceptions(Class[]), but for multiple scripts.
|
| public void | setWarningHandler(WarningHandler
null to indicate that no warnings be issuedImplements org. WarningHandler.
|