Skip to main content

[el-spec commits] [el-spec~source-code:58] Revert adding a targetVariableMapper since setting an EL variable for

  • From: kchung@...
  • To: commits@...
  • Subject: [el-spec commits] [el-spec~source-code:58] Revert adding a targetVariableMapper since setting an EL variable for
  • Date: Thu, 22 Mar 2012 18:34:43 +0000

Project:    el-spec
Repository: source-code
Revision:   58
Author:     kchung
Date:       2012-03-22 18:34:40 UTC
Link:       

Log Message:
------------
Revert adding a targetVariableMapper since setting an EL variable for 
assignment operator does not work anyway.




Revisions:
----------
58


Modified Paths:
---------------
trunk/impl/src/main/java/com/sun/el/parser/AstLambdaExpression.java
trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java
trunk/impl/src/main/java/com/sun/el/parser/AstAssign.java
trunk/impl/src/main/java/com/sun/el/ValueExpressionImpl.java
trunk/impl/src/main/java/com/sun/el/query/QueryOperator.java
trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java
trunk/impl/src/main/java/com/sun/el/lang/VariableMapperFactory.java
trunk/impl/src/main/java/com/sun/el/MethodExpressionImpl.java
trunk/impl/src/main/java/com/sun/el/lang/EvaluationContext.java


Diffs:
------
Index: trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java
===================================================================
--- trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java        
(revision 57)
+++ trunk/impl/src/test/java/org/glassfish/el/test/LinqTest.java        
(revision 58)
@@ -341,5 +341,13 @@
             "['x', 'b', 'a', 'b', 'c'].except(['b', 'c', 'd'])",
             new String[] {"x", "a"});
     }
+
+    @Test
+    public void testForEach() {
+        elp.defineBean("lst", new java.util.ArrayList());
+        testIterable("forEach",
+            "products.forEach(p->lst.add(p.name)); lst", exp2);
+    }
+            
 }
 
Index: trunk/impl/src/main/java/com/sun/el/lang/VariableMapperFactory.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/lang/VariableMapperFactory.java 
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/lang/VariableMapperFactory.java 
(revision 58)
@@ -43,6 +43,9 @@
 import javax.el.ValueExpression;
 import javax.el.VariableMapper;
 
+/**
+ * Creates a VariableMapper for the variables used in the expression.
+ */
 public class VariableMapperFactory extends VariableMapper {
 
     private final VariableMapper target;
Index: trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java     
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/lang/ExpressionBuilder.java     
(revision 58)
@@ -140,7 +140,6 @@
                 new SoftConcurrentHashMap();
     private FunctionMapper fnMapper;
     private VariableMapper varMapper;
-    private VariableMapper targetVarMapper;
     private String expression;
 
     /**
@@ -158,7 +157,6 @@
         }
         if (ctxVar != null) {
             this.varMapper = new VariableMapperFactory(ctxVar);
-            this.targetVarMapper = ctxVar;
         }
     }
 
@@ -217,6 +215,13 @@
         return n;
     }
 
+    /**
+     * Scan the expression nodes and captures the functions and variables 
used
+     * in this expression.  This ensures that any changes to the functions or
+     * variables mappings during the expression will not affect the 
evaluation
+     * of this expression, as the functions and variables are bound and
+     * resolved at parse time, as specified in the spec.
+     */
     private void prepare(Node node) throws ELException {
         node.accept(this);
         if (this.fnMapper instanceof FunctionMapperFactory) {
@@ -274,7 +279,7 @@
             throws ELException {
         Node n = this.build();
         return new ValueExpressionImpl(this.expression, n, this.fnMapper,
-                this.varMapper, this.targetVarMapper, expectedType);
+                this.varMapper, expectedType);
     }
 
     public MethodExpression createMethodExpression(Class expectedReturnType,
@@ -282,7 +287,7 @@
         Node n = this.build();
         if (n instanceof AstValue || n instanceof AstIdentifier) {
             return new MethodExpressionImpl(expression, n,
-                    this.fnMapper, this.varMapper, this.targetVarMapper,
+                    this.fnMapper, this.varMapper,
                     expectedReturnType, expectedParamTypes);
         } else if (n instanceof AstLiteralExpression) {
             return new MethodExpressionLiteral(expression, 
expectedReturnType,
Index: trunk/impl/src/main/java/com/sun/el/lang/EvaluationContext.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/lang/EvaluationContext.java     
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/lang/EvaluationContext.java     
(revision 58)
@@ -50,6 +50,11 @@
 import javax.el.VariableMapper;
 import javax.el.TypeConverter;
 
+/**
+ * The context for EL expression evaluation.  This wrapper ELContext captures
+ * the function mapper and the variable mapper at the point when the 
epxression
+ * is parsed, and only for those functions and variable used in the 
expression.
+ */
 public final class EvaluationContext extends ELContext {
 
     private final ELContext elContext;
@@ -57,14 +62,12 @@
     private final FunctionMapper fnMapper;
 
     private final VariableMapper varMapper;
-    private final VariableMapper targetVarMapper;
 
     public EvaluationContext(ELContext elContext, FunctionMapper fnMapper,
-            VariableMapper varMapper, VariableMapper targetVarMapper) {
+            VariableMapper varMapper) {
         this.elContext = elContext;
         this.fnMapper = fnMapper;
         this.varMapper = varMapper;
-        this.targetVarMapper = targetVarMapper;
     }
 
     public ELContext getELContext() {
@@ -79,10 +82,6 @@
         return this.varMapper;
     }
 
-    public VariableMapper getTargetVariableMapper() {
-        return this.targetVarMapper;
-    }
-
     public Object getContext(Class key) {
         return this.elContext.getContext(key);
     }
Index: trunk/impl/src/main/java/com/sun/el/MethodExpressionImpl.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/MethodExpressionImpl.java       
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/MethodExpressionImpl.java       
(revision 58)
@@ -110,7 +110,6 @@
     private FunctionMapper fnMapper;
 
     private VariableMapper varMapper;
-    private VariableMapper targetVarMapper;
 
     private transient Node node;
 
@@ -132,14 +131,12 @@
      */
     public MethodExpressionImpl(String expr, Node node,
             FunctionMapper fnMapper, VariableMapper varMapper,
-            VariableMapper targetVarMapper,
             Class expectedType, Class[] paramTypes) {
         super();
         this.expr = expr;
         this.node = node;
         this.fnMapper = fnMapper;
         this.varMapper = varMapper;
-        this.targetVarMapper =  targetVarMapper;
         this.expectedType = expectedType;
         this.paramTypes = paramTypes;
     }
@@ -231,7 +228,7 @@
             ELException {
         Node n = this.getNode();
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, this.targetVarMapper);
+                this.varMapper);
         return n.getMethodInfo(ctx, this.paramTypes);
     }
 
@@ -301,7 +298,7 @@
             throws PropertyNotFoundException, MethodNotFoundException,
             ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, targetVarMapper);
+                this.varMapper);
         return this.getNode().invoke(ctx, this.paramTypes, params);
     }
 
@@ -321,7 +318,6 @@
                 .readObject()));
         this.fnMapper = (FunctionMapper) in.readObject();
         this.varMapper = (VariableMapper) in.readObject();
-        this.targetVarMapper = (VariableMapper) in.readObject();
     }
 
     /*
@@ -336,7 +332,6 @@
         out.writeObject(ReflectionUtil.toTypeNameArray(this.paramTypes));
         out.writeObject(this.fnMapper);
         out.writeObject(this.varMapper);
-        out.writeObject(this.targetVarMapper);
     }
 
     public boolean isLiteralText() {
Index: trunk/impl/src/main/java/com/sun/el/query/QueryOperator.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/query/QueryOperator.java        
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/query/QueryOperator.java        
(revision 58)
@@ -103,6 +103,7 @@
         operators.put("min", new Min());
         operators.put("max", new Max());
         operators.put("average", new Average());
+        operators.put("forEach", new ForEach());
         operators.put("aggregate", new Aggregate());
     }
 
Index: trunk/impl/src/main/java/com/sun/el/parser/AstLambdaExpression.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/parser/AstLambdaExpression.java 
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/parser/AstLambdaExpression.java 
(revision 58)
@@ -70,7 +70,6 @@
                                     this.children[0],
                                     ctx.getFunctionMapper(),
                                     ctx.getVariableMapper(),
-                                    ctx.getTargetVariableMapper(),
                                     null);
         LambdaExpression lambda = new LambdaExpression(parameters, expr);
         Object ret = lambda;
Index: trunk/impl/src/main/java/com/sun/el/parser/AstAssign.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/parser/AstAssign.java   (revision 57)
+++ trunk/impl/src/main/java/com/sun/el/parser/AstAssign.java   (revision 58)
@@ -63,20 +63,19 @@
     public Object getValue(EvaluationContext ctx)
             throws ELException {
         if (children[0] instanceof AstIdentifier) {
-            // if the target is an EL variable or if it cannot be resolvered
-            // by a ELResolver, set the variable to the fhs expression
             String name = ((AstIdentifier)children[0]).image;
-            VariableMapper varMapper = ctx.getTargetVariableMapper();
-            if (varMapper != null && varMapper.resolveVariable(name) != null 
||
-                        !canResolve(ctx, name)) {
-                // set the variable to the new expression
-                varMapper.setVariable(name, new ValueExpressionImpl(
-                    "assignment operator",
-                    children[1],
-                    ctx.getFunctionMapper(),
-                    ctx.getVariableMapper(),
-                    varMapper,
-                    null));
+            if (!canResolve(ctx, name)) {
+                // If the target name cannot be resolvered by a ELResolver, 
set
+                // the the lhs expression to an EL variable with the name.
+                VariableMapper varMapper = ctx.getVariableMapper();
+                if (varMapper != null) {
+                    varMapper.setVariable(name, new ValueExpressionImpl(
+                        "assignment operator",
+                        children[1],
+                        ctx.getFunctionMapper(),
+                        varMapper,
+                        null));
+                }
                 return children[1].getValue(ctx);
             }
         }
Index: trunk/impl/src/main/java/com/sun/el/ValueExpressionImpl.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/ValueExpressionImpl.java        
(revision 57)
+++ trunk/impl/src/main/java/com/sun/el/ValueExpressionImpl.java        
(revision 58)
@@ -122,7 +122,6 @@
     private FunctionMapper fnMapper;
 
     private VariableMapper varMapper;
-    private VariableMapper targetVarMapper;
 
     private transient Node node;
 
@@ -134,13 +133,11 @@
      * 
      */
     public ValueExpressionImpl(String expr, Node node, FunctionMapper 
fnMapper,
-            VariableMapper varMapper, VariableMapper targetVarMapper,
-            Class expectedType) {
+            VariableMapper varMapper, Class expectedType) {
         this.expr = expr;
         this.node = node;
         this.fnMapper = fnMapper;
         this.varMapper = varMapper;
-        this.targetVarMapper = targetVarMapper;
         this.expectedType = expectedType;
     }
 
@@ -199,7 +196,7 @@
     public Class getType(ELContext context) throws PropertyNotFoundException,
             ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, this.targetVarMapper);
+                this.varMapper);
         return this.getNode().getType(ctx);
     }
 
@@ -211,7 +208,7 @@
     public ValueReference getValueReference(ELContext context)
             throws PropertyNotFoundException, ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper,  this.targetVarMapper);
+                this.varMapper);
         return this.getNode().getValueReference(ctx);
     }
 
@@ -223,7 +220,7 @@
     public Object getValue(ELContext context) throws 
PropertyNotFoundException,
             ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, this.targetVarMapper);
+                this.varMapper);
         Object value = this.getNode().getValue(ctx);
         if (this.expectedType != null) {
             try {
@@ -265,7 +262,7 @@
     public boolean isReadOnly(ELContext context)
             throws PropertyNotFoundException, ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, this.targetVarMapper);
+                this.varMapper);
         return this.getNode().isReadOnly(ctx);
     }
 
@@ -278,7 +275,6 @@
         }
         this.fnMapper = (FunctionMapper) in.readObject();
         this.varMapper = (VariableMapper) in.readObject();
-        this.targetVarMapper = (VariableMapper) in.readObject();
     }
 
     /*
@@ -291,7 +287,7 @@
             throws PropertyNotFoundException, PropertyNotWritableException,
             ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
-                this.varMapper, targetVarMapper);
+                this.varMapper);
         this.getNode().setValue(ctx, value);
     }
 
@@ -301,7 +297,6 @@
                 : "");
         out.writeObject(this.fnMapper);
         out.writeObject(this.varMapper);
-        out.writeObject(this.targetVarMapper);
     }
 
     public String toString() {





[el-spec commits] [el-spec~source-code:58] Revert adding a targetVariableMapper since setting an EL variable for

kchung 03/22/2012
 
 
Close
loading
Please Confirm
Close