use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class DebuggerTests method testBreakpoints.
public void testBreakpoints() {
ExpressionCompiler compiler = new ExpressionCompiler("a = 5;\nb = 5;\n\nif (a == b) {\n\nSystem.out.println('Good');\nreturn a + b;\n}\n");
System.out.println("-------\n" + compiler.getExpression() + "\n-------\n");
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
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));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class DebuggerTests method testDebugSymbolsWithUnixLinedEndings.
public void testDebugSymbolsWithUnixLinedEndings() throws Exception {
String expr = " System.out.println( \"a1\" );\n" + " System.out.println( \"a2\" );\n" + " System.out.println( \"a3\" );\n" + " System.out.println( \"a4\" );\n";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setDebugSymbols(true);
ctx.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(ctx));
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class DebuggerTests method testDebuggerInvoke2.
public void testDebuggerInvoke2() {
count = 0;
MVELRuntime.resetDebugger();
MVELRuntime.setThreadDebugger(new Debugger() {
public int onBreak(Frame frame) {
count++;
return 0;
}
});
String src = "a1=7;\na2=8;\nSystem.out.println(\"h\");\nac=23;\nde=23;\nge=23;\ngef=34;";
ExpressionCompiler c = new ExpressionCompiler(src);
ParserContext ctx = new ParserContext();
ctx.setSourceFile("mysource");
ctx.setDebugSymbols(true);
CompiledExpression compexpr = c.compile(ctx);
System.out.println(decompile(compexpr));
MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 1);
MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 2);
MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 3);
MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 4);
MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 5);
VariableResolverFactory factory = new DefaultLocalVariableResolverFactory();
MVEL.executeDebugger(compexpr, null, factory);
System.out.println(count);
assertEquals(5, count);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
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);
CompiledExpression expr = compiler.compile(ctx);
// 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.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
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);
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.addImport("Cheese", Cheese.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(5, count);
}
Aggregations