Search in sources :

Example 36 with VariableResolverFactory

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

the class DynamicSetAccessor method optimize.

private Object optimize(Object ctx, Object elCtx, VariableResolverFactory variableResolverFactory, Object value) {
    if (DynamicOptimizer.isOverloaded()) {
        DynamicOptimizer.enforceTenureLimit();
    }
    AccessorOptimizer ao = OptimizerFactory.getAccessorCompiler("ASM");
    _accessor = ao.optimizeSetAccessor(context, property, start, offset, ctx, elCtx, variableResolverFactory, false, value, value != null ? value.getClass() : Object.class);
    assert _accessor != null;
    return value;
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Example 37 with VariableResolverFactory

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

the class ASTNode method optimize.

private Object optimize(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if ((fields & DEOP) != 0) {
        fields ^= DEOP;
    }
    AccessorOptimizer optimizer;
    Object retVal = null;
    if ((fields & NOJIT) != 0 || factory != null && factory.isResolveable(nameCache)) {
        optimizer = getAccessorCompiler(SAFE_REFLECTIVE);
    } else {
        optimizer = getDefaultAccessorCompiler();
    }
    ParserContext pCtx;
    if ((fields & PCTX_STORED) != 0) {
        pCtx = (ParserContext) literal;
    } else {
        pCtx = new ParserContext(new ParserConfiguration(getInjectedImports(factory), null));
    }
    try {
        pCtx.optimizationNotify();
        setAccessor(optimizer.optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, egressType));
    } catch (OptimizationNotSupported ne) {
        setAccessor((optimizer = getAccessorCompiler(SAFE_REFLECTIVE)).optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, null));
    }
    if (accessor == null) {
        return get(expr, start, offset, ctx, factory, thisValue);
    }
    if (retVal == null) {
        retVal = optimizer.getResultOptPass();
    }
    if (egressType == null) {
        egressType = optimizer.getEgressType();
    }
    return retVal;
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer) ParserContext(org.mvel2.ParserContext) OptimizationNotSupported(org.mvel2.optimizers.OptimizationNotSupported) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 38 with VariableResolverFactory

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

the class Fold method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
    ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
    List list;
    if (constraintEx != null) {
        Collection col = ((Collection) dataEx.getValue(ctx, thisValue, factory));
        list = new ArrayList(col.size());
        for (Object o : col) {
            itemR.value = o;
            if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
                list.add(subEx.getValue(o, thisValue, itemFactory));
            }
        }
    } else {
        Collection col = ((Collection) dataEx.getValue(ctx, thisValue, factory));
        list = new ArrayList(col.size());
        for (Object o : col) {
            list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
        }
    }
    return list;
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ArrayList(java.util.ArrayList) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) ItemResolverFactory(org.mvel2.integration.impl.ItemResolverFactory)

Example 39 with VariableResolverFactory

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

the class Fold method getReducedValue.

public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
    ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
    List list;
    if (constraintEx != null) {
        Object x = dataEx.getValue(ctx, thisValue, factory);
        if (!(x instanceof Collection))
            throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
        list = new ArrayList(((Collection) x).size());
        for (Object o : (Collection) x) {
            itemR.value = o;
            if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
                list.add(subEx.getValue(o, thisValue, itemFactory));
            }
        }
    } else {
        Object x = dataEx.getValue(ctx, thisValue, factory);
        if (!(x instanceof Collection))
            throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
        list = new ArrayList(((Collection) x).size());
        for (Object o : (Collection) x) {
            list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
        }
    }
    return list;
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CompileException(org.mvel2.CompileException) List(java.util.List) ArrayList(java.util.ArrayList) ItemResolverFactory(org.mvel2.integration.impl.ItemResolverFactory)

Example 40 with VariableResolverFactory

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

the class ForEachNode method getReducedValue.

public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item);
    ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
    Object iterCond = MVEL.eval(expr, start, offset, thisValue, factory);
    if (itemType != null && itemType.isArray())
        enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
    this.compiledBlock = (ExecutableStatement) subCompileExpression(expr, blockStart, blockOffset);
    Object v;
    if (iterCond instanceof Iterable) {
        for (Object o : (Iterable) iterCond) {
            itemR.setValue(o);
            v = compiledBlock.getValue(ctx, thisValue, itemFactory);
            if (itemFactory.tiltFlag())
                return v;
        }
    } else if (iterCond != null && iterCond.getClass().isArray()) {
        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;
        }
    } else if (iterCond instanceof CharSequence) {
        for (Object o : iterCond.toString().toCharArray()) {
            itemR.setValue(o);
            v = compiledBlock.getValue(ctx, thisValue, itemFactory);
            if (itemFactory.tiltFlag())
                return v;
        }
    } else if (iterCond instanceof 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;
        }
    } else {
        throw new CompileException("non-iterable type: " + (iterCond != null ? iterCond.getClass().getName() : "null"), expr, start);
    }
    return null;
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) CompileException(org.mvel2.CompileException) ItemResolverFactory(org.mvel2.integration.impl.ItemResolverFactory)

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