Search in sources :

Example 46 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testTestIntToLong.

public void testTestIntToLong() {
    String s = "1+(long)a";
    ParserContext pc = new ParserContext();
    pc.addInput("a", Integer.class);
    ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
    CompiledExpression expr = compiler.compile();
    Map vars = new HashMap();
    vars.put("a", 1);
    Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
    assertEquals(new Long(2), r);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 47 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testEqualityRegression.

public void testEqualityRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("price == (new Integer( 5 ) + 5 ) ");
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 48 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class ArithmeticTests method testJIRA161.

public void testJIRA161() {
    Serializable s = MVEL.compileExpression("1==-(-1)", ParserContext.create().stronglyTyped());
    assertEquals(1 == -(-1), MVEL.executeExpression(s));
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    CompiledExpression compiledExpression = new ExpressionCompiler("1==-(-1)").compile(ctx);
    assertEquals(1 == -(-1), MVEL.executeExpression(compiledExpression));
}
Also used : Serializable(java.io.Serializable) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 49 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class ArithmeticTests method testStrongTypingModeComparison.

public void testStrongTypingModeComparison() {
    ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("a", Long.class);
    CompiledExpression compiledExpression = new ExpressionCompiler("a==0").compile(parserContext);
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("a", 0l);
    MVEL.executeExpression(compiledExpression, variables);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 50 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project drools by kiegroup.

the class ResultVerifier method isSuccess.

protected Boolean isSuccess(VerifyField currentField) {
    String s = "__fact__." + currentField.getFieldName() + " " + currentField.getOperator() + " __expected__";
    CompiledExpression expression = new ExpressionCompiler(s, parserContext).compile();
    return (Boolean) MVELSafeHelper.getEvaluator().executeExpression(expression, variables);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)219 ParserContext (org.mvel2.ParserContext)119 CompiledExpression (org.mvel2.compiler.CompiledExpression)65 HashMap (java.util.HashMap)39 Serializable (java.io.Serializable)30 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)22 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 Map (java.util.Map)18 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 LinkedHashMap (java.util.LinkedHashMap)15 HashSet (java.util.HashSet)10 List (java.util.List)10 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10 ArrayList (java.util.ArrayList)8 CompileException (org.mvel2.CompileException)8 Interceptor (org.mvel2.integration.Interceptor)8 Macro (org.mvel2.Macro)6 ASTNode (org.mvel2.ast.ASTNode)6