Search in sources :

Example 76 with ParserContext

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

the class TypesAndInferenceTests method testMultiTypeVarDeclr.

public void testMultiTypeVarDeclr() {
    String ex = "String a, b, c";
    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 77 with ParserContext

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

the class TypesAndInferenceTests method testEgressType.

public void testEgressType() {
    ExpressionCompiler compiler = new ExpressionCompiler("( $cheese )");
    ParserContext context = new ParserContext();
    context.addInput("$cheese", Cheese.class);
    assertEquals(Cheese.class, compiler.compile(context).getKnownEgressType());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 78 with ParserContext

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

the class TypesAndInferenceTests method testAnalysisCompile.

public void testAnalysisCompile() {
    ParserContext pCtx = new ParserContext();
    ExpressionCompiler e = new ExpressionCompiler("foo.aValue = 'bar'");
    e.setVerifyOnly(true);
    e.compile(pCtx);
    assertTrue(pCtx.getInputs().keySet().contains("foo"));
    assertEquals(1, pCtx.getInputs().size());
    assertEquals(0, pCtx.getVariables().size());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 79 with ParserContext

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

the class TypesAndInferenceTests method testDetermineEgressParametricType2.

public final void testDetermineEgressParametricType2() {
    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(null != typeParameters);
    assertTrue(String.class.equals(typeParameters[0]));
}
Also used : Type(java.lang.reflect.Type) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 80 with ParserContext

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

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").compile(parserContext);
    assertTrue(STRINGS.equals(executeExpression(expr, new A())));
    final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
    assertTrue(typeParameters != null);
    assertTrue(String.class.equals(typeParameters[0]));
}
Also used : Type(java.lang.reflect.Type) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

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