/** * Evaluates the specified String expression and returns the result. For example: * <pre class="groovyTestCase"> * assert Eval.me(' 2 * 4 + 2') == 10 * </pre> * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is not valid Groovy */ public static Object me(final String expression) throws CompilationFailedException { return me(null, null, expression); }
public void testX() throws CompilationFailedException { Object result = Eval.x(new Integer(10), "x"); assertEquals("10", result.toString()); }
public void testXY() throws CompilationFailedException { Integer ten = new Integer(10); Object result = Eval.xy(ten, ten, "x+y"); assertEquals("20", result.toString()); }
public void testXYZ() throws CompilationFailedException { Integer ten = new Integer(10); Object result = Eval.xyz(ten, ten, ten, "x+y+z"); assertEquals("30", result.toString()); } }
/** * Evaluates the specified String expression and makes the parameter available inside * the script bound to a variable named 'x', returning the result. For example, this * code executes without failure: * <pre class="groovyTestCase"> * assert Eval.x(2, ' x * 4 + 2') == 10 * </pre> * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is not valid Groovy */ public static Object x(final Object x, final String expression) throws CompilationFailedException { return me("x", x, expression); }
public Object propertyMissing(String propName) { Attribute result = findAttributeByPropertyName(propName); if (null == result) { String message = "The presentation model doesn't understand '" + propName + "'. \n"; message += "Known attribute names are: " + Eval.x(attributes, "x.collect{it.propertyName}"); throw new MissingPropertyException(message, propName, this.getClass()); } return result; }
public void testMeSimple() throws CompilationFailedException { Object result = Eval.me("10"); assertEquals("10", result.toString()); }
public static void configureDomainBinder(GrailsApplication grailsApplication, Set<GrailsDomainClass> domainClasses) { Object defaultMapping = Eval.x(grailsApplication, "x.config?.grails?.gorm?.default?.mapping"); // do Grails class configuration for (GrailsDomainClass domainClass : domainClasses) { if (defaultMapping instanceof Closure) { GrailsDomainBinder.evaluateMapping(domainClass, (Closure<?>)defaultMapping); } else { GrailsDomainBinder.evaluateMapping(domainClass); } } } }
public void testMeWithSymbolAndObject() throws CompilationFailedException { Object result = Eval.me("x", new Integer(10), "x"); assertEquals("10", result.toString()); }
/** * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object me(final String expression) throws CompilationFailedException { return me(null, null, expression); }
/** * evaluate expression and make x available inside the expression as 'x' * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object x(final Object x, final String expression) throws CompilationFailedException { return me("x", x, expression); }
/** * Evaluates the specified String expression and returns the result. For example: * <pre> * assert 10 == Eval.me(' 2 * 4 + 2') * </pre> * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is not valid Groovy */ public static Object me(final String expression) throws CompilationFailedException { return me(null, null, expression); }
/** * evaluate expression and make x available inside the expression as 'x' * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object x(final Object x, final String expression) throws CompilationFailedException { return me("x", x, expression); }
/** * evaluate expression and make x available inside the expression as 'x' * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object x(final Object x, final String expression) throws CompilationFailedException { return me("x", x, expression); }
/** * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object me(final String expression) throws CompilationFailedException { return me(null, null, expression); }
/** * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is no proper Groovy */ public static Object me(final String expression) throws CompilationFailedException { return me(null, null, expression); }
/** * Evaluates the specified String expression and makes the parameter available inside * the script bound to a variable named 'x', returning the result. For example, this * code executes without failure: * <pre> * assert 10 == Eval.x(2, ' x * 4 + 2') * </pre> * @param expression the Groovy expression to evaluate * @return the result of the expression * @throws CompilationFailedException if expression is not valid Groovy */ public static Object x(final Object x, final String expression) throws CompilationFailedException { return me("x", x, expression); }