Interface IExpressionEvaluator

All Superinterfaces:
ICookable, IMultiCookable
All Known Implementing Classes:
ExpressionEvaluator, ExpressionEvaluator

public interface IExpressionEvaluator extends ICookable, IMultiCookable
An engine that evaluates expressions in JVM bytecode.

The syntax of the expression to compile is that of a Java expression, as defined in JLS7, section 15. Notice that a Java expression does not have a concluding semicolon.

Example:

   a + 7 * b
 

(Notice that this expression refers to two parameters "a" and "b", as explained below.)

The expression may optionally be preceeded with a sequence of import directives like

   import java.text.*;
   new DecimalFormat("####,###.##").format(10200020.345345)
 

(Notice that the import directive is concluded with a semicolon, while the expression is not.) This feature is not available if you compile many expressions at a time (see below).

To set up an IExpressionEvaluator object, proceed as follows:

  1. Create an IExpressionEvaluator-derived class
  2. Configure the IExpressionEvaluator by calling any of the following methods:
  3. Call any of the ICookable.cook(String, java.io.Reader) methods to scan, parse, compile and load the expression into the JVM.

After the IExpressionEvaluator object is set up, the expression can be evaluated as often with different parameter values (see evaluate(Object[])). This evaluation is very fast, compared to the compilation.

Less common methods exist that allow for the specification of the name of the generated class, the class it extends, the interfaces it implements, the name of the method that executes the expression, the exceptions that this method (i.e. the expression) is allowed to throw, and the ClassLoader that is used to define the generated class and to load classes referenced by the expression.

If you want to compile many expressions at the same time, you have the option to cook an array of expressions in one IExpressionEvaluator by using the following methods:

Notice that these methods have array parameters in contrast to their one-expression brethren.

Notice that for functionally identical IExpressionEvaluators, Object.equals(java.lang.Object) will return true. E.g. "a+b" and "c + d" are functionally identical if "a" and "c" have the same type, and so do "b" and "d".

'JLS7' refers to the Java Language Specification, Java SE 7 Edition.