use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testsequentialAccessorsThenMethodCall.
public void testsequentialAccessorsThenMethodCall() {
String expr = "System.out.println(drools.workingMemory); " + "drools.workingMemory.ruleBase.removeRule(\"org.drools.examples\", \"some rule\"); ";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(true);
context.addInput("drools", KnowledgeHelper.class);
RuleBase ruleBase = new RuleBaseImpl();
WorkingMemory wm = new WorkingMemoryImpl(ruleBase);
KnowledgeHelper drools = new DefaultKnowledgeHelper(wm);
Map vars = new HashMap();
vars.put("drools", drools);
executeExpression(compiler.compile(context), vars);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class ArithmeticTests method testOperatorPrecedence5.
public void testOperatorPrecedence5() {
String ex = "_x_001 == _x_001 / 2 - _x_001 + _x_001 + _x_001 / 2 && _x_002 / 2 == _x_002 / 2";
Map vars = new HashMap();
vars.put("_x_001", 500.2);
vars.put("_x_002", 200.9);
vars.put("_r_001", 701);
ExpressionCompiler compiler = new ExpressionCompiler(ex);
assertEquals(true, executeExpression(compiler.compile(), vars));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testDuplicateVariableDeclaration.
public void testDuplicateVariableDeclaration() {
ExpressionCompiler compiler = new ExpressionCompiler("String x = \"abc\"; Integer x = new Integer( 10 );");
ParserContext context = new ParserContext();
try {
compiler.compile(context);
fail("Compilation must fail with duplicate variable declaration exception.");
} catch (RuntimeException ce) {
// success
}
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testSetAccessorOverloadedEqualsStrictMode.
public void testSetAccessorOverloadedEqualsStrictMode() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.bar = 0").compile(ctx);
} catch (CompileException e) {
// should fail.
e.printStackTrace();
return;
}
assertTrue(false);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class DebuggerTests method testBreakpoints5.
public void testBreakpoints5() {
OptimizerFactory.setDefaultOptimizer("ASM");
String expression = "System.out.println('foo');\r\n" + "a = new Foo244();\r\n" + "a.name = 'bar';\r\n" + "foo.happy();\r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "return a.name;";
Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
Map<String, Macro> macros = new HashMap<String, Macro>();
expression = parseMacros(expression, macros);
ExpressionCompiler compiler = new ExpressionCompiler(expression);
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
ctx.addImport("Foo244", Foo.class);
ctx.setInterceptors(interceptors);
CompiledExpression compiled = compiler.compile(ctx);
System.out.println("\nExpression:------------");
System.out.println(expression);
System.out.println("------------");
System.out.println(DebugTools.decompile(compiled));
MVELRuntime.registerBreakpoint("test2.mv", 1);
final Set<Integer> breaked = new HashSet<Integer>();
Debugger testDebugger = new Debugger() {
public int onBreak(Frame frame) {
System.out.println("Breakpoint [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
breaked.add(frame.getLineNumber());
return Debugger.STEP_OVER;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
System.out.println("\n==RUN==\n");
assertEquals("bar", MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertTrue("did not break at line 1", breaked.contains(1));
}
Aggregations