Search in sources :

Example 21 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

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;";
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("mysource");
    ctx.setDebugSymbols(true);
    ExpressionCompiler c = new ExpressionCompiler(src, ctx);
    CompiledExpression compexpr = c.compile();
    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 22 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

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;";
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("mysource");
    ctx.setDebugSymbols(true);
    ExpressionCompiler c = new ExpressionCompiler(src, ctx);
    CompiledExpression compexpr = c.compile();
    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 23 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class FunctionsTest method testFunctionReuse.

public void testFunctionReuse() {
    VariableResolverFactory functionFactory = new MapVariableResolverFactory();
    MVEL.eval("def foo() { \"foo\"; }; def bar() { \"bar\" };", functionFactory);
    VariableResolverFactory myVarFactory = new MapVariableResolverFactory();
    myVarFactory.setNextFactory(functionFactory);
    Serializable s = MVEL.compileExpression("foo() + bar();");
    assertEquals("foobar", MVEL.executeExpression(s, myVarFactory));
}
Also used : Serializable(java.io.Serializable) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 24 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class NullSafe method getValue.

public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    if (ctx == null)
        return null;
    if (nextNode == null) {
        final Accessor a = OptimizerFactory.getAccessorCompiler(OptimizerFactory.SAFE_REFLECTIVE).optimizeAccessor(pCtx, expr, start, offset, ctx, elCtx, variableFactory, true, ctx.getClass());
        nextNode = new AccessorNode() {

            public AccessorNode getNextNode() {
                return null;
            }

            public AccessorNode setNextNode(AccessorNode accessorNode) {
                return null;
            }

            public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
                return a.getValue(ctx, elCtx, variableFactory);
            }

            public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) {
                return a.setValue(ctx, elCtx, variableFactory, value);
            }

            public Class getKnownEgressType() {
                return a.getKnownEgressType();
            }
        };
    }
    // else {
    return nextNode.getValue(ctx, elCtx, variableFactory);
// }
}
Also used : AccessorNode(org.mvel2.compiler.AccessorNode) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) Accessor(org.mvel2.compiler.Accessor)

Example 25 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class SharedFuncLib method eval.

public <T> T eval(String formula, Map<String, Object> context, Class<T> toType) {
    VariableResolverFactory myVariableResolverFactory = new MapVariableResolverFactory();
    myVariableResolverFactory.setNextFactory(functionFactory);
    return MVEL.eval(formula, context, myVariableResolverFactory, toType);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)54 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)28 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 HashMap (java.util.HashMap)18 ParserContext (org.mvel2.ParserContext)10 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)10 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)9 CompiledExpression (org.mvel2.compiler.CompiledExpression)9 ASTNode (org.mvel2.ast.ASTNode)8 Debugger (org.mvel2.debug.Debugger)8 Frame (org.mvel2.debug.Frame)8 Interceptor (org.mvel2.integration.Interceptor)8 LinkedHashMap (java.util.LinkedHashMap)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 WithNode (org.mvel2.ast.WithNode)6 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)6 MapObject (org.mvel2.tests.core.res.MapObject)6 Macro (org.mvel2.Macro)4 Foo (org.mvel2.tests.core.res.Foo)4 DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)3