Author: markt
Date: Thu Jul 18 13:57:17 2013
New Revision: 1504475

URL: http://svn.apache.org/r1504475
Log:
Fix handling expressions of the form:
v = (x->y->x-y); v(2)(1)

There is still some further clean-up that can be done.

Modified:
    tomcat/trunk/java/org/apache/el/parser/AstFunction.java
    tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java
    tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java

Modified: tomcat/trunk/java/org/apache/el/parser/AstFunction.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstFunction.java?rev=1504475&r1=1504474&r2=1504475&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstFunction.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstFunction.java Thu Jul 18 13:57:17 
2013
@@ -95,15 +95,19 @@ public final class AstFunction extends S
             Object obj =
                     ctx.getELResolver().getValue(ctx, null, this.localName);
             if (obj instanceof LambdaExpression) {
-                LambdaExpression le = (LambdaExpression) obj;
                 // Build arguments
-                // TODO handle multiple sets of arguments
-                int numArgs = this.jjtGetChild(0).jjtGetNumChildren();
-                Object[] args = new Object[numArgs];
-                for (int i = 0; i < numArgs; i++) {
-                    args[i] = jjtGetChild(0).jjtGetChild(i).getValue(ctx);
+                int i = 0;
+                while (obj instanceof LambdaExpression && i < 
this.jjtGetNumChildren()) {
+                    Node parameters = jjtGetChild(i);
+                    int numArgs = parameters.jjtGetNumChildren();
+                    Object[] args = new Object[numArgs];
+                    for (int j = 0; j < numArgs; j++) {
+                        args[j] = parameters.jjtGetChild(j).getValue(ctx);
+                    }
+                    obj = ((LambdaExpression) obj).invoke(args);
+                    i++;
                 }
-                return le.invoke(ctx, args);
+                return obj;
             }
         }
 

Modified: tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java?rev=1504475&r1=1504474&r2=1504475&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java Thu Jul 18 
13:57:17 2013
@@ -76,7 +76,7 @@ public class AstLambdaExpression extends
         le.setELContext(ctx);
 
         if (jjtGetNumChildren() == 2) {
-            if (formalParameters.isEmpty()) {
+            if (formalParameters.isEmpty() && !(parent instanceof 
AstLambdaExpression)) {
                 // No formal parameters or method parameters so invoke the
                 // expression. If this is a nested expression inform the outer
                 // expression that an invocation has occurred so the correct 
set
@@ -130,7 +130,7 @@ public class AstLambdaExpression extends
 
     public void incMethodParameterIndex() {
         Node parent = jjtGetParent();
-        if (parent instanceof AstLambdaExpression) {
+        if (parent instanceof LambdaExpression) {
             // Method parameter index is maintained by outermost lambda
             // expressions as that is where the parameters are
             ((AstLambdaExpression) parent).incMethodParameterIndex();

Modified: tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java?rev=1504475&r1=1504474&r2=1504475&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java 
(original)
+++ tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java Thu Jul 
18 13:57:17 2013
@@ -144,4 +144,14 @@ public class TestAstLambdaExpression {
                         Integer.class);
         Assert.assertEquals(Integer.valueOf(1), result);
     }
+
+
+    @Test
+    public void testLambdaAsFunction() {
+        ELProcessor processor = new ELProcessor();
+        Object result =
+                processor.getValue("v = (x->y->x-y); v(2)(1)",
+                        Integer.class);
+        Assert.assertEquals(Integer.valueOf(1), result);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to