[jboss-cvs] JBossAS SVN: r92229 - in projects/annotations/trunk/core: src/main/java/org/jboss/annotations and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 11 09:39:56 EDT 2009


Author: jesper.pedersen
Date: 2009-08-11 09:39:56 -0400 (Tue, 11 Aug 2009)
New Revision: 92229

Added:
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/ITest.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/Test.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/package.html
Modified:
   projects/annotations/trunk/core/build.xml
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/InterfaceTests.java
Log:
[JBANN-19] [JBANN-20] New test case and enhancements to AR

Modified: projects/annotations/trunk/core/build.xml
===================================================================
--- projects/annotations/trunk/core/build.xml	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/build.xml	2009-08-11 13:39:56 UTC (rev 92229)
@@ -110,6 +110,9 @@
     <jar destfile="${build.core.dir}/testjars/classempty.jar"
          basedir="${build.core.dir}/test"
          includes="**/common/**, **/classempty/**"/>
+    <jar destfile="${build.core.dir}/testjars/classinterface.jar"
+         basedir="${build.core.dir}/test"
+         includes="**/common/**, **/classinterface/**"/>
     <jar destfile="${build.core.dir}/testjars/classlevel.jar"
          basedir="${build.core.dir}/test"
          includes="**/common/**, **/classlevel/**"/>

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -22,7 +22,7 @@
 
 package org.jboss.annotations;
 
-import java.util.List;
+import java.util.Collection;
 
 /**
  * An annotation repository
@@ -35,13 +35,28 @@
     * @param annotation The annotation class
     * @return True if the repository contains references
     */
-   public boolean hasAnnotation(Class annotation);
+   public boolean hasAnnotation(Class<?> annotation);
 
    /**
+    * Does the repository contain references of the specified annotation
+    * @param annotation The fully qualified class name for the annotation
+    * @return True if the repository contains references
+    */
+   public boolean hasAnnotation(String annotation);
+
+   /**
     * Get the instances of an annotation
     * @param annotation The annotation class
-    * @return The list of annotations of the specified class; <code>null</code>
+    * @return The collection of annotations of the specified class; <code>null</code>
     *         if no annotations exists
     */
-   public List<Annotation> getAnnotation(Class annotation);
+   public Collection<Annotation> getAnnotation(Class<?> annotation);
+
+   /**
+    * Get the instances of an annotation
+    * @param annotation The fully qualified class name for the annotation
+    * @return The collection of annotations of the specified class; <code>null</code>
+    *         if no annotations exists
+    */
+   public Collection<Annotation> getAnnotation(String annotation);
 }

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-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -25,8 +25,8 @@
 import org.jboss.annotations.Annotation;
 import org.jboss.annotations.AnnotationRepository;
 
+import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -38,18 +38,18 @@
 public class AnnotationRepositoryImpl implements AnnotationRepository
 {
    /** The repository */
-   private ConcurrentMap<String, List<Annotation>> repositoy;
+   private ConcurrentMap<String, Collection<Annotation>> repositoy;
 
    /**
     * Constructor
     * @param data The repository data
     */
-   public AnnotationRepositoryImpl(Map<String, List<Annotation>> data)
+   public AnnotationRepositoryImpl(Map<String, Collection<Annotation>> data)
    {
       if (data == null)
          throw new IllegalArgumentException("Data is null");
 
-      repositoy = new ConcurrentHashMap<String, List<Annotation>>(data);
+      repositoy = new ConcurrentHashMap<String, Collection<Annotation>>(data);
    }
 
    /**
@@ -57,31 +57,58 @@
     * @param annotation The annotation class
     * @return True if the repository contains references
     */
-   public boolean hasAnnotation(Class annotation)
+   public boolean hasAnnotation(Class<?> annotation)
    {
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      return repositoy.containsKey(annotation.getName());
+      return hasAnnotation(annotation.getName());
    }
 
    /**
+    * Does the repository contain references of the specified annotation
+    * @param annotation The fully qualified class name for the annotation
+    * @return True if the repository contains references
+    */
+   public boolean hasAnnotation(String annotation)
+   {
+      if (annotation == null)
+         throw new IllegalArgumentException("Annotation is null");
+
+      return repositoy.containsKey(annotation);
+   }
+
+   /**
     * Get the instances of an annotation
     * @param annotation The annotation class
     * @return The list of annotations of the specified class; <code>null</code>
     *         if no annotations exists
     */
-   public List<Annotation> getAnnotation(Class annotation)
+   public Collection<Annotation> getAnnotation(Class<?> annotation)
    {
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      List<Annotation> l = repositoy.get(annotation.getName());
+      return getAnnotation(annotation.getName());
+   }
+
+   /**
+    * Get the instances of an annotation
+    * @param annotation The fully qualified class name for the annotation
+    * @return The list of annotations of the specified class; <code>null</code>
+    *         if no annotations exists
+    */
+   public Collection<Annotation> getAnnotation(String annotation)
+   {
+      if (annotation == null)
+         throw new IllegalArgumentException("Annotation is null");
+
+      Collection<Annotation> l = repositoy.get(annotation);
       
       if (l == null)
          return null;
 
-      return Collections.unmodifiableList(l);
+      return Collections.unmodifiableCollection(l);
    }
 
    /**
@@ -91,7 +118,7 @@
    public int getSize()
    {
       int numberOfAnnotations = 0;
-      for (List<Annotation> l : repositoy.values())
+      for (Collection<Annotation> l : repositoy.values())
       {
          numberOfAnnotations += l.size();
       }
@@ -108,7 +135,7 @@
       if (annotation == null)
          throw new IllegalArgumentException("Annotation is null");
 
-      List<Annotation> l = repositoy.get(annotation.getName());
+      Collection<Annotation> l = repositoy.get(annotation.getName());
       
       if (l == null)
          return 0;

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -41,6 +41,7 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -81,7 +82,7 @@
     */
    public AnnotationRepository scan(URL[] urls, ClassLoader... cls)
    {
-      Map<String, List<Annotation>> result = new HashMap<String, List<Annotation>>();
+      Map<String, Collection<Annotation>> result = new HashMap<String, Collection<Annotation>>();
 
       long start = 0;
       if (log.isLoggable(Level.FINE))
@@ -210,6 +211,25 @@
                            }
                         }
                      }
+
+                     Class[] interfaces = clz.getInterfaces();
+                     if (interfaces != null)
+                     {
+                        for (Class interfaceClass : interfaces)
+                        {
+                           java.lang.annotation.Annotation[] interfaceAnnotations = interfaceClass.getAnnotations();
+                           if (interfaceAnnotations != null)
+                           {
+                              for (java.lang.annotation.Annotation annotation : interfaceAnnotations)
+                              {
+                                 processAnnotation(annotation, 
+                                                   AnnotationType.CLASS, 
+                                                   clz.getName(), null, null,
+                                                   result);
+                              }
+                           }
+                        }
+                     }
                   }
                }
                catch (Throwable t)
@@ -236,7 +256,7 @@
             long end = System.currentTimeMillis();
 
             int numberOfAnnotations = 0;
-            for (List<Annotation> l : result.values())
+            for (Collection<Annotation> l : result.values())
             {
                numberOfAnnotations += l.size();
             }
@@ -323,7 +343,7 @@
     */
    private void processAnnotation(java.lang.annotation.Annotation annotation, 
                                   AnnotationType type, String className, String memberName, String[] parameterTypes,
-                                  Map<String, List<Annotation>> map)
+                                  Map<String, Collection<Annotation>> map)
    {
       Class annotationClass = annotation.annotationType();
                         
@@ -335,7 +355,7 @@
          log.finest("Annotation=" + a);
 
       String key = annotationClass.getName();
-      List<Annotation> l = map.get(key);
+      Collection<Annotation> l = map.get(key);
       if (l == null)
          l = new ArrayList<Annotation>();
                         

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -37,6 +37,7 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -87,7 +88,7 @@
     */
    public AnnotationRepository scan(URL[] urls, ClassLoader... cls)
    {
-      Map<String, List<Annotation>> result = new HashMap<String, List<Annotation>>();
+      Map<String, Collection<Annotation>> result = new HashMap<String, Collection<Annotation>>();
 
       long start = 0;
       if (log.isLoggable(Level.FINE))
@@ -232,6 +233,28 @@
                            }
                         }
                      }
+
+                     // Interface annotations
+                     CtClass[] interfaces = ctClass.getInterfaces();
+                     if (interfaces != null)
+                     {
+                        for (CtClass interfaceClass : interfaces)
+                        {
+                           // Interface level annotations
+                           Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
+                        
+                           if (interfaceAnnotations != null)
+                           {
+                              for (Object annotation : interfaceAnnotations)
+                              {
+                                 processAnnotation(annotation, 
+                                                   AnnotationType.CLASS, 
+                                                   ctClass.getName(), null, null,
+                                                   result);
+                              }
+                           }
+                        }
+                     }
                   }
                }
                catch (NotFoundException nfe)
@@ -258,7 +281,7 @@
             long end = System.currentTimeMillis();
          
             int numberOfAnnotations = 0;
-            for (List<Annotation> l : result.values())
+            for (Collection<Annotation> l : result.values())
             {
                numberOfAnnotations += l.size();
             }
@@ -343,7 +366,7 @@
     */
    private void processAnnotation(Object annotation, 
                                   AnnotationType type, String className, String memberName, String[] parameterTypes,
-                                  Map<String, List<Annotation>> map)
+                                  Map<String, Collection<Annotation>> map)
    {
       Class annotationClass = annotation.getClass().getInterfaces()[0];
                         
@@ -355,7 +378,7 @@
          log.finest("Annotation=" + a);
 
       String key = annotationClass.getName();
-      List<Annotation> l = map.get(key);
+      Collection<Annotation> l = map.get(key);
       if (l == null)
          l = new ArrayList<Annotation>();
       

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -36,6 +36,7 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
@@ -88,7 +89,7 @@
     */
    public AnnotationRepository scan(URL[] urls, ClassLoader... cls)
    {
-      Map<String, List<Annotation>> result = new HashMap<String, List<Annotation>>();
+      Map<String, Collection<Annotation>> result = new HashMap<String, Collection<Annotation>>();
 
       long start = 0;
       if (log.isLoggable(Level.FINE))
@@ -257,6 +258,28 @@
                               }
                            }
                         }
+
+                        // Interface annotations
+                        CtClass[] interfaces = ctClass.getInterfaces();
+                        if (interfaces != null)
+                        {
+                           for (CtClass interfaceClass : interfaces)
+                           {
+                              // Interface level annotations
+                              Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
+                        
+                              if (interfaceAnnotations != null)
+                              {
+                                 for (Object annotation : interfaceAnnotations)
+                                 {
+                                    processAnnotation(annotation, 
+                                                      AnnotationType.CLASS, 
+                                                      ctClass.getName(), null, null,
+                                                      result);
+                                 }
+                              }
+                           }
+                        }
                      }
                   }
                }
@@ -287,7 +310,7 @@
          long end = System.currentTimeMillis();
 
          int numberOfAnnotations = 0;
-         for (List<Annotation> l : result.values())
+         for (Collection<Annotation> l : result.values())
          {
             numberOfAnnotations += l.size();
          }
@@ -312,7 +335,7 @@
     */
    private void processAnnotation(Object annotation, 
                                   AnnotationType type, String className, String memberName, String[] parameterTypes,
-                                  Map<String, List<Annotation>> map)
+                                  Map<String, Collection<Annotation>> map)
    {
       Class annotationClass = annotation.getClass().getInterfaces()[0];
                         
@@ -324,7 +347,7 @@
          log.finest("Annotation=" + a);
 
       String key = annotationClass.getName();
-      List<Annotation> l = map.get(key);
+      Collection<Annotation> l = map.get(key);
       if (l == null)
          l = new ArrayList<Annotation>();
       

Modified: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -30,8 +30,8 @@
 import org.jboss.annotations.test.tests.common.MyAnnotation;
 
 import java.net.URL;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
@@ -95,7 +95,7 @@
    @Test
    public void testConstructorStandard() throws Throwable
    {
-      Map<String, List<Annotation>> m = new HashMap<String, List<Annotation>>();
+      Map<String, Collection<Annotation>> m = new HashMap<String, Collection<Annotation>>();
 
       AnnotationRepositoryImpl ar = new AnnotationRepositoryImpl(m);
       assertNotNull(ar);
@@ -117,11 +117,11 @@
    }
 
    /**
-    * HasAnnotation null
+    * HasAnnotation null (Class)
     * @throws Throwable throwable exception 
     */
    @Test
-   public void testHasAnnotatitionNull() throws Throwable
+   public void testHasAnnotatitionClassNull() throws Throwable
    {
       URL archive = getURL("classlevel.jar");
       AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
@@ -130,7 +130,7 @@
 
       try
       {
-         ar.hasAnnotation(null);
+         ar.hasAnnotation((Class)null);
          fail("Operation success");
       }
       catch (Throwable t)
@@ -140,11 +140,11 @@
    }
 
    /**
-    * GetAnnotation null
+    * HasAnnotation null (String)
     * @throws Throwable throwable exception 
     */
    @Test
-   public void testGetAnnotatitionNull() throws Throwable
+   public void testHasAnnotatitionStringNull() throws Throwable
    {
       URL archive = getURL("classlevel.jar");
       AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
@@ -153,7 +153,7 @@
 
       try
       {
-         List<Annotation> l = ar.getAnnotation(null);
+         ar.hasAnnotation((String)null);
          fail("Operation success");
       }
       catch (Throwable t)
@@ -163,6 +163,52 @@
    }
 
    /**
+    * GetAnnotation null (Class)
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testGetAnnotatitionClassNull() throws Throwable
+   {
+      URL archive = getURL("classlevel.jar");
+      AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
+
+      assertNotNull(ar);
+
+      try
+      {
+         Collection<Annotation> l = ar.getAnnotation((Class)null);
+         fail("Operation success");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+   }
+
+   /**
+    * GetAnnotation null (String)
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testGetAnnotatitionStringNull() throws Throwable
+   {
+      URL archive = getURL("classlevel.jar");
+      AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
+
+      assertNotNull(ar);
+
+      try
+      {
+         Collection<Annotation> l = ar.getAnnotation((String)null);
+         fail("Operation success");
+      }
+      catch (Throwable t)
+      {
+         // Ok
+      }
+   }
+
+   /**
     * Size null
     * @throws Throwable throwable exception 
     */
@@ -217,7 +263,7 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);

Modified: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/ClassTests.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -29,7 +29,7 @@
 import org.jboss.annotations.test.tests.common.MyAnnotation;
 
 import java.net.URL;
-import java.util.List;
+import java.util.Collection;
 import java.util.logging.Logger;
 
 import org.junit.Test;
@@ -81,7 +81,7 @@
 
       assertFalse(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
       assertNull(l);
    }
 
@@ -99,7 +99,7 @@
 
       assertFalse(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNull(l);
    }
@@ -118,12 +118,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.CLASS);
       assertEquals("org.jboss.annotations.test.tests.classlevel.Test", annotation.getClassName());
@@ -145,12 +145,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.CONSTRUCTOR);
       assertEquals("org.jboss.annotations.test.tests.classconstructor.Test", annotation.getClassName());
@@ -172,12 +172,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.CONSTRUCTOR);
       assertEquals("org.jboss.annotations.test.tests.classconstructorwithparameter.Test", annotation.getClassName());
@@ -199,12 +199,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.METHOD);
       assertEquals("org.jboss.annotations.test.tests.classmethod.Test", annotation.getClassName());
@@ -226,12 +226,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.METHOD);
       assertEquals("org.jboss.annotations.test.tests.classmethodwithparameter.Test", annotation.getClassName());
@@ -253,16 +253,59 @@
 
       assertTrue(ar.hasAnnotation(MyAnnotation.class));
 
-      List<Annotation> l = ar.getAnnotation(MyAnnotation.class);
+      Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.FIELD);
       assertEquals("org.jboss.annotations.test.tests.classfield.Test", annotation.getClassName());
       assertEquals("myField", annotation.getMemberName());
       assertNull(annotation.getParameterTypes());
    }
+
+   /**
+    * Class interface
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testClassInterface() throws Throwable
+   {
+      URL archive = getURL("classinterface.jar");
+      AnnotationRepository ar = scanner.scan(new URL[] {archive});
+
+      assertNotNull(ar);
+
+      assertTrue(ar.hasAnnotation(Deprecated.class));
+
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
+
+      assertNotNull(l);
+      assertTrue(l.size() == 2);
+
+      for (Annotation annotation : l)
+      {
+         if ("org.jboss.annotations.test.tests.classinterface.Test".equals(annotation.getClassName()))
+         {
+            assertNotNull(annotation.getAnnotation());
+            assertTrue(annotation.getType() == AnnotationType.CLASS);
+            assertNull(annotation.getMemberName());
+            assertNull(annotation.getParameterTypes());
+         }
+         else if ("org.jboss.annotations.test.tests.classinterface.ITest".equals(annotation.getClassName()))
+         {
+            assertNotNull(annotation.getAnnotation());
+            assertTrue(annotation.getType() == AnnotationType.CLASS);
+            assertNull(annotation.getMemberName());
+            assertNull(annotation.getParameterTypes());
+         }
+         else
+         {
+            fail("Unknown annotation location");
+         }
+      }
+   }
+
 }

Modified: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/InterfaceTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/InterfaceTests.java	2009-08-11 12:59:46 UTC (rev 92228)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/InterfaceTests.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -28,7 +28,7 @@
 import org.jboss.annotations.AnnotationType;
 
 import java.net.URL;
-import java.util.List;
+import java.util.Collection;
 import java.util.logging.Logger;
 
 import org.junit.Test;
@@ -80,7 +80,7 @@
 
       assertFalse(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
       assertNull(l);
    }
 
@@ -98,12 +98,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.CLASS);
       assertEquals("org.jboss.annotations.test.tests.interfacelevel.Test", annotation.getClassName());
@@ -125,12 +125,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.METHOD);
       assertEquals("org.jboss.annotations.test.tests.interfacemethod.Test", annotation.getClassName());
@@ -152,12 +152,12 @@
 
       assertTrue(ar.hasAnnotation(Deprecated.class));
 
-      List<Annotation> l = ar.getAnnotation(Deprecated.class);
+      Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
 
       assertNotNull(l);
       assertTrue(l.size() == 1);
 
-      Annotation annotation = l.get(0);
+      Annotation annotation = l.iterator().next();
       assertNotNull(annotation.getAnnotation());
       assertTrue(annotation.getType() == AnnotationType.METHOD);
       assertEquals("org.jboss.annotations.test.tests.interfacemethodwithparameter.Test", annotation.getClassName());

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/ITest.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/ITest.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/ITest.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.annotations.test.tests.classinterface;
+
+/**
+ * Test
+ */
+ at Deprecated
+public interface ITest
+{
+}

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/Test.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/Test.java	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/Test.java	2009-08-11 13:39:56 UTC (rev 92229)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.annotations.test.tests.classinterface;
+
+/**
+ * Test
+ */
+public class Test implements ITest
+{
+}

Added: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/package.html
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/package.html	                        (rev 0)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/tests/classinterface/package.html	2009-08-11 13:39:56 UTC (rev 92229)
@@ -0,0 +1,3 @@
+<body>
+A class with a class level annotation
+</body>




More information about the jboss-cvs-commits mailing list