Evaluates the specified String expression and makes the first two parameters available inside the script bound to variables named 'x' and 'y' respectively, returning the result. For example, this code executes without failure: assert Eval.xy(2, 4, ' x y +
(final Object x, final Object y, final String expression)
| 94 | * @throws CompilationFailedException if expression is not valid Groovy |
| 95 | */ |
| 96 | public static Object xy(final Object x, final Object y, final String expression) throws CompilationFailedException { |
| 97 | Binding b = new Binding(); |
| 98 | b.setVariable("x", x); |
| 99 | b.setVariable("y", y); |
| 100 | GroovyShell sh = new GroovyShell(b); |
| 101 | return sh.evaluate(expression); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Evaluates the specified String expression and makes the first three parameters available inside |