Commits

Anonymous committed ad2c2af

Testing list expressions.

  • Participants
  • Parent commits 1208017

Comments (0)

Files changed (4)

File src/java/ognl/ASTIn.java

     {
         Object v1 = _children[0].getValue( context, source );
         Object v2 = _children[1].getValue( context, source );
+
         return OgnlOps.in( v1, v2 )? Boolean.TRUE : Boolean.FALSE;
     }
 

File src/java/ognl/ASTList.java

  */
 public class ASTList extends SimpleNode implements NodeType
 {
-
-    private Class _getterClass;
-    
     public ASTList(int id)
     {
         super(id);
     }
 
     protected Object getValueBody(OgnlContext context, Object source)
-        throws OgnlException
+            throws OgnlException
     {
         List answer = new ArrayList(jjtGetNumChildren());
         for(int i = 0; i < jjtGetNumChildren(); ++i)
 
     public Class getGetterClass()
     {
-        return _getterClass;
+        return null;
     }
-    
+
     public Class getSetterClass()
     {
-        return _getterClass;
+        return null;
     }
-    
+
     public String toString()
     {
         String result = "{ ";
         }
         return result + " }";
     }
-    
+
     public String toGetSourceString(OgnlContext context, Object target)
     {
         String result = "";
         boolean array = false;
 
         if (_parent != null && ASTCtor.class.isInstance(_parent)
-                && ((ASTCtor)_parent).isArray()) {
+            && ((ASTCtor)_parent).isArray()) {
 
             array = true;
         }
-        
+
         context.setCurrentType(List.class);
         context.setCurrentAccessor(List.class);
 
                     if (valueClass != null && ctorClass.isArray()) {
 
                         value = OgnlRuntime.getCompiler().createLocalReference(context,
-                                "(" + ExpressionCompiler.getCastString(ctorClass)
-                                + ")ognl.OgnlOps.toArray(" + value + ", " + ctorClass.getComponentType().getName()
-                                + ".class, true)",
-                                ctorClass
+                                                                               "(" + ExpressionCompiler.getCastString(ctorClass)
+                                                                               + ")ognl.OgnlOps.toArray(" + value + ", " + ctorClass.getComponentType().getName()
+                                                                               + ".class, true)",
+                                                                               ctorClass
                         );
 
                     } else  if (ctorClass.isPrimitive()) {
 
                         Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass(ctorClass);
-                        
+
                         value = OgnlRuntime.getCompiler().createLocalReference(context,
-                                "((" + wrapClass.getName()
-                                + ")ognl.OgnlOps.convertValue(" + value + ","
-                                + wrapClass.getName() + ".class, true))."
-                                + OgnlRuntime.getNumericValueGetter(wrapClass),
-                                ctorClass
+                                                                               "((" + wrapClass.getName()
+                                                                               + ")ognl.OgnlOps.convertValue(" + value + ","
+                                                                               + wrapClass.getName() + ".class, true))."
+                                                                               + OgnlRuntime.getNumericValueGetter(wrapClass),
+                                                                               ctorClass
                         );
 
                     } else if (ctorClass != Object.class) {
 
                         value = OgnlRuntime.getCompiler().createLocalReference(context,
-                                "(" + ctorClass.getName() + ")ognl.OgnlOps.convertValue(" + value + "," + ctorClass.getName() + ".class)",
-                                ctorClass
+                                                                               "(" + ctorClass.getName() + ")ognl.OgnlOps.convertValue(" + value + "," + ctorClass.getName() + ".class)",
+                                                                               ctorClass
                         );
-                        
+
                     } else if ((NodeType.class.isInstance(_children[i])
                                 && ((NodeType)_children[i]).getGetterClass() != null
                                 && Number.class.isAssignableFrom(((NodeType)_children[i]).getGetterClass()))
                     } else if (valueClass.isPrimitive()) {
                         value = "($w) (" + value + ")";
                     }
-                    
+
                 } else if (ctorClass == null || !ctorClass.isPrimitive()) {
 
                     value = " ($w) (" + value + ")";
 
                 if (objValue == null || value.length() <= 0)
                     value = "null";
-                
+
                 result += value;
             }
 
         context.setCurrentAccessor(List.class);
 
         result += "}";
-        
+
         if (!array)
             result += ")";
-        
+
         return result;
     }
-    
+
     public String toSetSourceString(OgnlContext context, Object target)
     {
         throw new UnsupportedCompilationException("Can't generate setter for ASTList.");

File src/java/ognl/ASTSequence.java

 public class ASTSequence extends SimpleNode implements NodeType, OrderedReturn
 {
     private Class _getterClass;
-    
     private String _lastExpression;
-    
     private String _coreExpression;
-    
+
     public ASTSequence(int id) {
         super(id);
     }
     protected Object getValueBody( OgnlContext context, Object source ) throws OgnlException
     {
         Object result = null;
-        for ( int i=0; i < _children.length; ++i ) {
+        for ( int i=0; i < _children.length; ++i )
+        {
             result = _children[i].getValue( context, source );
         }
+        
         return result; // The result is just the last one we saw.
     }
 
     {
         return _getterClass;
     }
-    
+
     public Class getSetterClass()
     {
         return null;
     }
-    
+
     public String getLastExpression()
     {
         return _lastExpression;
     }
-    
+
     public String getCoreExpression()
     {
         return _coreExpression;
     }
-    
+
     public String toString()
     {
         String      result = "";
-        
+
         for ( int i=0; i < _children.length; ++i ) {
             if (i > 0) {
                 result = result + ", ";
         }
         return result;
     }
-    
+
     public String toSetSourceString(OgnlContext context, Object target)
     {
         return "";
     }
-    
+
     public String toGetSourceString(OgnlContext context, Object target)
     {
         String result = "";
-        
+
         NodeType _lastType = null;
-        
-        for (int i = 0; i < _children.length; ++i) {
+
+        for (int i = 0; i < _children.length; ++i)
+        {
             //System.out.println("astsequence child : " + _children[i].getClass().getName());
             String seqValue = _children[i].toGetSourceString(context, target);
-            
+
             if ((i + 1) < _children.length
-                    && ASTOr.class.isInstance(_children[i])) {
+                && ASTOr.class.isInstance(_children[i])) {
                 seqValue = "(" + seqValue + ")";
             }
-            
+
             if (i > 0 && ASTProperty.class.isInstance(_children[i])
-                    && seqValue != null && seqValue.trim().length() > 0) {
+                && seqValue != null && seqValue.trim().length() > 0)
+            {
                 String pre = (String)context.get("_currentChain");
                 if (pre == null)
                     pre = "";
-                
+
                 seqValue = ExpressionCompiler.getRootExpression(_children[i], context.getRoot(), context) + pre + seqValue;
                 context.setCurrentAccessor(context.getRoot().getClass());
             }
-            
-            if ((i + 1) >= _children.length) {
+
+            if ((i + 1) >= _children.length)
+            {
                 _coreExpression = result;
                 _lastExpression = seqValue;
             }
-            
+
             if (seqValue != null && seqValue.trim().length() > 0 && (i + 1) < _children.length)
                 result += seqValue + ";";
             else if (seqValue != null && seqValue.trim().length() > 0)
                 result += seqValue;
-            
+
             // set last known type from last child with a type
-            
+
             if (NodeType.class.isInstance(_children[i]) && ((NodeType)_children[i]).getGetterClass() != null)
                 _lastType = (NodeType)_children[i];
-            
         }
-        
-        if (_lastType != null) {
-            
+
+        if (_lastType != null)
+        {
             _getterClass = _lastType.getGetterClass();
         }
-        
+
         return result;
     }
 }

File src/test/java/ognl/InExpressionTest.java

+package ognl;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for OGNL-118.
+ */
+public class InExpressionTest extends TestCase {
+
+    public void test_String_In()
+            throws Exception
+    {
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
+        Object node = Ognl.parseExpression("#name in {\"Greenland\", \"Austin\", \"Africa\", \"Rome\"}");
+        Object root = null;
+
+        context.put("name", "Austin");
+        assertEquals(Boolean.TRUE, Ognl.getValue(node, context, root));
+    }
+}