Search in sources :

Example 16 with ParserContext

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

the class CoreConfidenceTests method testParserErrorHandling.

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

Example 17 with ParserContext

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

the class CoreConfidenceTests method testContextFieldNotFound.

public void testContextFieldNotFound() {
    String str = "'stilton'.equals( type );";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.addInput("this", Cheese.class);
    pctx.setStrictTypeEnforcement(true);
    pctx.setStrongTyping(true);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Cheese(org.mvel2.tests.core.res.Cheese) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 18 with ParserContext

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

the class CoreConfidenceTests method testFieldNameWithUnderscore.

public void testFieldNameWithUnderscore() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrictTypeEnforcement(true);
    parserContext.setStrongTyping(true);
    parserContext.addInput("this", Underscore.class);
    Underscore underscore = new Underscore();
    assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("_id == \"test\"", parserContext), underscore));
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 19 with ParserContext

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

the class CoreConfidenceTests method testRegExWithCast.

public void testRegExWithCast() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("this", Foo.class);
    assertEquals(Boolean.class, MVEL.analyze("(String)bar.name ~= '[a-z].+'", parserContext));
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 20 with ParserContext

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

the class CoreConfidenceTests method testEmpty.

public void testEmpty() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    Serializable s = compileExpression("list = new java.util.ArrayList(); list == empty", ctx);
    Map vars = new HashMap();
    Boolean x = (Boolean) executeExpression(s, vars);
    assertNotNull(x);
    assertTrue(x.booleanValue());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ParserContext (org.mvel2.ParserContext)340 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)189 HashMap (java.util.HashMap)132 Serializable (java.io.Serializable)92 ParserConfiguration (org.mvel2.ParserConfiguration)70 Map (java.util.Map)68 CompiledExpression (org.mvel2.compiler.CompiledExpression)63 LinkedHashMap (java.util.LinkedHashMap)62 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)60 CompileException (org.mvel2.CompileException)51 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)28 Foo (org.mvel2.tests.core.res.Foo)27 List (java.util.List)26 ArrayList (java.util.ArrayList)22 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)21 MapObject (org.mvel2.tests.core.res.MapObject)19 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)14 IOException (java.io.IOException)13