use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class DebuggerTests method testBreakpointsAcrossWith.
public void testBreakpointsAcrossWith() {
String line1 = "System.out.println( \"a1\" );\n";
String line2 = "c = new Cheese();\n";
String line3 = "with ( c ) { type = 'cheddar',\n" + " price = 10 };\n";
String line4 = "System.out.println( \"a1\" );\n";
String expr = line1 + line2 + line3 + line4;
System.out.println(expr);
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.addImport("Cheese", Cheese.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile());
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(5, count);
}
use of org.mule.mvel2.compiler.ExpressionCompiler 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));
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class DebuggerTests method testDebugSymbolsSingleStatement.
public void testDebugSymbolsSingleStatement() {
String ex = "System.out.println( Cheese.STILTON );";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport(Cheese.class);
try {
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
CompiledExpression expr = compiler.compile();
// executing the following line with a MVEL.executeExpression() works fine
// but executeDebugger() fails
MVEL.executeDebugger(expr, null, (VariableResolverFactory) null);
} catch (Throwable e) {
e.printStackTrace();
fail("Should not raise exception: " + e.getMessage());
}
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class DebuggerTests method testBreakpoints3.
public void testBreakpoints3() {
String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n";
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile());
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class DebuggerTests method testBreakpoints.
public void testBreakpoints() {
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
ExpressionCompiler compiler = new ExpressionCompiler("a = 5;\nb = 5;\n\nif (a == b) {\n\nSystem.out.println('Good');\nreturn a + b;\n}\n", ctx);
System.out.println("-------\n" + compiler.getExpression() + "\n-------\n");
CompiledExpression compiled = compiler.compile();
MVELRuntime.registerBreakpoint("test.mv", 7);
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(10, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertTrue("did not break at line 7", breaked.contains(7));
}
Aggregations