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 2017/07/14 13:06:05 UTC

svn commit: r1801956 - /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java

Author: henrib
Date: Fri Jul 14 13:06:05 2017
New Revision: 1801956

URL: http://svn.apache.org/viewvc?rev=1801956&view=rev
Log:
JEXL-224: added logic to allow detecting an overloaded call(...) method in JexlArithmetic usable to perform a function call

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java?rev=1801956&r1=1801955&r2=1801956&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java Fri Jul 14 13:06:05 2017
@@ -1557,6 +1557,8 @@ public class Interpreter extends Interpr
                         }
                     }
                 }
+                final Object[] nargv;
+                final String mname;
                 // this may happen without the above when we are chaining call like x(a)(b)
                 if (functor != null) {
                     // lambda, script or jexl method will do
@@ -1567,41 +1569,42 @@ public class Interpreter extends Interpr
                         return ((JexlMethod) functor).invoke(target, argv);
                     }
                     // a generic callable
-                    vm = uberspect.getMethod(functor, "call", argv);
+                    mname = "call";
+                    vm = uberspect.getMethod(functor, mname, argv);
                     if (vm != null) {
                         return vm.invoke(functor, argv);
                     }
-                    // try JexlArithmetic or JexlContext function
+                    // prepend functor to arg to try JexlArithmetic or JexlContext function
+                    nargv = functionArguments(functor, narrow, argv);
                 } else {
+                    mname = methodName;
                     // no need to narrow since this has been performed in previous loop
-                    Object[] nargv = functionArguments(caller, narrow, argv);
-                    vm = uberspect.getMethod(context, methodName, nargv);
-                    if (vm != null) {
-                        argv = nargv;
-                        target = context;
-                        if (cacheable && vm.isCacheable()) {
-                            funcall = new ContextFuncall(vm, narrow);
-                        }
-                        break;
-                    }
-                    vm = uberspect.getMethod(arithmetic, methodName, nargv);
-                    if (vm != null) {
-                        argv = nargv;
-                        target = arithmetic;
-                        if (cacheable && vm.isCacheable()) {
-                            funcall = new ArithmeticFuncall(vm, narrow);
-                        }
-                        break;
+                    nargv = functionArguments(caller, narrow, argv);
+                }
+                vm = uberspect.getMethod(context, mname, nargv);
+                if (vm != null) {
+                    argv = nargv;
+                    target = context;
+                    if (cacheable && vm.isCacheable()) {
+                        funcall = new ContextFuncall(vm, narrow);
                     }
-                    // if we did not find an exact method by name and we haven't tried yet,
-                    // attempt to narrow the parameters and if this succeeds, try again in next loop
-                    if (arithmetic.narrowArguments(argv)) {
-                        narrow = true;
-                        continue;
+                    break;
+                }
+                vm = uberspect.getMethod(arithmetic, mname, nargv);
+                if (vm != null) {
+                    argv = nargv;
+                    target = arithmetic;
+                    if (cacheable && vm.isCacheable()) {
+                        funcall = new ArithmeticFuncall(vm, narrow);
                     }
+                    break;
+                }
+                // if we did not find an exact method by name and we haven't tried yet,
+                // attempt to narrow the parameters and if this succeeds, try again in next loop
+                if (!arithmetic.narrowArguments(argv)) {
+                    break;
                 }
-                // we are done trying
-                break;
+                narrow = true;
             }
             // we have either evaluated and returned or might have found a method
             if (vm != null) {