tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1503060 - in /tomcat/trunk: java/org/apache/el/parser/AstLambdaExpression.java java/org/apache/el/parser/AstLambdaExpressionOrInvocation.java test/org/apache/el/parser/TestAstLambdaExpression.java
Date Sun, 14 Jul 2013 21:20:43 GMT
Author: markt
Date: Sun Jul 14 21:20:43 2013
New Revision: 1503060

URL: http://svn.apache.org/r1503060
Log:
More lambda expression implementation. Handle the case of an expression without any formal
parameters.

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

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=1503060&r1=1503059&r2=1503060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstLambdaExpression.java Sun Jul 14 21:20:43 2013
@@ -40,7 +40,10 @@ public class AstLambdaExpression extends
         AstLambdaParameters formalParameters =
                 (AstLambdaParameters) children[0];
 
-        int paramCount = formalParameters.children.length;
+        int paramCount = 0;
+        if (formalParameters.children != null) {
+            paramCount = formalParameters.children.length;
+        }
         int argCount = 0;
         if (paramValues != null) {
             argCount = paramValues.length;
@@ -52,7 +55,7 @@ public class AstLambdaExpression extends
 
         // Build the argument map
         Map<String,Object> lambdaArgumnents = new HashMap<>();
-        for (int i = 0; i < formalParameters.children.length; i++) {
+        for (int i = 0; i < paramCount; i++) {
             lambdaArgumnents.put(formalParameters.children[i].getImage(),
                     paramValues[i]);
         }

Modified: tomcat/trunk/java/org/apache/el/parser/AstLambdaExpressionOrInvocation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstLambdaExpressionOrInvocation.java?rev=1503060&r1=1503059&r2=1503060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstLambdaExpressionOrInvocation.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstLambdaExpressionOrInvocation.java Sun Jul 14
21:20:43 2013
@@ -31,19 +31,17 @@ public class AstLambdaExpressionOrInvoca
     @Override
     public Object getValue(EvaluationContext ctx) throws ELException {
 
-        if (children.length == 2) {
-            AstLambdaExpression lambdaExpression =
-                    (AstLambdaExpression) children[0];
-
-
-            Object[] args =
-                    ((AstMethodParameters) children[1]).getParameters(ctx);
+        AstLambdaExpression lambdaExpression =
+                (AstLambdaExpression) children[0];
 
-            return lambdaExpression.invoke(ctx, null, args);
+        Object[] args;
+        if (children.length == 2) {
+            args = ((AstMethodParameters) children[1]).getParameters(ctx);
+        } else {
+            // No parameters - just the expression
+            args = null;
         }
-
-        // TODO Auto-generated method stub
-        return super.getValue(ctx);
+        return lambdaExpression.invoke(ctx, null, args);
     }
 }
 /* JavaCC - OriginalChecksum=6b3dd15b31540457a41bd55974037ed9 (do not edit this line) */

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=1503060&r1=1503059&r2=1503060&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java (original)
+++ tomcat/trunk/test/org/apache/el/parser/TestAstLambdaExpression.java Sun Jul 14 21:20:43
2013
@@ -29,4 +29,20 @@ public class TestAstLambdaExpression {
         Object result = processor.getValue("(x->x+1)(1)", Integer.class);
         Assert.assertEquals(Integer.valueOf(2), result);
     }
+
+
+    @Test
+    public void testSpec02() {
+        ELProcessor processor = new ELProcessor();
+        Object result = processor.getValue("((x,y)->x+y)(1,2)", Integer.class);
+        Assert.assertEquals(Integer.valueOf(3), result);
+    }
+
+
+    @Test
+    public void testSpec03() {
+        ELProcessor processor = new ELProcessor();
+        Object result = processor.getValue("(()->64)", Integer.class);
+        Assert.assertEquals(Integer.valueOf(64), result);
+    }
 }



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


Mime
View raw message