Package org.apache.xbean.finder
Class AnnotationFinder
java.lang.Object
org.apache.xbean.finder.AnnotationFinder
- All Implemented Interfaces:
IAnnotationFinder
ClassFinder searches the classpath of the specified classloader for
packages, classes, constructors, methods, or fields with specific annotations.
For security reasons ASM is used to find the annotations. Classes are not
loaded unless they match the requirements of a called findAnnotated* method.
Once loaded, these classes are cached.
- Version:
- $Rev$ $Date$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassclassclassstatic interfaceclassclassclassclassclass -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprotected final Map<String, List<AnnotationFinder.Info>> private final Archiveprivate static final intprivate final booleanprotected final Map<String, AnnotationFinder.ClassInfo> private booleanprivate final Set<Class<? extends Annotation>> protected final Map<String, AnnotationFinder.ClassInfo> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateAnnotationFinder(AnnotationFinder parent, Iterable<String> classNames) AnnotationFinder(Archive archive) AnnotationFinder(Archive archive, boolean checkRuntimeAnnotation) -
Method Summary
Modifier and TypeMethodDescription_findSubclasses(Class<T> clazz) protected booleanprivate List<AnnotationFinder.ClassInfo> collectImplementations(String interfaceName) findAnnotatedClasses(Class<? extends Annotation> annotation) List<Parameter<Constructor<?>>> findAnnotatedConstructorParameters(Class<? extends Annotation> annotation) findAnnotatedConstructors(Class<? extends Annotation> annotation) findAnnotatedFields(Class<? extends Annotation> annotation) findAnnotatedMethodParameters(Class<? extends Annotation> annotation) findAnnotatedMethods(Class<? extends Annotation> annotation) findAnnotatedPackages(Class<? extends Annotation> annotation) findClassesInPackage(String packageName, boolean recursive) findImplementations(Class<T> clazz) findInheritedAnnotatedClasses(Class<? extends Annotation> annotation) Naive implementation - works extremelly slow O(n^3)findMetaAnnotatedClasses(Class<? extends Annotation> annotation) findMetaAnnotatedClasses(Class<? extends Annotation> annotation, Set<Class<?>> classes) findMetaAnnotatedFields(Class<? extends Annotation> annotation) findMetaAnnotatedFields(Class<? extends Annotation> annotation, Set<Field> fields, Set<String> seen) findMetaAnnotatedMethods(Class<? extends Annotation> annotation) findMetaAnnotatedMethods(Class<? extends Annotation> annotation, Set<Method> methods, Set<String> seen) findSubclasses(Class<T> clazz) private <T> voidfindSubclasses(AnnotationFinder.ClassInfo classInfo, List<Class<? extends T>> found, Class<T> clazz) protected List<AnnotationFinder.Info> getAnnotationInfos(String name) Returns a list of classes that could not be loaded in last invoked findAnnotated* method.booleanprivate booleanprivate voidindex(List<? extends AnnotationFinder.Info> infos) private voidindex(AnnotationFinder.AnnotationInfo annotationInfo, AnnotationFinder.Info info) private voidprotected List<AnnotationFinder.Info> initAnnotationInfos(String name) booleanisAnnotationPresent(Class<? extends Annotation> annotation) protected booleanprivate static booleanisMetaAnnotation(Class<? extends Annotation> clazz) private booleanisMetaRoot(AnnotationFinder.ClassInfo classInfo) private static booleanisMetatypeAnnotation(Class<? extends Annotation> type) private static booleanisSelfAnnotated(Class<? extends Annotation> type, String name) private booleanisSelfAnnotated(AnnotationFinder.ClassInfo classInfo, String metatype) protected booleanlink()The link() method must be called to successfully use the findSubclasses and findImplementations methodsprotected voidlinkInterfaces(AnnotationFinder.ClassInfo classInfo) private voidprotected voidlinkParent(AnnotationFinder.ClassInfo classInfo) protected Map<String, List<AnnotationFinder.Info>> protected Map<String, AnnotationFinder.ClassInfo> protected voidreadClassDef(Class clazz) protected voidreadClassDef(String className) protected voidreadClassDef(String className, InputStream in) private voidprivate voidresolveAnnotations(List<String> scanned) Used to support meta annotationsprivate voidresolveAnnotations(AnnotationFinder parent, List<String> scanned) private static booleanvalidTarget(Class<? extends Annotation> type)
-
Field Details
-
ASM_FLAGS
private static final int ASM_FLAGS- See Also:
-
ALLOW_LAZY_LINKING
private static final boolean ALLOW_LAZY_LINKING -
metaroots
-
annotated
-
classInfos
-
originalInfos
-
classesNotLoaded
-
archive
-
checkRuntimeAnnotation
private final boolean checkRuntimeAnnotation -
linking
private volatile boolean linking
-
-
Constructor Details
-
AnnotationFinder
-
AnnotationFinder
- Parameters:
archive-checkRuntimeAnnotation- Has no effect on findMetaAnnotated* methods
-
AnnotationFinder
-
-
Method Details
-
newAnnotatedMap
-
newClassInfoMap
-
cleanOnNaked
protected boolean cleanOnNaked() -
isTracked
-
hasMetaAnnotations
public boolean hasMetaAnnotations() -
readClassDef
-
resolveAnnotations
-
index
-
index
-
getAnnotatedClassNames
- Specified by:
getAnnotatedClassNamesin interfaceIAnnotationFinder
-
getArchive
-
link
The link() method must be called to successfully use the findSubclasses and findImplementations methods- Returns:
- Throws:
IOException
-
enableMetaAnnotations
-
enableFindImplementations
-
enableFindSubclasses
-
resolveAnnotations
Used to support meta annotations Once the list of classes has been read from the Archive, we iterate over all the annotations that are used by those classes and recursively resolve any annotations those annotations use.- Parameters:
scanned-- Throws:
ClassNotFoundExceptionIOException
-
linkMetaAnnotations
private void linkMetaAnnotations() -
isMetaRoot
-
isSelfAnnotated
-
hasName
-
linkParent
-
isJvm
-
linkInterfaces
-
isAnnotationPresent
- Specified by:
isAnnotationPresentin interfaceIAnnotationFinder
-
getClassesNotLoaded
Returns a list of classes that could not be loaded in last invoked findAnnotated* method. The list will only contain entries of classes whose byte code matched the requirements of last invoked find* method, but were unable to be loaded and included in the results. The list returned is unmodifiable. Once obtained, the returned list will be a live view of the results from the last findAnnotated* method call. This method is not thread safe.- Specified by:
getClassesNotLoadedin interfaceIAnnotationFinder- Returns:
- an unmodifiable live view of classes that could not be loaded in previous findAnnotated* call.
-
findAnnotatedPackages
- Specified by:
findAnnotatedPackagesin interfaceIAnnotationFinder
-
findAnnotatedClasses
- Specified by:
findAnnotatedClassesin interfaceIAnnotationFinder
-
findMetaAnnotatedClasses
- Specified by:
findMetaAnnotatedClassesin interfaceIAnnotationFinder
-
isMetaAnnotation
-
isMetatypeAnnotation
-
isSelfAnnotated
-
validTarget
-
findMetaAnnotatedClasses
-
findInheritedAnnotatedClasses
Naive implementation - works extremelly slow O(n^3)- Specified by:
findInheritedAnnotatedClassesin interfaceIAnnotationFinder- Parameters:
annotation-- Returns:
- list of directly or indirectly (inherited) annotated classes
-
findAnnotatedMethods
- Specified by:
findAnnotatedMethodsin interfaceIAnnotationFinder
-
findAnnotatedMethodParameters
public List<Parameter<Method>> findAnnotatedMethodParameters(Class<? extends Annotation> annotation) -
findMetaAnnotatedMethods
- Specified by:
findMetaAnnotatedMethodsin interfaceIAnnotationFinder
-
findMetaAnnotatedMethods
-
findMetaAnnotatedFields
- Specified by:
findMetaAnnotatedFieldsin interfaceIAnnotationFinder
-
findMetaAnnotatedFields
-
findAnnotatedConstructors
- Specified by:
findAnnotatedConstructorsin interfaceIAnnotationFinder
-
findAnnotatedConstructorParameters
public List<Parameter<Constructor<?>>> findAnnotatedConstructorParameters(Class<? extends Annotation> annotation) -
findAnnotatedFields
- Specified by:
findAnnotatedFieldsin interfaceIAnnotationFinder
-
findClassesInPackage
- Specified by:
findClassesInPackagein interfaceIAnnotationFinder
-
findSubclasses
- Specified by:
findSubclassesin interfaceIAnnotationFinder
-
findSubclasses
private <T> void findSubclasses(AnnotationFinder.ClassInfo classInfo, List<Class<? extends T>> found, Class<T> clazz) -
_findSubclasses
-
findImplementations
- Specified by:
findImplementationsin interfaceIAnnotationFinder
-
collectImplementations
-
getAnnotationInfos
-
initAnnotationInfos
-
readClassDef
-
readClassDef
- Throws:
IOException
-
readClassDef
-
select
-
select
-
select
-
index
-