use of org.mule.mvel2.compiler.CompiledExpression 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.CompiledExpression 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.CompiledExpression 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));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class TypesAndInferenceTests method testMVEL236.
public void testMVEL236() {
StringBuffer buffer = new StringBuffer();
buffer.append("MyInterface2 var2 = (MyInterface2)var1;");
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("var1", MyInterface3.class);
ctx.addImport(MyInterface2.class);
ctx.addImport(MyInterface3.class);
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class TypesAndInferenceTests method testSetAccessorOverloadedEqualsStrictMode2.
public void testSetAccessorOverloadedEqualsStrictMode2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.aValue = 'bar'", ctx).compile();
} catch (CompileException e) {
assertTrue(false);
}
}
Aggregations