proyal      2003/12/30 12:47:53

  Modified:    jexl/src/java/org/apache/commons/jexl/parser
                        ASTEmptyFunction.java
               jexl/src/test/org/apache/commons/jexl JexlTest.java
  Log:
  Testcase and fix for bug where the empty() function didn't work on bean.subitem
  
  Revision  Changes    Path
  1.4       +19 -27    
jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTEmptyFunction.java
  
  Index: ASTEmptyFunction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTEmptyFunction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ASTEmptyFunction.java     9 Oct 2003 21:28:55 -0000       1.3
  +++ ASTEmptyFunction.java     30 Dec 2003 20:47:53 -0000      1.4
  @@ -89,38 +89,30 @@
       {
           SimpleNode sn = (SimpleNode) jjtGetChild(0);
   
  -        if (sn instanceof ASTReference)
  -        {
  -            String s = ((ASTReference)sn).getRootString();
  +        /*
  +         * I can't believe this
  +         */
   
  -            /*
  -             * I can't believe this
  -             */
  +        Object o = sn.value(jc);
   
  -            Object o = jc.getVars().get(s);
  +        if (o == null)
  +            return Boolean.TRUE;
   
  -            if (o == null)
  -                return Boolean.TRUE;
  +        if (o instanceof String && ((String)o).equals(""))
  +            return Boolean.TRUE;
   
  -            if (o instanceof String && ((String)o).equals(""))
  -                return Boolean.TRUE;
  +        if (o.getClass().isArray() && ((Object[])o).length == 0)
  +            return Boolean.TRUE;
   
  -            if (o.getClass().isArray() && ((Object[])o).length == 0)
  -                return Boolean.TRUE;
  +        if (o instanceof Collection && ((Collection)o).isEmpty())
  +            return Boolean.TRUE;
   
  -            if (o instanceof Collection && ((Collection)o).isEmpty())
  -                return Boolean.TRUE;
  +        /*
  +         *  Map isn't a collection
  +         */
  +        if (o instanceof Map && ((Map)o).isEmpty())
  +            return Boolean.TRUE;
   
  -                     /*
  -                      *  Map isn't a collection
  -                      */
  -                     if (o instanceof Map && ((Map)o).isEmpty())
  -                             return Boolean.TRUE;
  -
  -            return Boolean.FALSE;
  -        }
  -
  -        throw new Exception("programmer error : ASTEmptyFunction : invalid root"
  -                    + sn);
  +        return Boolean.FALSE;
       }
   }
  
  
  
  1.34      +12 -1     
jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java
  
  Index: JexlTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- JexlTest.java     18 Dec 2003 16:10:57 -0000      1.33
  +++ JexlTest.java     30 Dec 2003 20:47:53 -0000      1.34
  @@ -57,6 +57,7 @@
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  +import java.util.Collections;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  @@ -977,6 +978,16 @@
           jc.getVars().put( "this.is.a.test", "");
   
           assertExpression(jc, "empty(this.is.a.test)", Boolean.TRUE);
  +    }
  +
  +    public void testEmptySubListOfMap() throws Exception
  +    {
  +        JexlContext jc = JexlHelper.createContext();
  +        Map m = Collections.singletonMap("aList", Collections.EMPTY_LIST);
  +
  +        jc.getVars().put( "aMap", m );
  +
  +        assertExpression( jc, "empty( aMap.aList )", Boolean.TRUE );
       }
   
       public void testCoercionWithComparisionOperators()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to