Search in sources :

Example 41 with VariableResolverFactory

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

the class ForEachNode method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item);
    ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
    Object iterCond = condition.getValue(ctx, thisValue, factory);
    if (type == -1) {
        determineIterType(iterCond.getClass());
    }
    Object v;
    switch(type) {
        case ARRAY:
            int len = Array.getLength(iterCond);
            for (int i = 0; i < len; i++) {
                itemR.setValue(Array.get(iterCond, i));
                v = compiledBlock.getValue(ctx, thisValue, itemFactory);
                if (itemFactory.tiltFlag())
                    return v;
            }
            break;
        case CHARSEQUENCE:
            for (Object o : iterCond.toString().toCharArray()) {
                itemR.setValue(o);
                v = compiledBlock.getValue(ctx, thisValue, itemFactory);
                if (itemFactory.tiltFlag())
                    return v;
            }
            break;
        case INTEGER:
            int max = (Integer) iterCond + 1;
            for (int i = 1; i != max; i++) {
                itemR.setValue(i);
                v = compiledBlock.getValue(ctx, thisValue, itemFactory);
                if (itemFactory.tiltFlag())
                    return v;
            }
            break;
        case ITERABLE:
            for (Object o : (Iterable) iterCond) {
                itemR.setValue(o);
                v = compiledBlock.getValue(ctx, thisValue, itemFactory);
                if (itemFactory.tiltFlag())
                    return v;
            }
            break;
    }
    return null;
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ItemResolverFactory(org.mvel2.integration.impl.ItemResolverFactory)

Example 42 with VariableResolverFactory

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

the class ForNode method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    VariableResolverFactory ctxFactory = indexAlloc ? factory : new MapVariableResolverFactory(new HashMap<String, Object>(1), factory);
    Object v;
    for (initializer.getValue(ctx, thisValue, ctxFactory); (Boolean) condition.getValue(ctx, thisValue, ctxFactory); after.getValue(ctx, thisValue, ctxFactory)) {
        v = compiledBlock.getValue(ctx, thisValue, ctxFactory);
        if (ctxFactory.tiltFlag())
            return v;
    }
    return null;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 43 with VariableResolverFactory

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

the class Function method call.

public Object call(Object ctx, Object thisValue, VariableResolverFactory factory, Object[] parms) {
    if (parms != null && parms.length != 0) {
        // detect tail recursion
        if (factory instanceof FunctionVariableResolverFactory && ((FunctionVariableResolverFactory) factory).getIndexedVariableResolvers().length == parms.length) {
            FunctionVariableResolverFactory fvrf = (FunctionVariableResolverFactory) factory;
            if (fvrf.getFunction().equals(this)) {
                VariableResolver[] swapVR = fvrf.getIndexedVariableResolvers();
                fvrf.updateParameters(parms);
                try {
                    return compiledBlock.getValue(ctx, thisValue, fvrf);
                } finally {
                    fvrf.setIndexedVariableResolvers(swapVR);
                }
            }
        }
        return compiledBlock.getValue(thisValue, new FunctionVariableResolverFactory(this, factory, parameters, parms));
    } else if (cMode) {
        return compiledBlock.getValue(thisValue, new DefaultLocalVariableResolverFactory(factory, parameters).setNoTilt(true));
    } else {
        return compiledBlock.getValue(thisValue, new DefaultLocalVariableResolverFactory(factory, parameters).setNoTilt(true));
    }
}
Also used : FunctionVariableResolverFactory(org.mvel2.integration.impl.FunctionVariableResolverFactory) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolver(org.mvel2.integration.VariableResolver)

Example 44 with VariableResolverFactory

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

the class IndexedOperativeAssign method getReducedValue.

public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    VariableResolver resolver = factory.getIndexedVariableResolver(register);
    resolver.setValue(ctx = MathProcessor.doOperations(resolver.getValue(), operation, eval(expr, start, offset, ctx, factory)));
    return ctx;
}
Also used : VariableResolver(org.mvel2.integration.VariableResolver)

Example 45 with VariableResolverFactory

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

the class Strsim method getReducedValue.

public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    try {
        String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory));
        if (i == null)
            throw new ClassCastException();
        String x = (String) stmt.getReducedValue(ctx, thisValue, factory);
        if (x == null)
            throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), getStart());
        return similarity(i, x);
    } catch (ClassCastException e) {
        throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart());
    }
}
Also used : CompileException(org.mvel2.CompileException)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)16 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)15 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)15 VariableResolver (org.mvel2.integration.VariableResolver)14 HashMap (java.util.HashMap)10 CompileException (org.mvel2.CompileException)7 ParserContext (org.mvel2.ParserContext)7 AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)7 List (java.util.List)6 Map (java.util.Map)6 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)6 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 ASTNode (org.mvel2.ast.ASTNode)5 CompiledExpression (org.mvel2.compiler.CompiledExpression)5 Foo (org.mvel2.tests.core.res.Foo)5 IOException (java.io.IOException)4 Debugger (org.mvel2.debug.Debugger)4 Frame (org.mvel2.debug.Frame)4 Interceptor (org.mvel2.integration.Interceptor)4