Search in sources :

Example 66 with ParserContext

use of org.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 67 with ParserContext

use of org.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 68 with ParserContext

use of org.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 69 with ParserContext

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

the class TypesAndInferenceTests method testStrongTyping3.

public void testStrongTyping3() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    try {
        new ExpressionCompiler("foo.toUC(100.5").compile(ctx);
    } catch (Exception e) {
        // should fail.
        return;
    }
    assertTrue(false);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 70 with ParserContext

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

the class TypesAndInferenceTests method testStrictTypingCompilation3.

public void testStrictTypingCompilation3() throws NoSuchMethodException {
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ExpressionCompiler compiler = new ExpressionCompiler("message='Hello';b=7;\nSystem.out.println(message + ';' + b);\n" + "System.out.println(message + ';' + b); b");
    assertEquals(7, executeExpression(compiler.compile(ctx), new DefaultLocalVariableResolverFactory()));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ParserContext (org.mvel2.ParserContext)372 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)190 HashMap (java.util.HashMap)140 Serializable (java.io.Serializable)100 ParserConfiguration (org.mvel2.ParserConfiguration)86 Map (java.util.Map)74 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)67 LinkedHashMap (java.util.LinkedHashMap)66 CompiledExpression (org.mvel2.compiler.CompiledExpression)63 CompileException (org.mvel2.CompileException)53 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)31 Foo (org.mvel2.tests.core.res.Foo)27 List (java.util.List)26 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)24 MapObject (org.mvel2.tests.core.res.MapObject)23 ArrayList (java.util.ArrayList)22 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)19 IOException (java.io.IOException)16 MVEL.evalToBoolean (org.mvel2.MVEL.evalToBoolean)16 Debugger (org.mvel2.debug.Debugger)16