Search in sources :

Example 46 with ExpressionCompiler

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

the class CoreConfidenceTests method testTypeRegression.

public void testTypeRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("total = 0");
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    compiler.compile(ctx);
    assertEquals(Integer.class, compiler.getParserContextState().getVarOrInputType("total"));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 47 with ExpressionCompiler

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

the class CoreConfidenceTests method testListNestedInsideList.

public void testListNestedInsideList() {
    ParserContext ctx = new ParserContext();
    ctx.addImport("User", User.class);
    ExpressionCompiler compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users.get( 0 ), users.get( 1 ) ]");
    List list = (List) executeExpression(compiler.compile(ctx), new HashMap());
    User user = (User) list.get(0);
    assertEquals("Darth", user.getFirstName());
    user = (User) list.get(1);
    assertEquals("Bobba", user.getFirstName());
    compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users[0], users[1] ]");
    list = (List) executeExpression(compiler.compile(ctx), new HashMap());
    user = (User) list.get(0);
    assertEquals("Darth", user.getFirstName());
    user = (User) list.get(1);
    assertEquals("Bobba", user.getFirstName());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) List(java.util.List)

Example 48 with ExpressionCompiler

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

the class CoreConfidenceTests method testComaProblemStrikesBack.

public void testComaProblemStrikesBack() {
    String ex = "a.explanation = \"There is a coma, in here\"";
    ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler(ex);
    Serializable s = compiler.compile(ctx);
    Base a = new Base();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("a", a);
    executeExpression(s, variables);
    assertEquals("There is a coma, in here", a.data);
}
Also used : Serializable(java.io.Serializable) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 49 with ExpressionCompiler

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

the class CoreConfidenceTests method testTestIntToLong.

public void testTestIntToLong() {
    String s = "1+(long)a";
    ParserContext pc = new ParserContext();
    pc.addInput("a", Integer.class);
    ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
    CompiledExpression expr = compiler.compile();
    Map vars = new HashMap();
    vars.put("a", 1);
    Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
    assertEquals(new Long(2), r);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 50 with ExpressionCompiler

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

the class CoreConfidenceTests method testEqualityRegression.

public void testEqualityRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("price == (new Integer( 5 ) + 5 ) ");
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)110 CompiledExpression (org.mvel2.compiler.CompiledExpression)33 ParserContext (org.mvel2.ParserContext)31 Serializable (java.io.Serializable)15 Foo (org.mvel2.tests.core.res.Foo)12 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)11 HashMap (java.util.HashMap)9 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)9 Debugger (org.mvel2.debug.Debugger)8 Frame (org.mvel2.debug.Frame)8 HashSet (java.util.HashSet)5 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)5 List (java.util.List)4 Interceptor (org.mvel2.integration.Interceptor)4 Map (java.util.Map)3 ASTNode (org.mvel2.ast.ASTNode)3 WithNode (org.mvel2.ast.WithNode)3 Type (java.lang.reflect.Type)2 LinkedHashMap (java.util.LinkedHashMap)2 Macro (org.mvel2.Macro)2