Search in sources :

Example 41 with ExpressionCompiler

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

the class CoreConfidenceTests method testDynamicImportsInList.

public void testDynamicImportsInList() {
    ParserContext ctx = new ParserContext();
    ctx.addPackageImport("org.mvel2.tests.core.res");
    ExpressionCompiler compiler = new ExpressionCompiler("[ new User('Bobba', 'Feta') ]");
    List list = (List) executeExpression(compiler.compile(ctx));
    User user = (User) list.get(0);
    assertEquals("Bobba", user.getFirstName());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) List(java.util.List)

Example 42 with ExpressionCompiler

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

the class CoreConfidenceTests method testDynamicImportsWithIdentifierSameAsClassWithDiffCase.

public void testDynamicImportsWithIdentifierSameAsClassWithDiffCase() {
    ParserContext ctx = new ParserContext();
    ctx.addPackageImport("org.mvel2.tests.core.res");
    ctx.setStrictTypeEnforcement(false);
    ExpressionCompiler compiler = new ExpressionCompiler("bar.add(\"hello\")");
    compiler.compile(ctx);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 43 with ExpressionCompiler

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

the class CoreConfidenceTests method testParserErrorHandling.

public void testParserErrorHandling() {
    final ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler("a[");
    try {
        compiler.compile(ctx);
    } catch (Exception e) {
        return;
    }
    assertTrue(false);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) IOException(java.io.IOException)

Example 44 with ExpressionCompiler

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

the class CoreConfidenceTests method testStringConcatenation.

public void testStringConcatenation() {
    // debugging MVEL code, it seems that MVEL 'thinks' that the result of the expression:
    // "Drop +5%: "+$sb+" avg: $"+$av+" price: $"+$pr
    // is a double, and as so, he looks for a method:
    // Services.log( double );
    // but finds only:
    // Services.log( String );
    // raising the error.
    String ex = "services.log((String) \"Drop +5%: \"+$sb+\" avg: $\"+$av+\" price: $\"+$pr );";
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("$sb", String.class);
    ctx.addInput("$av", double.class);
    ctx.addInput("$pr", double.class);
    ctx.addInput("services", Services.class);
    try {
        ExpressionCompiler compiler = new ExpressionCompiler(ex);
        compiler.compile(ctx);
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Should not raise exception: " + e.getMessage());
    }
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 45 with ExpressionCompiler

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

the class CoreConfidenceTests method testAssignmentRegression.

public void testAssignmentRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("total = total + $cheese.price");
    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