Search in sources :

Example 41 with CompiledExpression

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

the class TypesAndInferenceTests method testParameterizedTypeInStrictMode4.

public void testParameterizedTypeInStrictMode4() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("base", Base.class);
    ExpressionCompiler compiler = new ExpressionCompiler("base.list.get(1).toUpperCase()");
    CompiledExpression ce = compiler.compile(ctx);
    assertEquals(String.class, ce.getKnownEgressType());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 42 with CompiledExpression

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

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 : CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 43 with CompiledExpression

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

the class TypesAndInferenceTests method testSetAccessorOverloadedEqualsStrictMode2.

public void testSetAccessorOverloadedEqualsStrictMode2() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("foo", Foo.class);
    try {
        CompiledExpression expr = new ExpressionCompiler("foo.aValue = 'bar'").compile(ctx);
    } catch (CompileException e) {
        assertTrue(false);
    }
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 44 with CompiledExpression

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

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 45 with CompiledExpression

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

the class WithTests method testInlineWith.

public void testInlineWith() {
    CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile();
    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) 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