Skip to main content

[el-spec commits] [el-spec~source-code:104] Support linq generation operators

  • From: kchung@...
  • To: commits@...
  • Subject: [el-spec commits] [el-spec~source-code:104] Support linq generation operators
  • Date: Fri, 25 May 2012 00:54:33 +0000

Project:    el-spec
Repository: source-code
Revision:   104
Author:     kchung
Date:       2012-05-25 00:51:48 UTC
Link:       

Log Message:
------------
Support linq generation operators



Revisions:
----------
104


Modified Paths:
---------------
trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java
trunk/impl/src/main/java/com/sun/el/parser/AstMethodArguments.java
trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java
trunk/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java
trunk/impl/src/main/java/com/sun/el/Messages.properties
trunk/impl/src/test/java/org/glassfish/el/test/LambdaTest.java


Diffs:
------
Index: trunk/impl/src/test/java/org/glassfish/el/test/LambdaTest.java
===================================================================
--- trunk/impl/src/test/java/org/glassfish/el/test/LambdaTest.java      
(revision 103)
+++ trunk/impl/src/test/java/org/glassfish/el/test/LambdaTest.java      
(revision 104)
@@ -30,6 +30,7 @@
     public void testImmediate() {
         ELProcessor elp = new ELProcessor();
         testExpr(elp, "immediate", "(x->x+1)(10)", 11L);
+        testExpr(elp, "immediate0", "(()->1001)()", 1001L);
         testExpr(elp, "immediate 2", "(((x,y)->x+y)(3,4))", 7L);
         testExpr(elp, "immediate 3", "(x->(y=x)+1)(10) + y", 21L);
     }
Index: trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java
===================================================================
--- trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java        
(revision 103)
+++ trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java        
(revision 104)
@@ -354,7 +354,17 @@
     public void testForEach() {
         testIterable("forEach",
             "lst = []; products.forEach(p->lst.add(p.name)); lst", exp2);
-        elp.eval("products.forEach((p,idx)->System.out.println(idx + \": \" 
+ p.name))");
+        elp.eval("products.forEach((p,idx)->System.out.println("
+                + "idx + \": \" + p.name + \", \" + p.unitPrice))");
     }
+
+    @Test
+    public void testGen() {
+        testIterable("linq:rang", "linq:range(10, 5)()",
+                new String[]{"10", "11", "12", "13", "14"});
+        testIterable("linq:repeat", "linq:repeat(\"xyz\", 3)",
+                new String[]{"xyz", "xyz", "xyz"});
+        testIterable("linq:_empty", "linq:_empty()", new String[]{});
+    }
 }
 
Index: trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java     
(revision 103)
+++ trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java     
(revision 104)
@@ -66,6 +66,7 @@
 import com.sun.el.parser.AstFunction;
 import com.sun.el.parser.AstIdentifier;
 import com.sun.el.parser.AstLiteralExpression;
+import com.sun.el.parser.AstMethodArguments;
 import com.sun.el.parser.AstValue;
 import com.sun.el.parser.ELParser;
 import com.sun.el.parser.Node;
@@ -271,10 +272,11 @@
                         "error.fnMapper.method", funcNode.getOutputName()));
             }
             int pcnt = m.getParameterTypes().length;
-            if (node.jjtGetNumChildren() != pcnt) {
+            int acnt = 
((AstMethodArguments)node.jjtGetChild(0)).getParameterCount();
+            if (acnt != pcnt) {
                 throw new ELException(MessageFactory.get(
                         "error.fnMapper.paramcount", 
funcNode.getOutputName(),
-                        "" + pcnt, "" + node.jjtGetNumChildren()));
+                        "" + pcnt, "" + acnt));
             }
         } else if (node instanceof AstIdentifier && this.varMapper != null) {
             String variable = ((AstIdentifier) node).getImage();
Index: trunk/impl/src/main/java/com/sun/el/Messages.properties
===================================================================
--- trunk/impl/src/main/java/com/sun/el/Messages.properties     (revision 103)
+++ trunk/impl/src/main/java/com/sun/el/Messages.properties     (revision 104)
@@ -73,7 +73,7 @@
 # ValidatingVisitor
 error.fnMapper.null=Expression uses functions, but no FunctionMapper was 
provided
 error.fnMapper.method=Function ''{0}'' not found
-error.fnMapper.paramcount=Function ''{0}'' specifies {1} params, but {2} 
were declared
+error.fnMapper.paramcount=Function ''{0}'' specifies {1} params, but {2} 
were supplied
 
 # **ExpressionImpl
 error.context.null=ELContext was null
Index: trunk/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java      
(revision 103)
+++ trunk/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java      
(revision 104)
@@ -40,6 +40,10 @@
 
 package com.sun.el;
 
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Method;
+
 import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.ExpressionFactory;
@@ -51,6 +55,7 @@
 import com.sun.el.lang.ELSupport;
 import com.sun.el.util.MessageFactory;
 import com.sun.el.query.QueryOperatorELResolver;
+import com.sun.el.query.Generation;
 
 /**
  * @see javax.el.ExpressionFactory
@@ -109,7 +114,25 @@
         return new ValueExpressionLiteral(instance, expectedType);
     }
 
+    @Override
     public ELResolver getQueryOperatorELResolver() {
         return new QueryOperatorELResolver();
     }
+
+    @Override
+    public Map<String, Method> getInitFunctionMap() {
+        Map<String, Method> funcs = new HashMap<String, Method>();
+        Class<Generation> genClass = Generation.class;
+        try {
+            funcs.put("linq:range", genClass.getMethod("range",
+                    new Class<?>[] {Integer.TYPE, Integer.TYPE}));
+            funcs.put("linq:repeat", genClass.getMethod("repeat",
+                    new Class<?>[] {Object.class, Integer.TYPE}));
+            funcs.put("linq:_empty", genClass.getMethod("empty",
+                    new Class<?>[] {}));
+        } catch (NoSuchMethodException ex) {
+            // Should not happen
+        }
+        return funcs;
+    }
 }
Index: trunk/impl/src/main/java/com/sun/el/parser/AstMethodArguments.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/parser/AstMethodArguments.java  
(revision 103)
+++ trunk/impl/src/main/java/com/sun/el/parser/AstMethodArguments.java  
(revision 104)
@@ -56,7 +56,7 @@
         return null;
     }
 
-    Object[] getParameters(EvaluationContext ctx) throws ELException {
+    public Object[] getParameters(EvaluationContext ctx) throws ELException {
 
         if (this.children == null)
             return new Object[] {};
@@ -68,6 +68,10 @@
         return obj;
     }
 
+    public int getParameterCount() {
+        return this.children == null? 0: this.children.length;
+    }
+
     @Override
     public boolean isParametersProvided() {
         return true;





[el-spec commits] [el-spec~source-code:104] Support linq generation operators

kchung 05/25/2012
 
 
Close
loading
Please Confirm
Close