You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by le...@apache.org on 2003/09/20 17:11:34 UTC

cvs commit: jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test AttributesTestCase.java Sample.java SampleIF1.java

leosutic    2003/09/20 08:11:34

  Modified:    attributes project.xml
               attributes/api/src/java overview.html
               attributes/api/src/java/org/apache/commons/attributes
                        Attributes.java CachedRepository.java
                        DefaultCachedRepository.java
                        EmptyCachedRepository.java
               attributes/compiler/src/java/org/apache/commons/attributes/compiler
                        AttributeCompiler.java AttributeIndexer.java
               attributes/site/xdocs index.xml
               attributes/unittest/src/test/org/apache/commons/attributes/test
                        AttributesTestCase.java Sample.java SampleIF1.java
  Log:
  Added ability to add attributes to method parameters and return values.
  
  Revision  Changes    Path
  1.8       +1 -1      jakarta-commons-sandbox/attributes/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/project.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- project.xml	22 Aug 2003 23:48:45 -0000	1.7
  +++ project.xml	20 Sep 2003 15:11:34 -0000	1.8
  @@ -5,7 +5,7 @@
       <pomVersion>3</pomVersion>
       <groupId>commons-attributes</groupId>
       <name>Jakarta Commons Attributes</name>
  -    <logo>./docs/attributes-logo.gif</logo>
  +    <logo>/attributes-logo.gif</logo>
       
       <currentVersion>2.0alpha</currentVersion>
       
  
  
  
  1.3       +35 -4     jakarta-commons-sandbox/attributes/api/src/java/overview.html
  
  Index: overview.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/overview.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- overview.html	22 Aug 2003 23:48:15 -0000	1.2
  +++ overview.html	20 Sep 2003 15:11:34 -0000	1.3
  @@ -50,7 +50,18 @@
    */
   public class MyClass { }</pre></blockquote>
           
  -        <h3>How do I use it?</h3>
  +        <h3>How do I use it with Maven?</h3>
  +        
  +        <p>Two steps: First, install the plugin. Your sources will be automatically precompiled. 
  +        Second, add the client api as a dependency: </p>
  +        
  +        <blockquote><pre>&lt;dependency&gt;
  +    &lt;groupId&gt;commons-attributes&lt;/groupId&gt;
  +    &lt;artifactId&gt;commons-attributes-api&lt;/artifactId&gt;
  +    &lt;version&gt;SNAPSHOT&lt;/version&gt;
  +&lt;/dependency&gt;</pre></blockquote>
  +        
  +        <h3>How do I use it with Ant?</h3>
           
           <p>The Attributes project provides a precompiler that you must run before you compile your Java
           classes with Javac (or some other Java compiler). The process goes like this:</p>
  @@ -176,6 +187,21 @@
   BUILD SUCCESSFUL
   Total time: 3 seconds</pre></blockquote>
           
  +        <h3>How do I add attributes to parameters and return values?</h3>
  +        
  +        <p>Use the following syntax:</p>
  +        <blockquote><pre>public class MyClass {
  +
  +    /**
  +     * @@.myParameter MyOtherAttribute
  +     * @@.return MyAttribute
  +     */
  +    public Integer myMethod (int myParameter) {};
  +
  +}</pre></blockquote>        
  +        
  +        <p>You will then be able to retrieve MyAttribute via <code>Attributes.getReturnAttribute( method )</code>
  +        and MyOtherAttribute via <code>Attributes.getParameterAttribute( method, 0 )</code></p>
           
           <h3>What happens if I add the same attribute twice?</h3>
           
  @@ -187,18 +213,23 @@
    */
   public class MyClass {}</pre></blockquote>
           
  -        <p>The question is now, will the collection returned by Attributes.getAttributes (MyClass.class) have one or two elements? The answer is that it depends on the way MyAttribute handles equality. The attributes associated with a class, method or field always for a Set, meaning that there are no duplicates. So if MyAttribute is implemented this way:</p>
  +        <p>The question is now, will the collection returned by Attributes.getAttributes (MyClass.class) have one or 
  +        two elements? The answer is that it depends on the way MyAttribute handles equality. The attributes associated
  +        with a class, method or field always for a Set, meaning that there are no duplicates. So if MyAttribute is 
  +        implemented this way:</p>
           
           <blockquote><pre>public class MyAttribute {}</pre></blockquote>
           
  -        <p>Then you will get two elements, since each instance of MyAttribute is different from every other instance. However, if MyAttribute is implemented like this:</p>
  +        <p>Then you will get two elements, since each instance of MyAttribute is different from every other instance. 
  +        However, if MyAttribute is implemented like this:</p>
           
           <blockquote><pre>public class MyAttribute {
       public int hashCode () { return 0; }
       public boolean equals (Object o) { return o instanceof MyAttribute; }
   }</pre></blockquote>
           
  -        <p>That is, every instance of MyAttribute is equal to any other instance of the class, then you will only get one element in the collection.</p>
  +        <p>That is, every instance of MyAttribute is equal to any other instance of the class, then you will only get
  +        one element in the collection.</p>
           
           <p>The above also holds true if the attribute has been inherited.</p>
           
  
  
  
  1.4       +54 -30    jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Attributes.java
  
  Index: Attributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/Attributes.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Attributes.java	24 Aug 2003 17:47:59 -0000	1.3
  +++ Attributes.java	20 Sep 2003 15:11:34 -0000	1.4
  @@ -146,6 +146,20 @@
       }
       
       /**
  +     * Gets all attributes for a parameter of a method.
  +     */
  +    public static Collection getParameterAttributes (Method method, int parameter) {
  +        return getCachedRepository (method.getDeclaringClass()).getParameterAttributes (method, parameter);
  +    }
  +    
  +    /**
  +     * Gets all attributes for the return value of a method.
  +     */
  +    public static Collection getReturnAttributes (Method method) {
  +        return getCachedRepository (method.getDeclaringClass()).getReturnAttributes (method);
  +    }
  +    
  +    /**
        * Gets all attributes for a field.
        */
       public static Collection getAttributes (Field field) {
  @@ -206,6 +220,22 @@
       public static Collection getAttributes (Method method, Class attributeClass) {
           return getAttributes (getAttributes (method), attributeClass);
       }
  +
  +    /**
  +     * Get all attributes of a given type from a method's parameter. For all objects o in the returned 
  +     * collection, <code>o.getClass() == attributeClass</code>.
  +     */
  +    public static Collection getParameterAttributes (Method method, int parameter, Class attributeClass) {
  +        return getAttributes (getParameterAttributes (method, parameter), attributeClass);
  +    }
  +    
  +    /**
  +     * Get all attributes of a given type from a method's return value. For all objects o in the returned 
  +     * collection, <code>o.getClass() == attributeClass</code>.
  +     */
  +    public static Collection getReturnAttributes (Method method, Class attributeClass) {
  +        return getAttributes (getReturnAttributes (method), attributeClass);
  +    }
       
       /**
        * Convenience function to test whether a collection of attributes contain
  @@ -256,6 +286,22 @@
       }
       
       /**
  +     * Tests if a method's parameter has an attribute of a given type. That is, is there any attribute
  +     * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
  +     */
  +    public static boolean hasParameterAttributeType (Method method, int parameter, Class attributeClass) {
  +        return hasAttributeType (getParameterAttributes (method, parameter), attributeClass);
  +    }
  +    
  +    /**
  +     * Tests if a method's return value has an attribute of a given type. That is, is there any attribute
  +     * <code>attr</code> such that <code>attr.getClass() == attributeClass</code>?
  +     */
  +    public static boolean hasReturnAttributeType (Method method, Class attributeClass) {
  +        return hasAttributeType (getReturnAttributes (method), attributeClass);
  +    }
  +    
  +    /**
        * Convenience function to test whether a collection of attributes contain
        * an attribute.
        */
  @@ -296,40 +342,18 @@
       }
       
       /**
  -     * Constructs an <code>AttributeIndex</code> for the given <code>ClassLoader</code>.
  -     * An AttributeIndex allows oyu to quickly find all classes that have a given
  -     * attribute.
  -     *
  -     * @deprecated This doesn't really belong here, and since I can move it into
  -     *             a separate class, I will. This class should concentrate on retrieving
  -     *             attributes from various elements, and not get into things like
  -     *             indexes and so on. Use <code>new AttributeIndex (cl)</code> instead. 
  -     *             <b>This method will be removed before 2.0.</b>
  -     */
  -    public static AttributeIndex getAttributeIndex (ClassLoader cl) throws Exception {
  -        return new AttributeIndex (cl);
  -    }
  -    
  -    
  -    /**
  -     * Filters a collection of <code>Class</code> objects. The returned collection
  -     * only contains those classes that have an attribute of the specified type.
  -     *
  -     * @deprecated moved to <code>AttributeUtil</code>. <b>This method will be removed
  -     *             before 2.0</b>
  +     * Tests if a method's parameter has an attribute. That is, is there any attribute
  +     * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        */
  -    public static Collection getClassesWithAttributeType (Collection classes, Class attributeClass) {
  -        return AttributeUtil.getClassesWithAttributeType (classes, attributeClass);
  +    public static boolean hasParameterAttribute (Method method, int parameter, Object attribute) {
  +        return hasAttribute (getParameterAttributes (method, parameter), attribute);
       }
       
       /**
  -     * Filters a collection objects. The returned collection
  -     * only contains those objects that have an attribute of the specified type.
  -     *
  -     * @deprecated moved to <code>AttributeUtil</code>.
  -     *             <b>This method will be removed before 2.0.</b>
  +     * Tests if a method's return value has an attribute. That is, is there any attribute
  +     * <code>attr</code> such that <code>attr.equals(attribute)</code>?
        */
  -    public static Collection getObjectsWithAttributeType (Collection objects, Class attributeClass) {
  -        return AttributeUtil.getObjectsWithAttributeType (objects, attributeClass);
  +    public static boolean hasReturnAttribute (Method method, Object attribute) {
  +        return hasAttribute (getReturnAttributes (method), attribute);
       }
   }
  
  
  
  1.4       +2 -0      jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/CachedRepository.java
  
  Index: CachedRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/CachedRepository.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CachedRepository.java	24 Aug 2003 17:47:59 -0000	1.3
  +++ CachedRepository.java	20 Sep 2003 15:11:34 -0000	1.4
  @@ -72,5 +72,7 @@
       public Collection getAttributes ();
       public Collection getAttributes (Field f);
       public Collection getAttributes (Method m);
  +    public Collection getParameterAttributes (Method m, int parameter);
  +    public Collection getReturnAttributes (Method m);
       public Collection getAttributes (Constructor c);
   }
  
  
  
  1.4       +147 -5    jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/DefaultCachedRepository.java
  
  Index: DefaultCachedRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/DefaultCachedRepository.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultCachedRepository.java	24 Aug 2003 17:47:59 -0000	1.3
  +++ DefaultCachedRepository.java	20 Sep 2003 15:11:34 -0000	1.4
  @@ -63,6 +63,7 @@
   import java.util.Collection;
   import java.util.Collections;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   import java.util.Set;
   import java.util.HashSet;
  @@ -77,6 +78,39 @@
       private final Map methods = new HashMap ();
       private final Map constructors = new HashMap ();
       
  +    private static class MethodAttributeBundle {
  +        private Collection attributes = EMPTY_COLLECTION;
  +        private List parameterAttributes = new ArrayList ();
  +        private Collection returnAttributes = EMPTY_COLLECTION;
  +        
  +        public MethodAttributeBundle () {
  +        }
  +        
  +        public Collection getAttributes () {
  +            return attributes;
  +        }
  +        
  +        public Collection getReturnAttributes () {
  +            return returnAttributes;
  +        }
  +        
  +        public Collection getParameterAttributes (int index) {
  +            return (Collection) parameterAttributes.get (index);
  +        }
  +        
  +        public void setAttributes (Collection attributes) {
  +            this.attributes = Collections.unmodifiableCollection (attributes);
  +        }
  +        
  +        public void setReturnAttributes (Collection returnAttributes) {
  +            this.returnAttributes = Collections.unmodifiableCollection (returnAttributes);
  +        }
  +        
  +        public void addParameterAttributes (Collection parameterAttributes) {
  +            this.parameterAttributes.add (Collections.unmodifiableCollection (parameterAttributes));
  +        }
  +    }
  +    
       public DefaultCachedRepository (Class clazz, AttributeRepositoryClass repo) {
           
           // ---- Fix up class attributes
  @@ -93,13 +127,19 @@
           // ---- Fix up method attributes
           Method[] methods = clazz.getDeclaredMethods ();
           for (int i = 0; i < methods.length; i++) {
  +            MethodAttributeBundle bundle = new MethodAttributeBundle ();
  +            
               Method m = methods[i];
               String key = Util.getSignature (m);
               
  -            Set attributes = new HashSet ();
  -            
  +            List attributeBundle = null;
               if (repo.getMethodAttributes ().containsKey (key)) {
  -                attributes.addAll ((Collection) repo.getMethodAttributes ().get (key));
  +                attributeBundle = (List) repo.getMethodAttributes ().get (key);
  +            }                
  +            
  +            Set attributes = new HashSet ();
  +            if (attributeBundle != null) {
  +                attributes.addAll ((Collection) attributeBundle.get (0));
               }
               attributes.addAll (getInheritableMethodAttributes (clazz.getSuperclass (), m.getName (), m.getParameterTypes ()));
               for (int j = 0; j < ifs.length; j++) {
  @@ -107,8 +147,38 @@
               }
               
               if (attributes.size () > 0) {
  -                this.methods.put (m, Collections.unmodifiableCollection (attributes));
  +                bundle.setAttributes (attributes);
  +            }
  +            
  +            // ---- Return value attributes
  +            attributes = new HashSet ();
  +            if (attributeBundle != null) {
  +                attributes.addAll ((Collection) attributeBundle.get (1));
               }
  +            attributes.addAll (getInheritableReturnAttributes (clazz.getSuperclass (), m.getName (), m.getParameterTypes ()));
  +            for (int j = 0; j < ifs.length; j++) {
  +                attributes.addAll (getInheritableReturnAttributes (ifs[j], m.getName (), m.getParameterTypes ()));
  +            }
  +            if (attributes.size () > 0) {
  +                bundle.setReturnAttributes (attributes);
  +            }
  +            
  +            // ---- Parameter attributes
  +            int numParameters = m.getParameterTypes().length;
  +            for (int k = 0; k < numParameters; k++) {
  +                attributes = new HashSet ();
  +                if (attributeBundle != null) {
  +                    attributes.addAll ((Collection) attributeBundle.get (k + 2));
  +                }
  +                attributes.addAll (getInheritableMethodParameterAttributes (clazz.getSuperclass (), m.getName (), m.getParameterTypes (), k));
  +                for (int j = 0; j < ifs.length; j++) {
  +                    attributes.addAll (getInheritableMethodParameterAttributes (ifs[j], m.getName (), m.getParameterTypes (), k));
  +                }
  +                                
  +                bundle.addParameterAttributes (attributes);
  +            }
  +            
  +            this.methods.put (m, bundle);
           }
           
           // --- Just copy constructor attributes (they aren't inherited)
  @@ -194,6 +264,62 @@
           return result;
       }
       
  +    private static Collection getInheritableMethodParameterAttributes (Class c, String methodName, Class[] methodParams, int parameter) {
  +        if (c == null) {
  +            return new ArrayList (0);
  +        }
  +        
  +        HashSet result = new HashSet ();
  +        
  +        try {
  +            // Get equivalent method in c
  +            Method m = c.getMethod (methodName, methodParams);
  +            if (m.getDeclaringClass () == c) {
  +                result.addAll (getInheritableAttributes (Attributes.getParameterAttributes (m, parameter)));
  +            }
  +        } catch (NoSuchMethodException nsme) {
  +        }
  +        
  +        // Traverse the class hierarchy
  +        result.addAll (getInheritableMethodParameterAttributes (c.getSuperclass (), methodName, methodParams, parameter));
  +        
  +        // Traverse the interface hierarchy
  +        Class[] ifs = c.getInterfaces ();
  +        for (int i = 0; i < ifs.length; i++) {
  +            result.addAll (getInheritableMethodParameterAttributes (ifs[i], methodName, methodParams, parameter));
  +        }
  +        
  +        return result;
  +    }
  +    
  +    private static Collection getInheritableReturnAttributes (Class c, String methodName, Class[] methodParams) {
  +        if (c == null) {
  +            return new ArrayList (0);
  +        }
  +        
  +        HashSet result = new HashSet ();
  +        
  +        try {
  +            // Get equivalent method in c
  +            Method m = c.getMethod (methodName, methodParams);
  +            if (m.getDeclaringClass () == c) {
  +                result.addAll (getInheritableAttributes (Attributes.getReturnAttributes (m)));
  +            }
  +        } catch (NoSuchMethodException nsme) {
  +        }
  +        
  +        // Traverse the class hierarchy
  +        result.addAll (getInheritableReturnAttributes (c.getSuperclass (), methodName, methodParams));
  +        
  +        // Traverse the interface hierarchy
  +        Class[] ifs = c.getInterfaces ();
  +        for (int i = 0; i < ifs.length; i++) {
  +            result.addAll (getInheritableReturnAttributes (ifs[i], methodName, methodParams));
  +        }
  +        
  +        return result;
  +    }
  +    
       public Collection getAttributes () {
           return classAttributes;
       }
  @@ -209,7 +335,23 @@
       
       public Collection getAttributes (Method m) {
           if (methods.containsKey (m)) {
  -            return (Collection) methods.get (m);
  +            return ((MethodAttributeBundle) methods.get (m)).getAttributes ();
  +        } else {
  +            return EMPTY_COLLECTION;
  +        }
  +    }
  +    
  +    public Collection getParameterAttributes (Method m, int parameter) {
  +        if (methods.containsKey (m)) {
  +            return ((MethodAttributeBundle) methods.get (m)).getParameterAttributes (parameter);
  +        } else {
  +            return EMPTY_COLLECTION;
  +        }
  +    }
  +    
  +    public Collection getReturnAttributes (Method m) {
  +        if (methods.containsKey (m)) {
  +            return ((MethodAttributeBundle) methods.get (m)).getReturnAttributes ();
           } else {
               return EMPTY_COLLECTION;
           }
  
  
  
  1.3       +8 -0      jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/EmptyCachedRepository.java
  
  Index: EmptyCachedRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/api/src/java/org/apache/commons/attributes/EmptyCachedRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EmptyCachedRepository.java	22 Aug 2003 23:48:15 -0000	1.2
  +++ EmptyCachedRepository.java	20 Sep 2003 15:11:34 -0000	1.3
  @@ -81,6 +81,14 @@
           return EMPTY_COLLECTION;
       }
       
  +    public Collection getParameterAttributes (Method m, int parameter) {
  +        return EMPTY_COLLECTION;
  +    }
  +    
  +    public Collection getReturnAttributes (Method m) {
  +        return EMPTY_COLLECTION;
  +    }
  +    
       public Collection getAttributes (Constructor c) {
           return EMPTY_COLLECTION;
       }
  
  
  
  1.4       +44 -2     jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java
  
  Index: AttributeCompiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeCompiler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AttributeCompiler.java	23 Aug 2003 21:07:11 -0000	1.3
  +++ AttributeCompiler.java	20 Sep 2003 15:11:34 -0000	1.4
  @@ -151,6 +151,10 @@
       }
       
       protected void addExpressions (Collection tags, PrintWriter pw, String collectionName, String fileName) {
  +        addExpressions (tags, null, pw, collectionName, fileName);
  +    }
  +    
  +    protected void addExpressions (Collection tags, String selector, PrintWriter pw, String collectionName, String fileName) {
           fileName = fileName.replace ('\\', '/');
           Iterator iter = tags.iterator ();
           while (iter.hasNext ()) {
  @@ -164,6 +168,26 @@
                       expression = expression.substring (1);
                   }
                   
  +                if (selector != null) {
  +                    if (expression.startsWith (".")) {
  +                        // We have selector, tag does...
  +                        String tagSelector = expression.substring (1, expression.indexOf (" "));
  +                        expression = expression.substring (expression.indexOf (" ")).trim ();
  +                        if (!selector.equals (tagSelector)) {
  +                            // ...but they didn't match.
  +                            continue;
  +                        }
  +                    } else {
  +                        // We have selector, but tag doesn't
  +                        continue;
  +                    }
  +                } else {
  +                    // No selector, but tag has selector.
  +                    if (expression.startsWith (".")) {
  +                        continue;
  +                    }
  +                }
  +                
                   if (!expression.endsWith (")")) {
                       expression = expression + "()";
                   }
  @@ -302,6 +326,7 @@
               
               pw.println ("    private static void initMethodAttributes () {");
               pw.println ("        java.util.Set attrs = null;");
  +            pw.println ("        java.util.List bundle = null;");
               for (Iterator iter = xClass.getMethods ().iterator (); iter.hasNext ();) {
                   XMethod member = (XMethod) iter.next ();
                   if (member.getDoc ().getTags ().size () > 0) {
  @@ -311,10 +336,27 @@
                       sb.append (")");
                       String key = sb.toString ();
                       
  +                    pw.println ("        bundle = new java.util.ArrayList ();");
                       pw.println ("        attrs = new java.util.HashSet ();");
  -                    addExpressions (member.getDoc ().getTags (), pw, "attrs", sourceFile.getPath ());
  -                    pw.println ("        methodAttributes.put (\"" + key + "\", attrs);");
  +                    addExpressions (member.getDoc ().getTags (), null, pw, "attrs", sourceFile.getPath ());
  +                    pw.println ("        bundle.add (attrs);");
                       pw.println ("        attrs = null;");
  +                    
  +                    pw.println ("        attrs = new java.util.HashSet ();");
  +                    addExpressions (member.getDoc ().getTags (), "return", pw, "attrs", sourceFile.getPath ());
  +                    pw.println ("        bundle.add (attrs);");
  +                    pw.println ("        attrs = null;");
  +                    
  +                    for (Iterator parameters = member.getParameters ().iterator (); parameters.hasNext ();) {
  +                        XParameter parameter = (XParameter) parameters.next ();
  +                        pw.println ("        attrs = new java.util.HashSet ();");
  +                        addExpressions (member.getDoc ().getTags (), parameter.getName (), pw, "attrs", sourceFile.getPath ());
  +                        pw.println ("        bundle.add (attrs);");
  +                        pw.println ("        attrs = null;");
  +                    }
  +                    
  +                    pw.println ("        methodAttributes.put (\"" + key + "\", bundle);");
  +                    pw.println ("        bundle = null;");
                       pw.println ();
                   }                
               }
  
  
  
  1.4       +2 -1      jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeIndexer.java
  
  Index: AttributeIndexer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/compiler/AttributeIndexer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AttributeIndexer.java	25 Aug 2003 18:17:59 -0000	1.3
  +++ AttributeIndexer.java	20 Sep 2003 15:11:34 -0000	1.4
  @@ -76,6 +76,7 @@
   
   import org.apache.commons.attributes.AttributeRepositoryClass;
   import org.apache.commons.attributes.Attributes;
  +import org.apache.commons.attributes.AttributeUtil;
   import org.apache.commons.attributes.Indexed;
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
  @@ -221,7 +222,7 @@
                                   indexedAttrs.add (inner.next ().getClass ());
                               }
                               
  -                            indexedAttrs = Attributes.getClassesWithAttributeType (indexedAttrs, Indexed.class);
  +                            indexedAttrs = AttributeUtil.getClassesWithAttributeType (indexedAttrs, Indexed.class);
                               
                               inner = indexedAttrs.iterator ();
                               while (inner.hasNext ()) {
  
  
  
  1.6       +9 -1      jakarta-commons-sandbox/attributes/site/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/site/xdocs/index.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- index.xml	24 Aug 2003 17:48:00 -0000	1.5
  +++ index.xml	20 Sep 2003 15:11:34 -0000	1.6
  @@ -110,6 +110,14 @@
                       <td>Yes</td>
                   </tr>
                   <tr>
  +                    <td>Can add attributes to return values of methods</td>
  +                    <td>Yes</td>
  +                </tr>
  +                <tr>
  +                    <td>Can add attributes to method parameters</td>
  +                    <td>Yes</td>
  +                </tr>
  +                <tr>
                       <td>Can add attributes to fields</td>
                       <td>Yes</td>
                   </tr>
  @@ -155,7 +163,7 @@
                   </tr>
                   <tr>
                       <td>Runtime code size</td>
  -                    <td>16kB</td>
  +                    <td>17kB</td>
                   </tr>
                   <tr>
                       <td>Unit test coverage</td>
  
  
  
  1.3       +13 -0     jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/AttributesTestCase.java
  
  Index: AttributesTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/AttributesTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AttributesTestCase.java	24 Aug 2003 17:48:00 -0000	1.2
  +++ AttributesTestCase.java	20 Sep 2003 15:11:34 -0000	1.3
  @@ -100,6 +100,19 @@
           assertTrue (Attributes.hasAttribute (m, new Dependency ( SampleService.class, "sample-if-1" ) ));
           assertTrue (Attributes.hasAttribute (m, new Dependency ( SampleService.class, "sample-if-2" ) ));
       }
  +
  +    public void testParameterAndReturnAttributes () throws Exception {
  +        Method m = Sample.class.getMethod ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE });
  +        assertEquals (0, Attributes.getAttributes (m).size ());
  +        assertEquals (2, Attributes.getReturnAttributes (m).size ());
  +        assertTrue (Attributes.hasReturnAttribute (m, new Dependency ( SampleService.class, "sample-return" ) ));
  +        assertTrue (Attributes.hasReturnAttribute (m, new Dependency ( SampleService.class, "sample-if-return" ) ));
  +                
  +        assertEquals (0, Attributes.getParameterAttributes (m, 0).size ());
  +        assertEquals (2, Attributes.getParameterAttributes (m, 1).size ());
  +        assertTrue (Attributes.hasParameterAttribute (m, 1, new Dependency ( SampleService.class, "sample-if-param-2" ) ));
  +        assertTrue (Attributes.hasParameterAttribute (m, 1, new ThreadSafe () ));
  +    }
       
       public void testFieldNonInheritance () throws Exception {
           Field f = SuperSample.class.getField ("field");
  
  
  
  1.2       +8 -0      jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Sample.java
  
  Index: Sample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/Sample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Sample.java	20 Aug 2003 23:16:16 -0000	1.1
  +++ Sample.java	20 Sep 2003 15:11:34 -0000	1.2
  @@ -19,6 +19,14 @@
       public void someMethod () {
           
       }
  +
  +    /**
  +     * @@.param2 ThreadSafe
  +     * @@.return Dependency ( SampleService.class, "sample-return" )
  +     */
  +    public Integer methodWithAttributes (int param1, int param2) {
  +        return null;
  +    }
       
       /**
        * @@Dependency ( SampleService.class, "sample-some-method2" )
  
  
  
  1.2       +9 -3      jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SampleIF1.java
  
  Index: SampleIF1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/SampleIF1.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SampleIF1.java	20 Aug 2003 23:16:16 -0000	1.1
  +++ SampleIF1.java	20 Sep 2003 15:11:34 -0000	1.2
  @@ -1,13 +1,19 @@
   package org.apache.commons.attributes.test;
   
   /**
  - * @Dependency ( SampleService.class, "sample-if-1-c" )
  + * @@Dependency ( SampleService.class, "sample-if-1-c" )
    */
   public interface SampleIF1 {
       
       /**
  -     * @Dependency ( SampleService.class, "sample-if-1" )
  -     * @ThreadSafe ()
  +     * @@Dependency ( SampleService.class, "sample-if-1" )
  +     * @@ThreadSafe ()
        */
       public void someMethod (int parameter);
  +    
  +    /**
  +     * @@.return Dependency ( SampleService.class, "sample-if-return" )
  +     * @@.param2 Dependency ( SampleService.class, "sample-if-param-2" )
  +     */
  +    public Integer methodWithAttributes (int param1, int param2);
   }