Package org.codehaus.janino

# Class ExpressionEvaluator

java.lang.Object
org.codehaus.commons.compiler.Cookable
org.codehaus.commons.compiler.MultiCookable
org.codehaus.janino.ExpressionEvaluator

All Implemented Interfaces:
  `ICookable`, `IExpressionEvaluator`, `IMultiCookable`

public class ExpressionEvaluator extends MultiCookable implements IExpressionEvaluator
This `IExpressionEvaluator` is implemented by creating and compiling a temporary compilation unit defining one class with one static method with one RETURN statement.

A number of "convenience constructors" exist that execute the set-up steps described for `IExpressionEvaluator` instantly.

If the expression type and the parameters' types are known at compile time, then a "fast" expression evaluator can be instantiated through `createFastEvaluator(String, Class, String...)`. Expression evaluation is faster than through `evaluate(Object[])`, because it is not done through reflection but through direct method invocation.

Example:

         public interface Foo {
             int bar(int a, int b);
         }
         ...
         Foo f = (Foo) ExpressionEvaluator.createFastExpressionEvaluator(
             "a + b",                    // expression to evaluate
             Foo.class,                  // interface that describes the expression's signature
             new String[] { "a", "b" },  // the parameters' names
             (ClassLoader) null          // Use current thread's context class loader
         );
         System.out.println("1 + 2 = " + f.bar(1, 2)); // Evaluate the expression

Notice: The `interfaceToImplement` must either be declared `public`, or with package scope in the root package (i.e. "no" package).

On my system (Intel P4, 2 GHz, MS Windows XP, JDK 1.4.1), expression "x + 1" evaluates as follows:

| Server JVM | Client JVM
Normal EE | 23.7 ns | 64.0 ns
Fast EE | 31.2 ns | 42.2 ns

## Field Summary

### Fields inherited from interface org.codehaus.commons.compiler.IExpressionEvaluator

`ANY_TYPE, DEFAULT_CLASS_NAME, DEFAULT_EXPRESSION_TYPE`

## Constructor Summary

Constructors
Constructor
Description
`ExpressionEvaluator()`
`ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes)`
Equivalent to
`ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, Class<?> extendedClass, Class<?>[] implementedTypes, ClassLoader parentClassLoader)`
Equivalent to
`ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)`
Equivalent to
`ExpressionEvaluator(Scanner scanner, String className, Class<?> extendedType, Class<?>[] implementedTypes, boolean staticMethod, Class<?> expressionType, String methodName, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, ClassLoader parentClassLoader)`
Creates an expression evaluator with the full configurability.

## Method Summary

Modifier and Type
Method
Description
`protected Java.Type[]`
`classesToTypes(Location location, Class<?>... classes)`
Converts an array of `Class`es into an array of`Java.Type`s.
`protected Java.Type`
`classToType(Location location, Class<?> clazz)`
Wraps a reflection `Class` in a `Java.Type` object.
`void`
`cook(String[] fileNames, Reader[] readers)`
Same as `Cookable.cook(String, Reader)`, but cooks a set of documents into one class.
`void`
`cook(String fileName, Reader reader)`
Reads, scans, parses and compiles Java tokens from the given `Reader`.
`final void`
`cook(Parser... parsers)`
`final void`
`cook(Scanner scanner)`
`final void`
`cook(Scanner... scanners)`
Like `cook(Scanner)`, but cooks a set of scripts into one class.
`<T> T`
`createFastEvaluator(Reader reader, Class<? extends T> interfaceToImplement, String... parameterNames)`
`<T> T`
`createFastEvaluator(String script, Class<? extends T> interfaceToImplement, String... parameterNames)`
If the parameter and return types of the expression are known at compile time, then a "fast" expression evaluator can be instantiated through `IExpressionEvaluator.createFastEvaluator(String, Class, String[])`.
`<T> T`
`createFastEvaluator(Scanner scanner, Class<T> interfaceToImplement, String... parameterNames)`
Notice: This method is not declared in `IScriptEvaluator`, and is hence only available in this implementation of `org.codehaus.commons.compiler`.
`static Object`
`createFastExpressionEvaluator(String expression, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)`
Deprecated.
Use `createFastEvaluator(String, Class, String[])` instead:
`static Object`
`createFastExpressionEvaluator(Scanner scanner, String[] defaultImports, String className, Class<?> extendedType, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)`
Deprecated.
Use `createFastEvaluator(Reader, Class, String[])` instead
`static Object`
`createFastExpressionEvaluator(Scanner scanner, String className, Class<?> extendedType, Class<?> interfaceToImplement, String[] parameterNames, ClassLoader parentClassLoader)`
Deprecated.
Use `createFastEvaluator(Reader, Class, String[])` instead
`Object`
`evaluate()`
Shorthand for `evaluate``(new Object[0])`.
`Object`
`evaluate(int idx, Object[] arguments)`
Same as `IExpressionEvaluator.evaluate(Object[])`, but for multiple expressions.
`Object`
`evaluate(Object[] arguments)`
Evaluates the expression with concrete parameter values.
`Map<String,byte[]>`
`getBytecodes()`
`Class<?>`
`getClazz()`
`Class<?>`
`getDefaultExpressionType()`
`String[]`
`getDefaultImports()`
`Method`
`getMethod()`
`Method`
`getMethod(int idx)`
Same as `IExpressionEvaluator.getMethod()`, but for multiple expressions.
`Method[]`
`getResult()`
`static String[]`
`guessParameterNames(Scanner scanner)`
Guess the names of the parameters used in the given expression.
`protected Java.Type`
`optionalClassToType(Location location, Class<?> clazz)`
Wraps a reflection `Class` in a `Java.Type` object.
`EnumSet<JaninoOption>`
`options()`
`ExpressionEvaluator`
`options(EnumSet<JaninoOption> options)`
Sets the options for all future compilations.
`void`
`setClassName(String className)`
Sets the name of the generated class.
`void`
`setCompileErrorHandler(ErrorHandler compileErrorHandler)`
Installs an `ErrorHandler` which is invoked during compilation on each error.
`void`
`setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)`
Determines what kind of debugging information is included in the generates classes.
`void`
`setDefaultExpressionType(Class<?> defaultExpressionType)`
Reconfigures the "default expression type"; if no expression type is configured for an expression, then, when cooking this `IExpressionEvaluator`, the "default expression type" is used for the expression
`void`
`setDefaultImports(String... defaultImports)`
"Default imports" add to the system import "java.lang", i.e.
`void`
`setExpressionType(Class<?> expressionType)`
Defines the type of the expression.
`void`
`setExpressionTypes(Class<?>[] expressionTypes)`
Configures the types of the expressions.
`void`
`setExtendedClass(Class<?> extendedType)`
Sets a particular superclass that the generated class will extend.
`void`
`setImplementedInterfaces(Class<?>[] implementedTypes)`
Configures the interfaces that the generated class implements.
`void`
`setMethodName(String methodName)`
Defines the name of the generated method.
`void`
`setMethodNames(String[] methodNames)`
Same as `IExpressionEvaluator.setMethodName(String)`, but for multiple expressions.
`void`
`setOverrideMethod(boolean overrideMethod)`
Defines whether the generated method overrides a methods declared in a supertype.
`void`
`setOverrideMethod(boolean[] overrideMethod)`
Same as `IExpressionEvaluator.setOverrideMethod(boolean)`, but for multiple expressions.
`void`
`setParameters(String[][] parameterNames, Class<?>[][] parameterTypes)`
Same as `IExpressionEvaluator.setParameters(String[], Class[])`, but for multiple expressions.
`void`
`setParameters(String[] parameterNames, Class<?>[] parameterTypes)`
Defines the names and types of the parameters of the generated method.
`void`
`setParentClassLoader(ClassLoader parentClassLoader)`
The "parent class loader" is used to load referenced classes.
`void`
`setReturnType(Class<?> returnType)`
`void`
`setSourceVersion(int version)`
Specifies the version of source code accepted, in analogy with JAVAC's `-source` command line option.
`void`
`setStaticMethod(boolean staticMethod)`
Defines whether the generated method should be STATIC or not.
`void`
`setStaticMethod(boolean[] staticMethod)`
Same as `IExpressionEvaluator.setStaticMethod(boolean)`, but for multiple expressions.
`void`
`setTargetVersion(int version)`
Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's `-target` command line option.
`void`
`setThrownExceptions(Class<?>[] thrownExceptions)`
Defines the exceptions that the generated method may throw.
`void`
`setThrownExceptions(Class<?>[][] thrownExceptions)`
Same as `IExpressionEvaluator.setThrownExceptions(Class[])`, but for multiple expressions.
`void`
`setWarningHandler(WarningHandler warningHandler)`
By default, warnings are discarded, but an application my install a custom `WarningHandler`.

### Methods inherited from class org.codehaus.commons.compiler.MultiCookable

`cook, cook, cook, cook, cook, cook, cook, cookFiles, cookFiles, cookFiles, cookFiles`

### Methods inherited from class org.codehaus.commons.compiler.Cookable

`cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.codehaus.commons.compiler.ICookable

`cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile`

### Methods inherited from interface org.codehaus.commons.compiler.IMultiCookable

`cook, cook, cook, cook, cook, cook, cook, cookFiles, cookFiles, cookFiles, cookFiles`

## Constructor Details

### ExpressionEvaluator

public ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes) throws CompileException
Equivalent to

         ExpressionEvaluator ee = new ExpressionEvaluator();
         ee.setExpressionType(expressionType);
         ee.setParameters(parameterNames, parameterTypes);
         ee.cook(expression);

Throws:
  `CompileException`
See Also:
  - `ExpressionEvaluator()`
  - `setExpressionType(Class)`
  - `ScriptEvaluator.setParameters(String[], Class[])`
  - `Cookable.cook(String)`

### ExpressionEvaluator

public ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader parentClassLoader) throws CompileException
Equivalent to

         ExpressionEvaluator ee = new ExpressionEvaluator();
         ee.setExpressionType(expressionType);
         ee.setParameters(parameterNames, parameterTypes);
         ee.setThrownExceptions(thrownExceptions);
         ee.setParentClassLoader(parentClassLoader);
         ee.cook(expression);

Throws:
  `CompileException`
See Also:
  - `ExpressionEvaluator()`
  - `setExpressionType(Class)`
  - `ScriptEvaluator.setParameters(String[], Class[])`
  - `ScriptEvaluator.setThrownExceptions(Class[])`
  - `SimpleCompiler.setParentClassLoader(ClassLoader)`
  - `Cookable.cook(String)`

### ExpressionEvaluator

public ExpressionEvaluator(String expression, Class<?> expressionType, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, Class<?> extendedClass, Class<?>[] implementedTypes, @Nullable ClassLoader parentClassLoader) throws CompileException
Equivalent to

         ExpressionEvaluator ee = new ExpressionEvaluator();
         ee.setExpressionType(expressionType);
         ee.setParameters(parameterNames, parameterTypes);
         ee.setThrownExceptions(thrownExceptions);
         ee.setExtendedClass(extendedClass);
         ee.setImplementedTypes(implementedTypes);
         ee.setParentClassLoader(parentClassLoader);
         ee.cook(expression);

Throws:
  `CompileException`
See Also:
  - `ExpressionEvaluator()`
  - `setExpressionType(Class)`
  - `ScriptEvaluator.setParameters(String[], Class[])`
  - `ScriptEvaluator.setThrownExceptions(Class[])`
  - `ClassBodyEvaluator.setExtendedClass(Class)`
  - `ClassBodyEvaluator.setImplementedInterfaces(Class[])`
  - `SimpleCompiler.setParentClassLoader(ClassLoader)`
  - `Cookable.cook(String)`

### ExpressionEvaluator

public ExpressionEvaluator(Scanner scanner, String className, @Nullable Class<?> extendedType, Class<?>[] implementedTypes, boolean staticMethod, Class<?> expressionType, String methodName, String[] parameterNames, Class<?>[] parameterTypes, Class<?>[] thrownExceptions, @Nullable ClassLoader parentClassLoader) throws CompileException, IOException
Creates an expression evaluator with the full configurability.

Equivalent to:

         ExpressionEvaluator ee = new ExpressionEvaluator();
         ee.setClassName(className);
         ee.setExtendedType(extendedType);
         ee.setImplementedTypes(implementedTypes);
         ee.setStaticMethod(staticMethod);
         ee.setExpressionType(expressionType);
         ee.setMethodName(methodName);
         ee.setParameters(parameterNames, parameterTypes);
         ee.setThrownExceptions(thrownExceptions);
         ee.setParentClassLoader(parentClassLoader);
         ee.cook(scanner);

Throws:
  `CompileException`
  `IOException`
See Also:
  - `IExpressionEvaluator`
  - `IClassBodyEvaluator.setClassName(String)`
  - `IClassBodyEvaluator.setExtendedClass(Class)`
  - `IClassBodyEvaluator.setImplementedInterfaces(Class[])`
  - `IScriptEvaluator.setStaticMethod(boolean)`
  - `IExpressionEvaluator.setExpressionType(Class)`
  - `IScriptEvaluator.setMethodName(String)`
  - `IScriptEvaluator.setParameters(String[], Class[])`
  - `IScriptEvaluator.setThrownExceptions(Class[])`
  - `ISimpleCompiler.setParentClassLoader(ClassLoader)`
  - `ICookable.cook(Reader)`

### ExpressionEvaluator

public ExpressionEvaluator()

## Method Details

### setParentClassLoader

public void setParentClassLoader(@Nullable ClassLoader parentClassLoader)
Description copied from interface: `IExpressionEvaluator`
The "parent class loader" is used to load referenced classes. Useful values are:

`System.getSystemClassLoader()` | The running JVM's class path
`Thread.currentThread().getContextClassLoader()` or `null` | The class loader effective for the invoking thread
`ClassLoaders.BOOTCLASSPATH_CLASS_LOADER` | The running JVM's boot class path

The parent class loader defaults to the current thread's context class loader.

Specified by:
  `setParentClassLoader` in interface `IExpressionEvaluator`

### setDebuggingInformation

public void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)
Description copied from interface: `IExpressionEvaluator`
Determines what kind of debugging information is included in the generates classes. The default is typically "`-g:none`".

Specified by:
  `setDebuggingInformation` in interface `IExpressionEvaluator`

### setSourceVersion

public void setSourceVersion(int version)
Description copied from interface: `ICookable`
Specifies the version of source code accepted, in analogy with JAVAC's `-source` command line option. May be ignored by an implementation (e.g. the `janino` implementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation. `-1` means to use a default version.

Specified by:
  `setSourceVersion` in interface `ICookable`

### setTargetVersion

public void setTargetVersion(int version)
Description copied from interface: `ICookable`
Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's `-target` command line option. Allowed values depend on the implementation. The default value also depends on the implementation. The only invariant is that the generated class files are suitable for the currently executing JVM. `-1` means to use a default version.

Specified by:
  `setTargetVersion` in interface `ICookable`

### setCompileErrorHandler

public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
Description copied from interface: `IExpressionEvaluator`
Installs an `ErrorHandler` which is invoked during compilation on each error. (By default, the compilation throws a `CompileException` on the first error and terminates.)

If the given `ErrorHandler` throws a `CompileException`, then the compilation terminates and the exception is propagated.

If the given `ErrorHandler` does not throw a `CompileException` but completes normally, then the compilation may or may not continue, depending on the error. Iff the compilation completes normally but errors were reported, then it will throw a `CompileException` indicating the number of errors.

In other words: The `ErrorHandler` may throw a `CompileException` or not, but the compilation will definitely throw a `CompileException` if one or more compile errors have occurred.

Specified by:
  `setCompileErrorHandler` in interface `IExpressionEvaluator`
Parameters:
  `compileErrorHandler` - `null` to restore the default behavior (throwing a `CompileException`)

### setWarningHandler

public void setWarningHandler(@Nullable WarningHandler warningHandler)
Description copied from interface: `IExpressionEvaluator`
By default, warnings are discarded, but an application my install a custom `WarningHandler`.

Specified by:
  `setWarningHandler` in interface `IExpressionEvaluator`
Parameters:
  `warningHandler` - `null` to indicate that no warnings be issued

### setDefaultImports

public void setDefaultImports(String... defaultImports)
Description copied from interface: `IExpressionEvaluator`
"Default imports" add to the system import "java.lang", i.e. the evaluator may refer to classes imported by default imports without having to explicitly declare IMPORT statements.

Notice that JDK 5 "static imports" are also supported, as shown here:

         sc.setDefaultImports(
             "java.util.Map",                          // Single type import
             "java.io.*",                              // Type-import-on-demand
             "static java.util.Collections.EMPTY_MAP", // Single static import
             "static java.util.Collections.*",         // Static-import-on-demand
         );

Specified by:
  `setDefaultImports` in interface `IExpressionEvaluator`

### getDefaultImports

public String[] getDefaultImports()

Specified by:
  `getDefaultImports` in interface `IExpressionEvaluator`
Returns:
  The default imports that were previously configured with `IExpressionEvaluator.setDefaultImports(String...)`

### options

public EnumSet<JaninoOption> options()

Returns:
  A reference to the currently effective compilation options; changes to it take effect immediately

### options

public ExpressionEvaluator options(EnumSet<JaninoOption> options)
Sets the options for all future compilations.

### setDefaultExpressionType

public void setDefaultExpressionType(Class<?> defaultExpressionType)
Description copied from interface: `IExpressionEvaluator`
Reconfigures the "default expression type"; if no expression type is configured for an expression, then, when cooking this `IExpressionEvaluator`, the "default expression type" is used for the expression

Specified by:
  `setDefaultExpressionType` in interface `IExpressionEvaluator`

### getDefaultExpressionType

public Class<?> getDefaultExpressionType()

Specified by:
  `getDefaultExpressionType` in interface `IExpressionEvaluator`
Returns:
  The currently configured "default expression type"
See Also:
  - `IExpressionEvaluator.setDefaultExpressionType(Class)`

### setImplementedInterfaces

public void setImplementedInterfaces(Class<?>[] implementedTypes)
Description copied from interface: `IExpressionEvaluator`
Configures the interfaces that the generated class implements.

Specified by:
  `setImplementedInterfaces` in interface `IExpressionEvaluator`

### setReturnType

public void setReturnType(Class<?> returnType)

Specified by:
  `setReturnType` in interface `IExpressionEvaluator`

### setExpressionType

public void setExpressionType(Class<?> expressionType)
Description copied from interface: `IExpressionEvaluator`
Defines the type of the expression.

Defaults to `Object``.class`, which, thanks to autoboxing, allows for any expression type (including primitive types).

If `expressionType` is `void.class`, then the expression must be an invocation of a `void` method.

Specified by:
  `setExpressionType` in interface `IExpressionEvaluator`

### setExpressionTypes

public void setExpressionTypes(Class<?>[] expressionTypes)
Description copied from interface: `IExpressionEvaluator`
Configures the types of the expressions.

Unless this method is called, all expressions have type `Object``.class`.

If any expression has type `void.class`, then it must be an invocation of a `void` method.

Specified by:
  `setExpressionTypes` in interface `IExpressionEvaluator`

### setOverrideMethod

public void setOverrideMethod(boolean overrideMethod)
Description copied from interface: `IExpressionEvaluator`
Defines whether the generated method overrides a methods declared in a supertype.

Specified by:
  `setOverrideMethod` in interface `IExpressionEvaluator`

### setOverrideMethod

public void setOverrideMethod(boolean[] overrideMethod)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.setOverrideMethod(boolean)`, but for multiple expressions.

Specified by:
  `setOverrideMethod` in interface `IExpressionEvaluator`

### setParameters

public void setParameters(String[] parameterNames, Class<?>[] parameterTypes)
Description copied from interface: `IExpressionEvaluator`
Defines the names and types of the parameters of the generated method.

names`.length` and types`.length` must be equal. This invariant may be checked immediately, or later when the expression is cooked.

The parameters can be of primitive type, e.g. `double.class`.

The default is to have zero parameters.

Specified by:
  `setParameters` in interface `IExpressionEvaluator`

### setParameters

public void setParameters(String[][] parameterNames, Class<?>[][] parameterTypes)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.setParameters(String[], Class[])`, but for multiple expressions.

Specified by:
  `setParameters` in interface `IExpressionEvaluator`

### setClassName

public void setClassName(String className)
Description copied from interface: `IExpressionEvaluator`
Sets the name of the generated class. Defaults to `IExpressionEvaluator.DEFAULT_CLASS_NAME`. In most cases, there is no need to set this name, because the generated class is loaded into its own `ClassLoader` where its name cannot collide with classes generated by other evaluators.

One reason to use this function is to have a class name in a non-default package, which can be relevant when types and members with DEFAULT accessibility are accessed.

Specified by:
  `setClassName` in interface `IExpressionEvaluator`

### setExtendedClass

public void setExtendedClass(@Nullable Class<?> extendedType)
Description copied from interface: `IExpressionEvaluator`
Sets a particular superclass that the generated class will extend. If extendedClass is `null`, the generated class will extend `Object`.

The usual reason to set a base class for an evaluator is that the generated class can directly access the superclass's (non-private) members.

Specified by:
  `setExtendedClass` in interface `IExpressionEvaluator`

### setStaticMethod

public void setStaticMethod(boolean staticMethod)
Description copied from interface: `IExpressionEvaluator`
Defines whether the generated method should be STATIC or not. Defaults to `true`.

Specified by:
  `setStaticMethod` in interface `IExpressionEvaluator`

### setStaticMethod

public void setStaticMethod(boolean[] staticMethod)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.setStaticMethod(boolean)`, but for multiple expressions.

Specified by:
  `setStaticMethod` in interface `IExpressionEvaluator`

### setMethodName

public void setMethodName(String methodName)
Description copied from interface: `IExpressionEvaluator`
Defines the name of the generated method. Initially, the method name is "eval*".

Specified by:
  `setMethodName` in interface `IExpressionEvaluator`
Parameters:
  `methodName` - `null` means reset to default name
See Also:
  - `IScriptEvaluator.DEFAULT_METHOD_NAME`

### setMethodNames

public void setMethodNames(String[] methodNames)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.setMethodName(String)`, but for multiple expressions.

Define the names of the generated methods. By default the methods have distinct and implementation-specific names.

If two expressions have the same name, then they must have different parameter types (see `IExpressionEvaluator.setParameters(String[][], Class[][])`).

Specified by:
  `setMethodNames` in interface `IExpressionEvaluator`

### setThrownExceptions

public void setThrownExceptions(Class<?>[] thrownExceptions)
Description copied from interface: `IExpressionEvaluator`
Defines the exceptions that the generated method may throw.

Specified by:
  `setThrownExceptions` in interface `IExpressionEvaluator`

### setThrownExceptions

public void setThrownExceptions(Class<?>[][] thrownExceptions)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.setThrownExceptions(Class[])`, but for multiple expressions.

Specified by:
  `setThrownExceptions` in interface `IExpressionEvaluator`

### getMethod

public Method getMethod()

Specified by:
  `getMethod` in interface `IExpressionEvaluator`
Returns:
  The generated and loaded `Method`

### getMethod

public Method getMethod(int idx)
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.getMethod()`, but for multiple expressions.

Specified by:
  `getMethod` in interface `IExpressionEvaluator`

### getResult

public Method[] getResult()

Specified by:
  `getResult` in interface `IExpressionEvaluator`
Returns:
  The generated method
Throws:
  `IllegalStateException` - The `ScriptEvaluator` has not yet be cooked

### cook

public void cook(@Nullable String fileName, Reader reader) throws CompileException, IOException
Description copied from interface: `ICookable`
Reads, scans, parses and compiles Java tokens from the given `Reader`.

Specified by:
  `cook` in interface `ICookable`
Specified by:
  `cook` in class `Cookable`
Parameters:
  `fileName` - Used when reporting errors and warnings
Throws:
  `CompileException`
  `IOException`

### cook

public void cook(String[] fileNames, Reader[] readers) throws CompileException, IOException
Description copied from interface: `IMultiCookable`
Same as `Cookable.cook(String, Reader)`, but cooks a set of documents into one class. Notice that if any of the documents causes trouble, the entire compilation will fail. If you need to report which of the documents causes the exception, you may want to use the `fileNames` parameter to distinguish between the individual token sources.

Specified by:
  `cook` in interface `IMultiCookable`
Specified by:
  `cook` in class `MultiCookable`
Throws:
  `CompileException`
  `IOException`

### cook

public final void cook(Scanner scanner) throws CompileException, IOException

Throws:
  `CompileException`
  `IOException`

### cook

public final void cook(Scanner... scanners) throws CompileException, IOException
Like `cook(Scanner)`, but cooks a set of scripts into one class. Notice that if any of the scripts causes trouble, the entire compilation will fail. If you need to report which of the scripts causes the exception, you may want to use the `fileName` argument of `Scanner(String, Reader)` to distinguish between the individual token sources.

On a 2 GHz Intel Pentium Core Duo under Windows XP with an IBM 1.4.2 JDK, compiling 10000 expressions "a + b" (integer) takes about 4 seconds and 56 MB of main memory. The generated class file is 639203 bytes large.

The number and the complexity of the scripts is restricted by the Limitations of the Java Virtual Machine, where the most limiting factor is the 64K entries limit of the constant pool. Since every method with a distinct name requires one entry there, you can define at best 32K (very simple) scripts.

If and only if the number of scanners is one, then that single script may contain leading IMPORT directives.

Throws:
  `IllegalStateException` - Any of the preceding `set...()` had an array size different from that of `scanners`
  `CompileException`
  `IOException`

### cook

public final void cook(Parser... parsers) throws CompileException, IOException

Throws:
  `CompileException`
  `IOException`
See Also:
  - `cook(Scanner[])`

### classesToTypes

protected Java.Type[] classesToTypes(Location location, @Nullable Class<?>... classes)
Converts an array of `Class`es into an array of`Java.Type`s.

### optionalClassToType

@Nullable protected Java.Type optionalClassToType(Location location, @Nullable Class<?> clazz)
Wraps a reflection `Class` in a `Java.Type` object.

### classToType

protected Java.Type classToType(Location location, Class<?> clazz)
Wraps a reflection `Class` in a `Java.Type` object.

### evaluate

@Nullable public Object evaluate() throws InvocationTargetException
Description copied from interface: `IExpressionEvaluator`
Shorthand for `evaluate``(new Object[0])`.

Specified by:
  `evaluate` in interface `IExpressionEvaluator`
Throws:
  `InvocationTargetException`

### evaluate

@Nullable public Object evaluate(@Nullable Object[] arguments) throws InvocationTargetException
Description copied from interface: `IExpressionEvaluator`
Evaluates the expression with concrete parameter values.

Each argument value must have the same type as specified through the "parameterTypes" parameter of `IExpressionEvaluator.setParameters(String[], Class[])`.

Arguments of primitive type must passed with their wrapper class objects.

The object returned has the class as specified through `IExpressionEvaluator.setExpressionType(Class)`.

This method is thread-safe.

`Null` arguments is equivalent with `new Object[0]`.

Notice: In version 3.1.8, the arguments parameter was changed from `Object[]` to `Object...`, which turned out to be a really bad decision because it caused a very ugly invocation ambiguity with `IExpressionEvaluator.evaluate(int, Object[])`. Thus, with version 3.1.10, the parameter was changed back to `Object[]`.

Specified by:
  `evaluate` in interface `IExpressionEvaluator`
Parameters:
  `arguments` - The actual parameter values
Throws:
  `InvocationTargetException`

### evaluate

@Nullable public Object evaluate(int idx, @Nullable Object[] arguments) throws InvocationTargetException
Description copied from interface: `IExpressionEvaluator`
Same as `IExpressionEvaluator.evaluate(Object[])`, but for multiple expressions.

Notice: In version 3.1.8, the arguments parameter was changed from `Object[]` to `Object...`, which turned out to be a really bad decision because it caused a very ugly invocation ambiguity with `IExpressionEvaluator.evaluate(int, Object[])`. Thus, with version 3.1.10, the parameter was changed back to `Object[]`.

Specified by:
  `evaluate` in interface `IExpressionEvaluator`
Throws:
  `InvocationTargetException`

### getClazz

public Class<?> getClazz()

Specified by:
  `getClazz` in interface `IExpressionEvaluator`
Returns:
  The generated `Class`

### getBytecodes

public Map<String,byte[]> getBytecodes()

Specified by:
  `getBytecodes` in interface `ICookable`
Returns:
  The generated Java bytecode; maps class name to bytes

### createFastExpressionEvaluator

@Deprecated public static Object createFastExpressionEvaluator(String expression, Class<?> interfaceToImplement, String[] parameterNames, @Nullable ClassLoader parentClassLoader) throws CompileException
Deprecated.
Use `createFastEvaluator(String, Class, String[])` instead:

Throws:
  `CompileException`

### createFastExpressionEvaluator

@Deprecated public static Object createFastExpressionEvaluator(Scanner scanner, String className, @Nullable Class<?> extendedType, Class<?> interfaceToImplement, String[] parameterNames, @Nullable ClassLoader parentClassLoader) throws CompileException, IOException
Deprecated.
Use `createFastEvaluator(Reader, Class, String[])` instead

Throws:
  `CompileException`
  `IOException`

### createFastExpressionEvaluator

@Deprecated public static Object createFastExpressionEvaluator(Scanner scanner, String[] defaultImports, String className, @Nullable Class<?> extendedType, Class<?> interfaceToImplement, String[] parameterNames, @Nullable ClassLoader parentClassLoader) throws CompileException, IOException
Deprecated.
Use `createFastEvaluator(Reader, Class, String[])` instead

Throws:
  `CompileException`
  `IOException`

### createFastEvaluator

public <T> T createFastEvaluator(Reader reader, Class<? extends T> interfaceToImplement, String... parameterNames) throws CompileException, IOException

Specified by:
  `createFastEvaluator` in interface `IExpressionEvaluator`
Throws:
  `CompileException`
  `IOException`
See Also:
  - `IExpressionEvaluator.createFastEvaluator(String, Class, String[])`

### createFastEvaluator

public <T> T createFastEvaluator(String script, Class<? extends T> interfaceToImplement, String... parameterNames) throws CompileException
Description copied from interface: `IExpressionEvaluator`
If the parameter and return types of the expression are known at compile time, then a "fast" expression evaluator can be instantiated through `IExpressionEvaluator.createFastEvaluator(String, Class, String[])`. Expression evaluation is faster than through `IExpressionEvaluator.evaluate(Object[])`, because it is not done through reflection but through direct method invocation.

Example:

     public interface Foo {
         int bar(int a, int b);
     }
     ...
     ExpressionEvaluator ee = CompilerFactoryFactory.getDefaultCompilerFactory().newExpressionEvaluator();

     // Optionally configure the EE here...
     ee.setClassName("Bar");
     ee.setDefaultImports(new String[] { "java.util.*" });
     ee.setExtendedClass(SomeOtherClass.class);
     ee.setParentClassLoader(someClassLoader);

     // Optionally configure the EE here...
     Foo f = (Foo) ee.createFastEvaluator(
         "a + b",                    // expression to evaluate
         Foo.class,                  // interface that describes the expression's signature
         new String[] { "a", "b" }   // the parameters' names
     );
     System.out.println("1 + 2 = " + f.bar(1, 2)); // Evaluate the expression

All other configuration (implemented type, static method, return type, method name, parameter names and types, thrown exceptions) are predetermined by the interfaceToImplement.

Notice: The `interfaceToImplement` must be accessible by the compiled class, i.e. either be declared `public`, or with `protected` or default access in the package of the compiled class (see `IExpressionEvaluator.setClassName(String)`.

Specified by:
  `createFastEvaluator` in interface `IExpressionEvaluator`
Throws:
  `CompileException`

### createFastEvaluator

public <T> T createFastEvaluator(Scanner scanner, Class<T> interfaceToImplement, String... parameterNames) throws CompileException, IOException
Notice: This method is not declared in `IScriptEvaluator`, and is hence only available in this implementation of `org.codehaus.commons.compiler`. To be independent from this particular implementation, try to switch to `createFastEvaluator(Reader, Class, String[])`.

Parameters:
  `scanner` - Source of tokens to read
Throws:
  `CompileException`
  `IOException`
See Also:
  - `createFastEvaluator(Reader, Class, String[])`

### guessParameterNames

public static String[] guessParameterNames(Scanner scanner) throws CompileException, IOException
Guess the names of the parameters used in the given expression. The strategy is to look at all "ambiguous names" in the expression (e.g. in "a.b.c.d()", the ambiguous name is "a.b.c"), and then at the first components of the ambiguous name.

- If any component starts with an upper-case letter, then ambiguous name is assumed to be a type name.
- Otherwise, it is assumed to be a parameter name.

Throws:
  `CompileException`
  `IOException`
See Also:
  - `Scanner(String, Reader)`