Search in sources :

Example 91 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler 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 92 with ExpressionCompiler

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

the class TypesAndInferenceTests method testVarInputs2.

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

Example 93 with ExpressionCompiler

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

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()", ctx);
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 94 with ExpressionCompiler

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

the class TypesAndInferenceTests method testStrictStrongTypingCompilationErrors1.

public void testStrictStrongTypingCompilationErrors1() throws Exception {
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ctx.setStrongTyping(true);
    ctx.addImport(Foo.class);
    ctx.addInput("$bar", Bar.class);
    try {
        ExpressionCompiler compiler = new ExpressionCompiler("System.out.println( $ba );", ctx);
        compiler.compile();
        fail("This should not compileShared");
    } catch (Exception e) {
    }
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompileException(org.mvel2.CompileException)

Example 95 with ExpressionCompiler

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

the class TypesAndInferenceTests method testParameterizedTypeInStrictMode2.

public void testParameterizedTypeInStrictMode2() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("ctx", Object.class);
    ExpressionCompiler compiler = new ExpressionCompiler("org.mvel2.DataConversion.convert(ctx, String).toUpperCase()", ctx);
    assertEquals(String.class, compiler.compile().getKnownEgressType());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

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