You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by db...@apache.org on 2012/06/06 03:08:10 UTC
svn commit: r1346692 - in
/commons/sandbox/classscan/branches/commons-finder: ResourceFinder.mdtext
src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
src/main/java/org/apache/commons/classscan/finder/model/
Author: dblevins
Date: Wed Jun 6 01:08:09 2012
New Revision: 1346692
URL: http://svn.apache.org/viewvc?rev=1346692&view=rev
Log:
Step towards making the internal Info objects static so they can be promoted to top level for listener api
Removed:
commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/
Modified:
commons/sandbox/classscan/branches/commons-finder/ResourceFinder.mdtext
commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
Modified: commons/sandbox/classscan/branches/commons-finder/ResourceFinder.mdtext
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/ResourceFinder.mdtext?rev=1346692&r1=1346691&r2=1346692&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/ResourceFinder.mdtext (original)
+++ commons/sandbox/classscan/branches/commons-finder/ResourceFinder.mdtext Wed Jun 6 01:08:09 2012
@@ -9,7 +9,7 @@ Taken from a StackOverflow answer on how
# ResourceFinder
-* [ResourceFinder][1] is a self-contained java file capable of replacing ServiceLoader usage as well as `classLoader.getResource()` calls.
+* ResourceFinder is a self-contained java file capable of replacing ServiceLoader usage as well as `classLoader.getResource()` calls.
Before our attention spans get too short, here's how it can replace a `ServiceLoader`
Modified: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java?rev=1346692&r1=1346691&r2=1346692&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java (original)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java Wed Jun 6 01:08:09 2012
@@ -504,7 +504,7 @@ public class AnnotationFinder implements
classes.add(clazz);
}
- final String meta = info.getMetaAnnotationName();
+ final String meta = getMetaAnnotationName(info);
if (meta != null) {
classes.addAll(findMetaAnnotatedClasses((Class<? extends Annotation>) clazz, classes));
}
@@ -516,6 +516,42 @@ public class AnnotationFinder implements
return classes;
}
+ private String getMetaAnnotationName(Info info) {
+ if (info instanceof ClassInfo) {
+ ClassInfo classInfo = (ClassInfo) info;
+ return getMetaAnnotationName(classInfo);
+ }
+
+ if (info instanceof FieldInfo) {
+ FieldInfo fieldInfo = (FieldInfo) info;
+ return getMetaAnnotationName(fieldInfo.getDeclaringClass());
+ }
+
+ if (info instanceof MethodInfo) {
+ MethodInfo methodInfo = (MethodInfo) info;
+ return getMetaAnnotationName(methodInfo.getDeclaringClass());
+ }
+
+ return null;
+ }
+
+ private String getMetaAnnotationName(ClassInfo classInfo) {
+ for (AnnotationInfo info : classInfo.getAnnotations()) {
+ for (Class<? extends Annotation> metaroot : metaroots) {
+ if (info.getName().equals(metaroot.getName())) return classInfo.getName();
+ }
+ }
+
+ if (classInfo.getName().endsWith("$$")) {
+ final ClassInfo info = classInfos.get(classInfo.getName().substring(0, classInfo.getName().length() - 2));
+ if (info != null) {
+ return getMetaAnnotationName(info);
+ }
+ }
+
+ return null;
+ }
+
/**
* Naive implementation - works extremelly slow O(n^3)
*
@@ -622,7 +658,7 @@ public class AnnotationFinder implements
for (Info info : infos) {
- final String meta = info.getMetaAnnotationName();
+ final String meta = getMetaAnnotationName(info);
if (meta != null) {
if (meta.equals(annotation.getName())) continue;
if (!seen.add(meta)) continue;
@@ -681,7 +717,7 @@ public class AnnotationFinder implements
for (Info info : infos) {
- final String meta = info.getMetaAnnotationName();
+ final String meta = getMetaAnnotationName(info);
if (meta != null) {
if (meta.equals(annotation.getName())) continue;
if (!seen.add(meta)) continue;
@@ -1144,20 +1180,7 @@ public class AnnotationFinder implements
@Override
public String getMetaAnnotationName() {
- for (AnnotationInfo info : getAnnotations()) {
- for (Class<? extends Annotation> metaroot : metaroots) {
- if (info.getName().equals(metaroot.getName())) return name;
- }
- }
-
- if (name.endsWith("$$")) {
- final ClassInfo info = classInfos.get(name.substring(0, name.length() - 2));
- if (info != null) {
- return info.getMetaAnnotationName();
- }
- }
-
- return null;
+ return AnnotationFinder.this.getMetaAnnotationName(this);
}
public String getPackageName() {