You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2012/07/09 21:06:17 UTC
svn commit: r1359338 - in /commons/proper/jexl/branches/2.0/src:
main/java/org/apache/commons/jexl2/Interpreter.java
test/java/org/apache/commons/jexl2/IssuesTest.java
Author: henrib
Date: Mon Jul 9 19:06:17 2012
New Revision: 1359338
URL: http://svn.apache.org/viewvc?rev=1359338&view=rev
Log:
VDB:
Refactored FormulaGrid to minimize impact of removing deprecated grid & al classes (ooops)
Modified:
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/Interpreter.java
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=1359338&r1=1359337&r2=1359338&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/Interpreter.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/Interpreter.java Mon Jul 9 19:06:17 2012
@@ -1021,52 +1021,51 @@ public class Interpreter implements Pars
}
JexlException xjexl = null;
+ JexlMethod vm = null;
try {
// attempt to reuse last executor cached in volatile JexlNode.value
if (cache) {
Object cached = node.jjtGetValue();
if (cached instanceof JexlMethod) {
- JexlMethod me = (JexlMethod) cached;
- Object eval = me.tryInvoke(methodName, bean, argv);
- if (!me.tryFailed(eval)) {
+ vm = (JexlMethod) cached;
+ Object eval = vm.tryInvoke(methodName, bean, argv);
+ if (!vm.tryFailed(eval)) {
return eval;
}
}
}
boolean cacheable = cache;
- JexlMethod vm = uberspect.getMethod(bean, methodName, argv, node);
- // DG: If we can't find an exact match, narrow the parameters and try again
+ vm = uberspect.getMethod(bean, methodName, argv, node);
if (vm == null) {
- if (arithmetic.narrowArguments(argv)) {
- vm = uberspect.getMethod(bean, methodName, argv, node);
- }
- if (vm == null) {
- Object functor = null;
- // could not find a method, try as a var
- if (bean == context) {
- int register = methodNode.getRegister();
- if (register >= 0) {
- functor = registers[register];
- } else {
- functor = context.get(methodName);
- }
+ Object functor = null;
+ // could not find a method, try as a var
+ if (bean == context) {
+ int register = methodNode.getRegister();
+ if (register >= 0) {
+ functor = registers[register];
} else {
- JexlPropertyGet gfunctor = uberspect.getPropertyGet(bean, methodName, node);
- if (gfunctor != null) {
- functor = gfunctor.tryInvoke(bean, methodName);
- }
+ functor = context.get(methodName);
}
- // script of jexl method will do
- if (functor instanceof Script) {
- return ((Script) functor).execute(context, argv.length > 0 ? argv : null);
- } else if (functor instanceof JexlMethod) {
- vm = (JexlMethod) functor;
- cacheable = false;
- } else {
- xjexl = new JexlException.Method(node, methodName, null);
+ } else {
+ JexlPropertyGet gfunctor = uberspect.getPropertyGet(bean, methodName, node);
+ if (gfunctor != null) {
+ functor = gfunctor.tryInvoke(bean, methodName);
}
}
+ // script or JexlMethod will do
+ if (functor instanceof Script) {
+ return ((Script) functor).execute(context, argv.length > 0 ? argv : null);
+ } else if (functor instanceof JexlMethod) {
+ vm = (JexlMethod) functor;
+ cacheable = false;
+ // DG: If we can't find an exact match, narrow the parameters and try again
+ } else if (arithmetic.narrowArguments(argv)) {
+ vm = uberspect.getMethod(bean, methodName, argv, node);
+ } else {
+ xjexl = new JexlException.Method(node, methodName, null);
+ }
}
+
if (xjexl == null) {
// vm cannot be null if xjexl is null
Object eval = vm.invoke(bean, argv);
Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1359338&r1=1359337&r2=1359338&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java Mon Jul 9 19:06:17 2012
@@ -1111,4 +1111,23 @@ public class IssuesTest extends JexlTest
result = script.execute(null, foo, 2, 1);
assertEquals(42, result);
}
+
+ @Test
+ public void test136() throws Exception {
+ JexlEngine jexl = new JexlEngine();
+ JexlContext jc = new MapContext();
+ Script script;
+ Expression expr;
+ Object result;
+
+ script = jexl.createScript("var x = $TAB[idx]; return x;", "idx");
+ jc.set("fn01", script);
+
+ script = jexl.createScript("$TAB = { 1:11, 2:22, 3:33}; IDX=2;");
+ script.execute(jc);
+
+ expr = jexl.createExpression("fn01(IDX)");
+ result = expr.evaluate(jc);
+ assertEquals("EXPR01 result", 22, result);
+ }
}