Search in sources :

Example 6 with CompiledExpression

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

the class WithTests method testInlineWith5.

public void testInlineWith5() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    ParserContext pCtx = new ParserContext();
    pCtx.setStrongTyping(true);
    pCtx.addInput("foo", Foo.class);
    CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile(pCtx);
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 7 with CompiledExpression

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

the class MutationsTests method testDeepAssignment2.

public void testDeepAssignment2() {
    Map map = createTestMap();
    ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
    ParserContext ctx = new ParserContext();
    ctx.addInput("foo", Foo.class);
    ctx.setStrongTyping(true);
    CompiledExpression ce = compiler.compile(ctx);
    executeExpression(ce, map);
    assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 8 with CompiledExpression

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

the class MutationsTests method testUnQualifiedStaticTyping.

public void testUnQualifiedStaticTyping() {
    CompiledExpression ce = (CompiledExpression) compileExpression("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ");
    assertEquals(new BigDecimal(20), testCompiledSimple("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ", new HashMap()));
}
Also used : HashMap(java.util.HashMap) CompiledExpression(org.mvel2.compiler.CompiledExpression) BigDecimal(java.math.BigDecimal)

Example 9 with CompiledExpression

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

the class TypesAndInferenceTests method testMVEL228.

public void testMVEL228() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.setStrictTypeEnforcement(true);
    HashMap<String, Class> params = new HashMap<String, Class>();
    params.put("helper", ScriptHelper228.class);
    params.put("person", Person228.class);
    ctx.setInputs(params);
    String script = "helper.methodB(2);\n" + "person.getName2();";
    try {
        CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
    } catch (Exception e) {
        return;
    }
    fail("Should have thrown an exception");
}
Also used : CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 10 with CompiledExpression

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

the class TypesAndInferenceTests method testMVEL234.

public void testMVEL234() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("import java.text.SimpleDateFormat;");
    buffer.append("if (\"test\".matches(\"[0-9]\")) {");
    buffer.append("  return false;");
    buffer.append("}else{");
    buffer.append("  SimpleDateFormat sqf = new SimpleDateFormat(\"yyyyMMdd\");");
    buffer.append("}");
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    try {
        CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : CompiledExpression(org.mvel2.compiler.CompiledExpression)

Aggregations

CompiledExpression (org.mvel2.compiler.CompiledExpression)38 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)34 ParserContext (org.mvel2.ParserContext)21 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)10 Foo (org.mvel2.tests.core.res.Foo)10 Debugger (org.mvel2.debug.Debugger)8 Frame (org.mvel2.debug.Frame)8 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 ASTNode (org.mvel2.ast.ASTNode)5 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)4 Serializable (java.io.Serializable)3 Interceptor (org.mvel2.integration.Interceptor)3 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)3 Type (java.lang.reflect.Type)2 Macro (org.mvel2.Macro)2 WithNode (org.mvel2.ast.WithNode)2 Base (org.mvel2.tests.core.res.Base)2 ASTIterator (org.mvel2.util.ASTIterator)2 ASTLinkedList (org.mvel2.util.ASTLinkedList)2