You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/11/03 15:37:52 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/util/introspection ClassMap.java MethodMap.java

jvanzyl     00/11/03 06:37:51

  Modified:    src/java/org/apache/velocity/util/introspection
                        ClassMap.java MethodMap.java
  Log:
  - fixed a bug where the introspector wasn't returning the correct
    method due to the structure of a while loop.
  
  Revision  Changes    Path
  1.4       +11 -6     jakarta-velocity/src/java/org/apache/velocity/util/introspection/ClassMap.java
  
  Index: ClassMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/introspection/ClassMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClassMap.java	2000/11/01 20:45:30	1.3
  +++ ClassMap.java	2000/11/03 14:37:49	1.4
  @@ -55,6 +55,7 @@
    */
   
   import java.util.Map;
  +import java.util.List;
   import java.util.Hashtable;
   
   import java.lang.reflect.Method;
  @@ -64,14 +65,14 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:bob@werken.com">Bob McWhirter</a>
  - * @version $Id: ClassMap.java,v 1.3 2000/11/01 20:45:30 werken Exp $
  + * @version $Id: ClassMap.java,v 1.4 2000/11/03 14:37:49 jvanzyl Exp $
    */
   
   public class ClassMap
   {
  -    static final private class CacheMiss { }
  -    
  -    static final private CacheMiss CACHE_MISS = new CacheMiss();
  +    private static final class CacheMiss { }
  +    private static final CacheMiss CACHE_MISS = new CacheMiss();
  +    private static final Object OBJECT = new Object();
   
       /** 
        * Class passed into the constructor used to as
  @@ -175,7 +176,7 @@
           
           for (int j = 0; j < parameterTypes.length; j++)
               methodKey.append(parameterTypes[j].getName());
  -
  +        
           return methodKey.toString();
       }
   
  @@ -184,8 +185,12 @@
           StringBuffer methodKey = new StringBuffer().append(method);
           
           for (int j = 0; j < params.length; j++)
  +        {
  +            if (params[j] == null)
  +                params[j] = OBJECT;
               methodKey.append(params[j].getClass().getName());
  -
  +        }            
  +        
           return methodKey.toString();
       }
   }
  
  
  
  1.4       +11 -9     jakarta-velocity/src/java/org/apache/velocity/util/introspection/MethodMap.java
  
  Index: MethodMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/introspection/MethodMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MethodMap.java	2000/11/01 20:45:31	1.3
  +++ MethodMap.java	2000/11/03 14:37:50	1.4
  @@ -65,7 +65,7 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:bob@werken.com">Bob McWhirter</a>
  - * @version $Id: MethodMap.java,v 1.3 2000/11/01 20:45:31 werken Exp $
  + * @version $Id: MethodMap.java,v 1.4 2000/11/03 14:37:50 jvanzyl Exp $
    */
   
   public class MethodMap
  @@ -87,6 +87,11 @@
           ((List) methodByNameMap.get(methodName)).add(method);
       }
   
  +    public List get(String key)
  +    {
  +        return (List) methodByNameMap.get("key");
  +    }
  +
       public Method find(String methodName, Object[] params)
       {
           List methodList = (List) methodByNameMap.get(methodName);
  @@ -99,10 +104,9 @@
           Class[] parameterTypes = null;
           Method  method = null;
   
  -        int     i = 0;
  -        int     numMethods = methodList.size();
  +        int numMethods = methodList.size();
           
  -        while ( (method == null) && ( i < numMethods ) )
  +        for (int i = 0; i < numMethods; i++)
           {
               method = (Method) methodList.get(i);
               parameterTypes = method.getParameterTypes();
  @@ -118,15 +122,13 @@
                   for (int j = 0; j < parameterTypes.length; j++)
                   {
                       if (!parameterTypes[j].isAssignableFrom(params[j].getClass()))
  -                    {
  -                        method = null;
                           break;
  -                    }
  +
  +                    return method;
                   }
               }
  -            ++i;
           }
   
  -        return method;
  +        return null;
       }
   }