use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class CoreConfidenceTests method testMVEL190.
public void testMVEL190() {
ParserContext context = new ParserContext();
context.addImport(Ship.class);
context.addImport(MapObject.class);
context.addInput("obj", MapObject.class);
Object compiled = MVEL.compileExpression("((Ship) obj).getName()", context);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("obj", new Ship());
VariableResolverFactory varsResolver = new MapVariableResolverFactory(vars);
System.out.println(executeExpression(compiled, varsResolver));
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects2.
// compiled - asm
public void testThisReferenceMapVirtualObjects2() {
// Create our root Map object
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
if (!Boolean.getBoolean("mvel2.disable.jit"))
OptimizerFactory.setDefaultOptimizer("ASM");
// Run test
assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class CoreConfidenceTests method testTestIntToLong.
public void testTestIntToLong() {
String s = "1+(long)a";
ParserContext pc = new ParserContext();
pc.addInput("a", Integer.class);
ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
CompiledExpression expr = compiler.compile();
Map vars = new HashMap();
vars.put("a", 1);
Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
assertEquals(new Long(2), r);
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class DebuggerTests method testBreakpointsAcrossComments2.
public void testBreakpointsAcrossComments2() {
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
ExpressionCompiler compiler = new ExpressionCompiler(// 1
"// This is a comment\n" + // 2
"//Second comment line\n" + // 3
"//Third Comment Line\n" + // 4
"\n" + // 5
"//Test\n" + // 6
"System.out.println('4');\n" + // 7
"//System.out.println('5'); \n" + // 8
"a = 0;\n" + // 9
"b = 1;\n" + " a + b", // 10
ctx);
CompiledExpression compiled = compiler.compile();
MVELRuntime.registerBreakpoint("test2.mv", 6);
MVELRuntime.registerBreakpoint("test2.mv", 8);
MVELRuntime.registerBreakpoint("test2.mv", 9);
MVELRuntime.registerBreakpoint("test2.mv", 10);
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 0;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
assertEquals(1, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertEquals("did not break at expected lines", Make.Set.<Integer>$()._(6)._(8)._(9)._(10)._(), breaked);
}
use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mvel.
the class DebuggerTests method testBreakpointsAcrossComments.
public void testBreakpointsAcrossComments() {
String expression = // 1
"/** This is a comment\n" + // 2
" * Second comment line\n" + // 3
" * Third Comment Line\n" + // 4
" */\n" + // 5
"System.out.println('4');\n" + // 6
"System.out.println('5');\n" + // 7
"a = 0;\n" + // 8
"b = 1;\n" + // 9
"a + b";
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
ExpressionCompiler compiler = new ExpressionCompiler(expression, ctx);
System.out.println("Expression:\n------------");
System.out.println(expression);
System.out.println("------------");
CompiledExpression compiled = compiler.compile();
MVELRuntime.registerBreakpoint("test2.mv", 9);
final Set<Integer> linesEncountered = new HashSet<Integer>();
Debugger testDebugger = new Debugger() {
public int onBreak(Frame frame) {
linesEncountered.add(frame.getLineNumber());
System.out.println("Breakpoint Encountered [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
System.out.println("vars:" + frame.getFactory().getKnownVariables());
System.out.println("Resume Execution");
return 0;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
assertEquals(1, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertTrue("Debugger did not break at line 9", linesEncountered.contains(9));
}
Aggregations