Search in sources :

Example 36 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testMVEL232.

public void testMVEL232() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.setStrictTypeEnforcement(true);
    String script = "for(int i=0;i<2;i++) { " + "  System.out.println(i+\"\");" + "} " + " return true;";
    try {
        CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
        HashMap<String, Object> map = new HashMap<String, Object>();
        MVEL.executeExpression(compiled, map);
    } catch (Exception e) {
        e.printStackTrace();
        fail("should now throw an exception");
    }
}
Also used : HashMap(java.util.HashMap) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression) CompileException(org.mvel2.CompileException)

Example 37 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testDetermineEgressParametricType2.

public final void testDetermineEgressParametricType2() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("strings", List.class, new Class[] { String.class });
    final CompiledExpression expr = new ExpressionCompiler("strings", parserContext).compile();
    assertTrue(STRINGS.equals(executeExpression(expr, new A())));
/*
    final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
    assertTrue(null != typeParameters);
    assertTrue(String.class.equals(typeParameters[0]));
*/
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 38 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testDetermineEgressParametricType.

public final void testDetermineEgressParametricType() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("strings", List.class, new Class[] { String.class });
    final CompiledExpression expr = new ExpressionCompiler("strings", parserContext).compile();
    assertTrue(STRINGS.equals(executeExpression(expr, new A())));
/*
    final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
    assertTrue(typeParameters != null);
    assertTrue(String.class.equals(typeParameters[0]));
*/
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 39 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class WithTests method testInlineWithImpliedThis.

public void testInlineWithImpliedThis() {
    Base b = new Base();
    ExpressionCompiler expr = new ExpressionCompiler(".{ data = 'foo' }");
    CompiledExpression compiled = expr.compile();
    executeExpression(compiled, b);
    assertEquals(b.data, "foo");
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) Base(org.mvel2.tests.core.res.Base) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 40 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class WithTests method testExecuteCoercionTwice2.

public void testExecuteCoercionTwice2() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo", new Foo());
    vars.put("$value", new Long(5));
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);
    ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };", ctx);
    CompiledExpression compiled = compiler.compile();
    executeExpression(compiled, null, vars);
    executeExpression(compiled, null, vars);
}
Also used : HashMap(java.util.HashMap) Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Aggregations

CompiledExpression (org.mvel2.compiler.CompiledExpression)81 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)65 ParserContext (org.mvel2.ParserContext)48 HashMap (java.util.HashMap)20 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)20 Foo (org.mvel2.tests.core.res.Foo)20 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)15 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)14 DataType (org.mule.runtime.api.metadata.DataType)11 HashSet (java.util.HashSet)10 Test (org.junit.Test)9 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)9 ParserContext (org.mule.mvel2.ParserContext)8 Map (java.util.Map)6 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)6 CompileException (org.mvel2.CompileException)6 ASTNode (org.mvel2.ast.ASTNode)6 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)6