[jboss-cvs] JBossAS SVN: r92990 - projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Aug 29 13:28:03 EDT 2009


Author: jesper.pedersen
Date: 2009-08-29 13:28:02 -0400 (Sat, 29 Aug 2009)
New Revision: 92990

Modified:
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
Log:
[JBANN-3] Support inheritance (Part 4)

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-08-29 15:47:56 UTC (rev 92989)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-08-29 17:28:02 UTC (rev 92990)
@@ -192,57 +192,66 @@
          ClassInfo ci = classInfo.get(clz);
          Collection<Annotation> as = ci.getAnnotations(annotation);
 
-         if (!ci.isAbstract() || ci.isInterface())
+         if (as != null && as.size() > 0)
          {
-            if (as != null && as.size() > 0)
+            if (!ci.isAbstract() || ci.isInterface())
             {
                l.addAll(as);
             }
 
-            if (ci.getChildren() != null)
-            {
-               for (String childClass : ci.getChildren())
-               {
-                  ClassInfo chdi = classInfo.get(childClass);
-                  if (chdi != null && as != null)
-                  {
-                     for (Annotation a : as)
-                     {
-                        Annotation na = new Annotation(a.getAnnotationClassName(), a.getAnnotation(),
-                                                       a.getType(), chdi.getClassName(), 
-                                                       a.getMemberName(), a.getParameterTypes());
-                        l.add(na);
-                     }
-                  }
-               }
-            }
+            Collection<Annotation> childAnnotations = foldAnnotations(as, ci);
+            if (childAnnotations != null)
+               l.addAll(childAnnotations);
          }
-         else
+      }
+
+      if (l.size() == 0)
+         return null;
+
+      return Collections.unmodifiableCollection(l);
+   }
+
+   /**
+    * Fold annotations onto children
+    * @param annotations The annotations that should folded onto each child
+    * @param ci The parent class information
+    * @return The folded annotations; <code>null</code> if there are no children
+    */
+   private Collection<Annotation> foldAnnotations(Collection<Annotation> annotations, ClassInfo ci)
+   {
+      if (ci != null && ci.getChildren() != null)
+      {
+         if (annotations != null && annotations.size() > 0)
          {
-            if (ci.getChildren() != null)
+            Collection<Annotation> result = new HashSet<Annotation>(annotations.size());
+
+            for (String childClass : ci.getChildren())
             {
-               for (String childClass : ci.getChildren())
+               ClassInfo chdi = classInfo.get(childClass);
+               if (chdi != null)
                {
-                  ClassInfo chdi = classInfo.get(childClass);
-                  if (chdi != null && as != null)
+                  if (!chdi.isAbstract() || chdi.isInterface())
                   {
-                     for (Annotation a : as)
+                     for (Annotation a : annotations)
                      {
                         Annotation na = new Annotation(a.getAnnotationClassName(), a.getAnnotation(),
                                                        a.getType(), chdi.getClassName(), 
                                                        a.getMemberName(), a.getParameterTypes());
-                        l.add(na);
+                        result.add(na);
                      }
                   }
+
+                  Collection<Annotation> childAnnotations = foldAnnotations(annotations, chdi);
+                  if (childAnnotations != null)
+                     result.addAll(childAnnotations);
                }
             }
+
+            return result;
          }
       }
 
-      if (l.size() == 0)
-         return null;
-
-      return Collections.unmodifiableCollection(l);
+      return null;
    }
 
    /**




More information about the jboss-cvs-commits mailing list