public void eval(Object ctx, VariableResolverFactory factory) { if (setExpression == null) { this.statement.getValue(ctx, factory); } else { MVEL.executeSetExpression(setExpression, ctx, factory, this.statement.getValue(ctx, factory)); } } }
public void eval(Object ctx, VariableResolverFactory factory) { if (setExpression == null) { this.statement.getValue(ctx, factory); } else { MVEL.executeSetExpression(setExpression, ctx, factory, this.statement.getValue(ctx, factory)); } } }
public void eval(Object ctx, VariableResolverFactory factory) { if (setExpression == null) { this.statement.getValue(ctx, factory); } else { MVEL.executeSetExpression(setExpression, ctx, factory, this.statement.getValue(ctx, factory)); } } }
public void testSetExpressions1() { Map<String, Object> myMap = new HashMap<String, Object>(); final Serializable fooExpr = compileSetExpression("foo"); executeSetExpression(fooExpr, myMap, "blah"); assertEquals("blah", myMap.get("foo")); executeSetExpression(fooExpr, myMap, "baz"); assertEquals("baz", myMap.get("foo")); }
public void testListPropertyHandler2() { MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; Serializable s = MVEL.compileSetExpression("list[0]"); Base b; MVEL.executeSetExpression(s, new Base(), "hey you"); MVEL.executeSetExpression(s, b = new Base(), "hey you"); assertEquals("set", b.list.get(0)); }
public void testListPropertyHandler3() { MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; OptimizerFactory.setDefaultOptimizer("ASM"); Serializable s = MVEL.compileSetExpression("list[0]"); Base b; MVEL.executeSetExpression(s, new Base(), "hey you"); MVEL.executeSetExpression(s, b = new Base(), "hey you"); assertEquals("set", b.list.get(0)); }
public void testBindListToArray() { Map<String, Object> vars = createTestMap(); ArrayList<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); OptimizerFactory.setDefaultOptimizer("reflective"); Serializable s = MVEL.compileSetExpression("foo.charArray"); MVEL.executeSetExpression(s, vars, list); assertEquals(((Foo) vars.get("foo")).getCharArray().length, 3); }
public Object processWith(Object ctx, Object thisValue, VariableResolverFactory factory) { for (WithNode.ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), ctx, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(ctx, thisValue, factory); } } return ctx; }
public void testBindingNullToPrimitiveTypes4() { Map<String, Object> vars = createTestMap(); ((Foo) vars.get("foo")).charTestFld = 'a'; OptimizerFactory.setDefaultOptimizer("reflective"); Serializable s = MVEL.compileSetExpression("foo.charTestFld"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).charTestFld, 0); OptimizerFactory.setDefaultOptimizer("ASM"); s = MVEL.compileSetExpression("foo.charTestFld"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).charTestFld, 0); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).charTestFld, 0); }
public Object processWith(Object ctx, Object thisValue, VariableResolverFactory factory) { for (WithNode.ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), ctx, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(ctx, thisValue, factory); } } return ctx; }
public Object processWith(Object ctx, Object thisValue, VariableResolverFactory factory) { for (WithNode.ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), ctx, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(ctx, thisValue, factory); } } return ctx; }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { if (thisValue == null) throw new CompileException("with-block against null pointer (this)", expr, start); for (ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), thisValue, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(thisValue, thisValue, factory); } } return thisValue; }
public void testBindingNullToPrimitiveTypes3() { Map<String, Object> vars = createTestMap(); ((Foo) vars.get("foo")).setCharTest('a'); OptimizerFactory.setDefaultOptimizer("reflective"); Serializable s = MVEL.compileSetExpression("foo.charTest"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCharTest(), 0); OptimizerFactory.setDefaultOptimizer("ASM"); s = MVEL.compileSetExpression("foo.charTest"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCharTest(), 0); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCharTest(), 0); }
public void testBindingNullToPrimitiveTypes2() { Map<String, Object> vars = createTestMap(); ((Foo) vars.get("foo")).setCountTest(10); OptimizerFactory.setDefaultOptimizer("reflective"); Serializable s = MVEL.compileSetExpression("foo.boolTest"); MVEL.executeSetExpression(s, vars, null); assertFalse(((Foo) vars.get("foo")).isBoolTest()); OptimizerFactory.setDefaultOptimizer("ASM"); s = MVEL.compileSetExpression("foo.boolTest"); MVEL.executeSetExpression(s, vars, null); assertFalse(((Foo) vars.get("foo")).isBoolTest()); MVEL.executeSetExpression(s, vars, null); assertFalse(((Foo) vars.get("foo")).isBoolTest()); }
public void testSetExpressions2() { Foo foo = new Foo(); Collection col = new ArrayList(); final Serializable fooExpr = compileSetExpression("collectionTest"); executeSetExpression(fooExpr, foo, col); assertEquals(col, foo.getCollectionTest()); }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { if (thisValue == null) throw new CompileException("with-block against null pointer (this)", expr, start); for (ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), thisValue, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(thisValue, thisValue, factory); } } return thisValue; }
public void testBindingNullToPrimitiveTypes() { Map<String, Object> vars = createTestMap(); ((Foo) vars.get("foo")).setCountTest(10); OptimizerFactory.setDefaultOptimizer("reflective"); Serializable s = MVEL.compileSetExpression("foo.countTest"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCountTest(), 0); OptimizerFactory.setDefaultOptimizer("ASM"); s = MVEL.compileSetExpression("foo.countTest"); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCountTest(), 0); MVEL.executeSetExpression(s, vars, null); assertEquals(((Foo) vars.get("foo")).getCountTest(), 0); }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { if (thisValue == null) throw new CompileException("with-block against null pointer (this)"); for (ParmValuePair pvp : withExpressions) { if (pvp.getSetExpression() != null) { executeSetExpression(pvp.getSetExpression(), thisValue, factory, pvp.getStatement().getValue(ctx, thisValue, factory)); } else { pvp.getStatement().getValue(thisValue, thisValue, factory); } } return thisValue; }
public void testSetterViaMapNotation() { TestClass tc = new TestClass(); tc.getExtra().put("test", "value"); ParserContext ctx = new ParserContext(); ctx.withInput("this", TestClass.class); ctx.setStrongTyping(true); String expression = "extra[\"test\"]"; Serializable compiled = MVEL.compileSetExpression(expression, tc.getClass(), ctx); MVEL.executeSetExpression(compiled, tc, "value3"); assertEquals("value3", tc.getExtra().get("test")); }
public void testSetterViaDotNotation() { TestClass tc = new TestClass(); tc.getExtra().put("test", "value"); ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); String expression = "extra.test"; Serializable compiled = MVEL.compileSetExpression(expression, ctx); MVEL.executeSetExpression(compiled, tc, "value2"); assertEquals("value2", tc.getExtra().get("test")); }