Search in sources :

Example 11 with DefaultLocalVariableResolverFactory

use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory 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);
}
Also used : Debugger(org.mvel2.debug.Debugger) Frame(org.mvel2.debug.Frame) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 12 with DefaultLocalVariableResolverFactory

use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.

the class DebuggerTests method testDebuggerInvoke.

public void testDebuggerInvoke() {
    count = 0;
    MVELRuntime.resetDebugger();
    MVELRuntime.setThreadDebugger(new Debugger() {

        public int onBreak(Frame frame) {
            if (frame.getFactory().isResolveable("a1")) {
                a1++;
            }
            if (frame.getFactory().isResolveable("a4")) {
                a4++;
                System.out.println("HEI " + frame.getLineNumber());
            }
            count++;
            return 0;
        }
    });
    String src = "a1=7;\na2=8;\na3=9;\na4=10;\na5=11;\na6=12;\na7=13;\na8=14;";
    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(), 3);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 7);
    VariableResolverFactory factory = new DefaultLocalVariableResolverFactory();
    MVEL.executeDebugger(compexpr, null, factory);
    System.out.println(a1);
    System.out.println(a4);
    System.out.println(count);
    assertEquals(2, a1);
    // test passes but the breakpoint should be received by line 7, not by line 3
    assertEquals(1, a4);
    // three breakpoints FAILS
    assertEquals(3, count);
}
Also used : Debugger(org.mvel2.debug.Debugger) Frame(org.mvel2.debug.Frame) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 13 with DefaultLocalVariableResolverFactory

use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testDynamicImports3.

public void testDynamicImports3() {
    String expression = "import java.util.*; HashMap map = new HashMap(); map.size()";
    ExpressionCompiler compiler = new ExpressionCompiler(expression);
    Serializable s = compiler.compile();
    assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory()));
    assertEquals(0, MVEL.eval(expression, new HashMap()));
}
Also used : Serializable(java.io.Serializable) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)13 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)8 ItemResolverFactory (org.mvel2.integration.impl.ItemResolverFactory)4 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 CompileException (org.mvel2.CompileException)2 ParserContext (org.mvel2.ParserContext)2 CompiledExpression (org.mvel2.compiler.CompiledExpression)2 Debugger (org.mvel2.debug.Debugger)2 Frame (org.mvel2.debug.Frame)2 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)2 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)2 java.util (java.util)1 VariableResolver (org.mvel2.integration.VariableResolver)1 FunctionVariableResolverFactory (org.mvel2.integration.impl.FunctionVariableResolverFactory)1