use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testStaticNestedWithMethodCall.
public void testStaticNestedWithMethodCall() {
String expr = "item = new Item( \"Some Item\"); $msg.addItem( item ); return $msg";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(false);
context.addImport("Message", Message.class);
context.addImport("Item", Item.class);
// Serializable compiledExpression = compiler.compileShared(context);
Map vars = new HashMap();
vars.put("$msg", new Message());
Message msg = (Message) executeExpression(compiler.compile(context), vars);
Item item = (Item) msg.getItems().get(0);
assertEquals("Some Item", item.getName());
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrictTypingCompilation2.
public void testStrictTypingCompilation2() throws Exception {
ParserContext ctx = new ParserContext();
// noinspection RedundantArrayCreation
ctx.addImport("getRuntime", new MethodStub(Runtime.class.getMethod("getRuntime", new Class[] {})));
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("getRuntime()");
StaticMethodImportResolverFactory si = new StaticMethodImportResolverFactory(ctx);
Serializable expression = compiler.compile(ctx);
serializationTest(expression);
assertTrue(executeExpression(expression, si) instanceof Runtime);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testTypeByMethod.
public final void testTypeByMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
CompiledExpression compiledExpression = new ExpressionCompiler("!a.show").compile(context);
assertEquals(Boolean.class, compiledExpression.getKnownEgressType());
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testIncrementAndAssignWithInputs.
public void testIncrementAndAssignWithInputs() {
ExpressionCompiler compiler = new ExpressionCompiler("total += cheese");
compiler.compile();
assertTrue(compiler.getParserContextState().getInputs().containsKey("total"));
assertTrue(compiler.getParserContextState().getInputs().containsKey("cheese"));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testCompileWithNewInsideMethodCall.
public void testCompileWithNewInsideMethodCall() {
String expr = " p.name = \"goober\";\n" + " System.out.println(p.name);\n" + " drools.insert(new Address(\"Latona\"));\n";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(false);
context.addImport("Person", Person.class);
context.addImport("Address", Address.class);
context.addInput("p", Person.class);
context.addInput("drools", Drools.class);
compiler.compile(context);
}
Aggregations