Search in sources :

Example 51 with Foo

use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.

the class TypesAndInferenceTests method testStrictTypingCompilation4.

public void testStrictTypingCompilation4() throws NoSuchMethodException {
    ParserContext ctx = new ParserContext();
    ctx.addImport(Foo.class);
    ctx.setStrictTypeEnforcement(true);
    ExpressionCompiler compiler = new ExpressionCompiler("x_a = new Foo()");
    compiler.compile(ctx);
    assertEquals(Foo.class, ctx.getVariables().get("x_a"));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 52 with Foo

use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.

the class TypesAndInferenceTests method testMultiTypeVarDeclr2.

public void testMultiTypeVarDeclr2() {
    String ex = "String a = 'foo', b = 'baz', c = 'bar'";
    ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler(ex);
    compiler.compile(ctx);
    assertNotNull(ctx.getVariables());
    assertEquals(3, ctx.getVariables().entrySet().size());
    for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
        assertEquals(String.class, entry.getValue());
    }
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 53 with Foo

use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.

the class TypesAndInferenceTests method testParameterizedTypeInStrictMode.

public void testParameterizedTypeInStrictMode() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("foo", HashMap.class, new Class[] { String.class, String.class });
    ExpressionCompiler compiler = new ExpressionCompiler("foo.get('bar').toUpperCase()");
    compiler.compile(ctx);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 54 with Foo

use of org.mvel2.tests.core.res.Foo 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 55 with Foo

use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.

the class TypesAndInferenceTests method testVarInputs2.

public void testVarInputs2() {
    ExpressionCompiler compiler = new ExpressionCompiler("test != foo && bo.addSomething(trouble); String bleh = foo; twa = bleh;");
    ParserContext ctx = new ParserContext();
    compiler.compile(ctx);
    System.out.println(ctx.getVarOrInputType("bleh"));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)27 Foo (org.mvel2.tests.core.res.Foo)22 ParserContext (org.mvel2.ParserContext)18 CompiledExpression (org.mvel2.compiler.CompiledExpression)15 Serializable (java.io.Serializable)14 HashMap (java.util.HashMap)12 Test (org.junit.Test)9 KieServices (org.kie.api.KieServices)9 KieFileSystem (org.kie.api.builder.KieFileSystem)9 ReleaseId (org.kie.api.builder.ReleaseId)9 KieContainer (org.kie.api.runtime.KieContainer)9 PropertyAccessException (org.mvel2.PropertyAccessException)9 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)9 KieSession (org.kie.api.runtime.KieSession)8 ConsequenceException (org.kie.api.runtime.rule.ConsequenceException)7 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)7 Map (java.util.Map)5 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)5 Interceptor (org.mvel2.integration.Interceptor)4 ASTNode (org.mvel2.ast.ASTNode)3