use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class DebuggerTests method testBreakpoints2.
public void testBreakpoints2() {
ExpressionCompiler compiler = new ExpressionCompiler("System.out.println('test the debugger');\n a = 0;");
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
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";
ExpressionCompiler compiler = new ExpressionCompiler(expression);
System.out.println("Expression:\n------------");
System.out.println(expression);
System.out.println("------------");
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
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));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class MacroProcessorTest method testMacroSupportWithDebugging.
public void testMacroSupportWithDebugging() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("foo", new Foo());
Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
Map<String, Macro> macros = new HashMap<String, Macro>();
interceptors.put("Modify", new Interceptor() {
public int doBefore(ASTNode node, VariableResolverFactory factory) {
((WithNode) node).getNestedStatement().getValue(null, factory);
factory.createVariable("mod", "FOOBAR!");
return 0;
}
public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) {
return 0;
}
});
macros.put("modify", new Macro() {
public String doMacro() {
return "@Modify with";
}
});
ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("System.out.println('hello');\n" + "System.out.println('bye');\n" + "modify (foo) { aValue = 'poo', \n" + " aValue = 'poo' };\n mod", macros));
// compiler.setDebugSymbols(true);
ParserContext ctx = new ParserContext(null, interceptors, null);
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
MVELRuntime.setThreadDebugger(new Debugger() {
public int onBreak(Frame frame) {
System.out.println(frame.getSourceName() + ":" + frame.getLineNumber());
return Debugger.STEP;
}
});
MVELRuntime.registerBreakpoint("test.mv", 3);
System.out.println(DebugTools.decompile(compiled));
Assert.assertEquals("FOOBAR!", MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(vars)));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testParameterizedTypeInStrictMode4.
public void testParameterizedTypeInStrictMode4() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("base", Base.class);
ExpressionCompiler compiler = new ExpressionCompiler("base.list.get(1).toUpperCase()");
CompiledExpression ce = compiler.compile(ctx);
assertEquals(String.class, ce.getKnownEgressType());
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL232.
public void testMVEL232() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
String script = "for(int i=0;i<2;i++) { " + " System.out.println(i+\"\");" + "} " + " return true;";
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
HashMap<String, Object> map = new HashMap<String, Object>();
MVEL.executeExpression(compiled, map);
} catch (Exception e) {
e.printStackTrace();
fail("should now throw an exception");
}
}
Aggregations