geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r729546 - in /geronimo/xbean/trunk/xbean-finder/src: main/java/org/apache/xbean/finder/ClassFinder.java test/java/org/acme/foo/FamilyHalloween.java test/java/org/acme/foo/Holiday.java test/java/org/apache/xbean/finder/ClassFinderTest.java
Date Fri, 26 Dec 2008 22:20:46 GMT
Author: jlaskowski
Date: Fri Dec 26 14:20:45 2008
New Revision: 729546

URL: http://svn.apache.org/viewvc?rev=729546&view=rev
Log:
XBEAN-120 Search for semi-annotated classes in inheritance tree (as if @Inherited's applied)

Added:
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/FamilyHalloween.java
Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/Holiday.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/ClassFinderTest.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java?rev=729546&r1=729545&r2=729546&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
Fri Dec 26 14:20:45 2008
@@ -245,6 +245,28 @@
         return classes;
     }
 
+    public List<Class> findInheritedAnnotatedClasses(Class<? extends Annotation>
annotation) {
+        classesNotLoaded.clear();
+        List<Class> classes = new ArrayList<Class>();
+        for (ClassInfo classInfo : classInfos) {
+            try {
+                Class clazz = classInfo.get();
+                do {
+                    if (clazz.isAnnotationPresent(annotation)) {
+                        classes.add(classInfo.get());
+                        break;
+                    }
+                    clazz = clazz.getSuperclass();
+                } while (clazz != null && clazz != Object.class);
+            } catch (ClassNotFoundException e) {
+                classesNotLoaded.add(classInfo.getName());
+            } catch (NoClassDefFoundError e) {
+                classesNotLoaded.add(classInfo.getName());
+            }
+        }
+        return classes;
+    }
+
     public List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation)
{
         classesNotLoaded.clear();
         List<ClassInfo> seen = new ArrayList<ClassInfo>();

Added: geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/FamilyHalloween.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/FamilyHalloween.java?rev=729546&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/FamilyHalloween.java (added)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/FamilyHalloween.java Fri
Dec 26 14:20:45 2008
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.acme.foo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FamilyHalloween extends Halloween {
+}

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/Holiday.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/Holiday.java?rev=729546&r1=729545&r2=729546&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/Holiday.java (original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/acme/foo/Holiday.java Fri Dec 26 14:20:45
2008
@@ -16,10 +16,14 @@
  */
 package org.acme.foo;
 
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
 /**
  * @version $Revision$ $Date$
  */
-@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE})
-@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
+@Target(value = {java.lang.annotation.ElementType.TYPE})
+@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
 public @interface Holiday {
 }

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/ClassFinderTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/ClassFinderTest.java?rev=729546&r1=729545&r2=729546&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/ClassFinderTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/ClassFinderTest.java
Fri Dec 26 14:20:45 2008
@@ -25,15 +25,16 @@
 import org.acme.bar.FullyAnnotated;
 import org.acme.foo.Blue;
 import org.acme.foo.Color;
+import org.acme.foo.Deployable;
+import org.acme.foo.FamilyHalloween;
 import org.acme.foo.Green;
 import org.acme.foo.Halloween;
 import org.acme.foo.Holiday;
+import org.acme.foo.Primary;
+import org.acme.foo.Property;
 import org.acme.foo.Red;
 import org.acme.foo.Thanksgiving;
 import org.acme.foo.ValentinesDay;
-import org.acme.foo.Deployable;
-import org.acme.foo.Primary;
-import org.acme.foo.Property;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Constructor;
@@ -101,6 +102,26 @@
         }
     }
 
+    public void testFindInheritedAnnotatedClassesInherited() throws Exception {
+        Class[] expected = {FamilyHalloween.class, Halloween.class, Thanksgiving.class, ValentinesDay.class};
+        List<Class> actual = classFinder.findInheritedAnnotatedClasses(Holiday.class);
+
+        assertNotNull(actual);
+        assertEquals(expected.length, actual.size());
+        for (Class clazz : expected) {
+            assertTrue(clazz.getName(), actual.contains(clazz));
+        }
+
+        expected = new Class[]{Halloween.class, Thanksgiving.class, ValentinesDay.class};
+        actual = classFinder.findAnnotatedClasses(Holiday.class);
+        assertNotNull(actual);
+        assertEquals(expected.length, actual.size());
+        for (Class clazz : expected) {
+            assertTrue(clazz.getName(), actual.contains(clazz));
+        }
+
+    }
+
     public void testFindAnnotatedMethods() throws Exception {
         List<Method> methods = classFinder.findAnnotatedMethods(Get.class);
         assertNotNull("methods", methods);



Mime
View raw message