You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by db...@apache.org on 2011/12/08 21:53:11 UTC
svn commit: r1212117 - in /geronimo/xbean/trunk/xbean-finder/src:
main/java/org/apache/xbean/finder/AnnotationFinder.java
test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java
Author: dblevins
Date: Thu Dec 8 20:53:11 2011
New Revision: 1212117
URL: http://svn.apache.org/viewvc?rev=1212117&view=rev
Log:
XBEAN-197: Alternate annotations can serve as @Metatype
Modified:
geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java
Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java?rev=1212117&r1=1212116&r2=1212117&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java (original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java Thu Dec 8 20:53:11 2011
@@ -35,6 +35,8 @@ import org.objectweb.asm.signature.Signa
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -121,6 +123,8 @@ public class AnnotationFinder implements
// diff new and old lists
resolveAnnotations(new ArrayList<String>());
+ linkMetaAnnotations();
+
return this;
}
@@ -136,7 +140,6 @@ public class AnnotationFinder implements
* @throws IOException
*/
private void resolveAnnotations(List<String> scanned) {
-
// Get a list of the annotations that exist before we start
final List<String> annotations = new ArrayList<String>(annotated.keySet());
@@ -145,6 +148,12 @@ public class AnnotationFinder implements
readClassDef(annotation);
}
+ // If the "annotated" list has grown, then we must scan those
+ if (annotated.keySet().size() != annotations.size()) {
+ resolveAnnotations(annotations);
+ }
+
+
// for (ClassInfo classInfo : classInfos.values()) {
// for (AnnotationInfo annotationInfo : classInfo.getAnnotations()) {
// for (AnnotationInfo info : annotationInfo.getAnnotations()) {
@@ -156,6 +165,9 @@ public class AnnotationFinder implements
// }
// }
// }
+ }
+
+ private void linkMetaAnnotations() {
for (ClassInfo classInfo : classInfos.values()) {
if (isMetaRoot(classInfo)) {
try {
@@ -172,17 +184,13 @@ public class AnnotationFinder implements
readClassDef(info.getName() + "$$");
}
}
-
- // If the "annotated" list has grown, then we must scan those
- if (annotated.keySet().size() != annotations.size()) {
- resolveAnnotations(annotations);
- }
}
private boolean isMetaRoot(ClassInfo classInfo) {
if (!classInfo.isAnnotation()) return false;
if (isSelfAnnotated(classInfo, "Metatype")) return true;
+ if (isSelfAnnotated(classInfo, "Metaroot")) return false;
for (AnnotationInfo annotationInfo : classInfo.getAnnotations()) {
final ClassInfo annotation = classInfos.get(annotationInfo.getName());
@@ -370,9 +378,28 @@ public class AnnotationFinder implements
}
private static boolean isMetatypeAnnotation(Class<? extends Annotation> type) {
- return type.getSimpleName().equals("Metatype") && type.isAnnotationPresent(type);
+ if (isSelfAnnotated(type, "Metatype")) return true;
+
+ for (Annotation annotation : type.getAnnotations()) {
+ if (isSelfAnnotated(annotation.annotationType(), "Metaroot")) return true;
+ }
+
+ return false;
}
+ private static boolean isSelfAnnotated(Class<? extends Annotation> type, String name) {
+ return type.isAnnotationPresent(type) && type.getSimpleName().equals(name) && validTarget(type);
+ }
+
+ private static boolean validTarget(Class<? extends Annotation> type) {
+ final Target target = type.getAnnotation(Target.class);
+
+ if (target == null) return false;
+
+ final ElementType[] targets = target.value();
+
+ return targets.length == 1 && targets[0] == ElementType.ANNOTATION_TYPE;
+ }
private Set<Class<?>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation, Set<Class<?>> classes) {
Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java?rev=1212117&r1=1212116&r2=1212117&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java (original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/RootMetaAnnotatedClassTest.java Thu Dec 8 20:53:11 2011
@@ -43,9 +43,6 @@ import static java.lang.annotation.Reten
public class RootMetaAnnotatedClassTest extends TestCase {
public void test() throws Exception {
-
- }
- public void _test() throws Exception {
AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Square.class, Circle.class, Triangle.class, Fake.class, Store.class, Farm.class, None.class)).link();
Map<Class<?>, Annotated<Class<?>>> map = new HashMap<Class<?>, Annotated<Class<?>>>();