Search in sources :

Example 96 with ExpressionCompiler

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

the class CoreConfidenceTests method testStaticNestedWithImport.

public void testStaticNestedWithImport() {
    String expr = "Message.GOODBYE;\n";
    ExpressionCompiler compiler = new ExpressionCompiler(expr);
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(false);
    context.addImport("Message", Message.class);
    assertEquals(1, executeExpression(compiler.compile(context)));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 97 with ExpressionCompiler

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

the class CoreConfidenceTests method testParsingStability2.

public void testParsingStability2() {
    ExpressionCompiler compiler = new ExpressionCompiler("( dim.height == 1 || dim.height == ( 1+1) || dim.height == x )");
    Map<String, Object> imports = new HashMap<String, Object>();
    imports.put("java.awt.Dimension", Dimension.class);
    final ParserContext parserContext = new ParserContext(imports, null, "sourceFile");
    parserContext.setStrictTypeEnforcement(false);
    compiler.compile(parserContext);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 98 with ExpressionCompiler

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

the class CoreConfidenceTests method testConcatWithLineBreaks.

public void testConcatWithLineBreaks() {
    ExpressionCompiler parser = new ExpressionCompiler("\"foo\"+\n\"bar\"");
    ParserContext ctx = new ParserContext();
    ctx.setDebugSymbols(true);
    ctx.setSourceFile("source.mv");
    assertEquals("foobar", executeExpression(parser.compile(ctx)));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 99 with ExpressionCompiler

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

the class CoreConfidenceTests method testLateResolveOfClass.

public void testLateResolveOfClass() {
    ExpressionCompiler compiler = new ExpressionCompiler("System.out.println(new Foo());");
    ParserContext ctx = new ParserContext();
    ctx.addImport(Foo.class);
    compiler.removeParserContext();
    System.out.println(executeExpression(compiler.compile(ctx)));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 100 with ExpressionCompiler

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

the class TypesAndInferenceTests method testDetermineRequiredInputsInConstructor.

public void testDetermineRequiredInputsInConstructor() throws Exception {
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(false);
    ctx.setStrongTyping(false);
    ctx.addImport(Foo.class);
    ExpressionCompiler compiler = new ExpressionCompiler("new Foo244( $bar,  $bar.age );");
    Serializable compiled = compiler.compile(ctx);
    Set<String> requiredInputs = compiler.getParserContextState().getInputs().keySet();
    assertEquals(1, requiredInputs.size());
    assertTrue(requiredInputs.contains("$bar"));
}
Also used : Serializable(java.io.Serializable) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)108 CompiledExpression (org.mvel2.compiler.CompiledExpression)32 ParserContext (org.mvel2.ParserContext)30 Serializable (java.io.Serializable)14 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