Search in sources :

Example 21 with ParserContext

use of org.mule.mvel2.ParserContext in project mvel by mikebrock.

the class GenericsTypeInferenceTest method testInferLastTypeParametersFromMethod.

public final void testInferLastTypeParametersFromMethod() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("a", A.class);
    final CompiledExpression compiledExpression = new ExpressionCompiler("a.values()").compile(context);
    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
    assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
    assertTrue("No type parameters detected", null != context.getLastTypeParameters());
    assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 22 with ParserContext

use of org.mule.mvel2.ParserContext in project mvel by mikebrock.

the class GenericsTypeInferenceTest method testInferLastTypeParametersFromPropertyMethod.

public final void testInferLastTypeParametersFromPropertyMethod() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("a", A.class);
    final CompiledExpression compiledExpression = new ExpressionCompiler("a.getFooMap()[\"key\"].someMethod()").compile(context);
    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
    assertEquals("Expression did not evaluate correctly: ", "bar", val);
    assertNotNull("No type parameters detected", context.getLastTypeParameters());
    assertEquals("Wrong parametric type inferred", String.class, context.getLastTypeParameters()[0]);
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 23 with ParserContext

use of org.mule.mvel2.ParserContext in project mvel by mikebrock.

the class GenericsTypeInferenceTest method testInferLastTypeParametersFromProperty.

public final void testInferLastTypeParametersFromProperty() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("a", A.class);
    final CompiledExpression compiledExpression = new ExpressionCompiler("a.strings").compile(context);
    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
    assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
    assertTrue("No type parameters detected", null != context.getLastTypeParameters());
    assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 24 with ParserContext

use of org.mule.mvel2.ParserContext in project mvel by mikebrock.

the class ArraysTests method testArrayLength.

public void testArrayLength() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("x", String[].class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) ParserContext(org.mvel2.ParserContext)

Example 25 with ParserContext

use of org.mule.mvel2.ParserContext in project mvel by mikebrock.

the class ArraysTests method testArrayCoercion1.

public void testArrayCoercion1() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("bar", Bar.class);
    Serializable s = compileSetExpression("bar.intarray[0]", ctx);
    Foo foo = new Foo();
    executeSetExpression(s, foo, "12");
    assertEquals(12, foo.getBar().getIntarray()[0].intValue());
    foo = new Foo();
    executeSetExpression(s, foo, "13");
    assertEquals(13, foo.getBar().getIntarray()[0].intValue());
    OptimizerFactory.setDefaultOptimizer("ASM");
    ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("bar", Bar.class);
    s = compileSetExpression("bar.intarray[0]", ctx);
    foo = new Foo();
    executeSetExpression(s, foo, "12");
    assertEquals(12, foo.getBar().getIntarray()[0].intValue());
    executeSetExpression(s, foo, "13");
    assertEquals(13, foo.getBar().getIntarray()[0].intValue());
}
Also used : Serializable(java.io.Serializable) Foo(org.mvel2.tests.core.res.Foo) ParserContext(org.mvel2.ParserContext)

Aggregations

ParserContext (org.mvel2.ParserContext)340 HashMap (java.util.HashMap)128 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)119 Serializable (java.io.Serializable)82 ParserConfiguration (org.mvel2.ParserConfiguration)70 Map (java.util.Map)64 LinkedHashMap (java.util.LinkedHashMap)62 CompiledExpression (org.mvel2.compiler.CompiledExpression)48 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)42 CompileException (org.mvel2.CompileException)37 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)23 ArrayList (java.util.ArrayList)20 List (java.util.List)19 MapObject (org.mvel2.tests.core.res.MapObject)18 Debugger (org.mvel2.debug.Debugger)15 Frame (org.mvel2.debug.Frame)15 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)14 HashSet (java.util.HashSet)12 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10