Package org.apache.xbean.finder
Class AnnotationFinder
- java.lang.Object
-
- org.apache.xbean.finder.AnnotationFinder
-
- All Implemented Interfaces:
IAnnotationFinder
public class AnnotationFinder extends java.lang.Object implements 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: 1881759 $ $Date: 2020-09-16 10:29:43 +0200 (Wed, 16 Sep 2020) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAnnotationFinder.AnnotatableclassAnnotationFinder.AnnotationInfoclassAnnotationFinder.ClassInfoclassAnnotationFinder.FieldInfostatic interfaceAnnotationFinder.InfoclassAnnotationFinder.InfoBuildingVisitorclassAnnotationFinder.MethodInfoclassAnnotationFinder.PackageInfoclassAnnotationFinder.ParameterInfoclassAnnotationFinder.SubArchive
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.util.List<AnnotationFinder.Info>>annotatedprotected java.util.Map<java.lang.String,AnnotationFinder.ClassInfo>classInfosprotected java.util.Map<java.lang.String,AnnotationFinder.ClassInfo>originalInfos
-
Constructor Summary
Constructors Constructor Description AnnotationFinder(Archive archive)AnnotationFinder(Archive archive, boolean checkRuntimeAnnotation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancleanOnNaked()AnnotationFinderenableFindImplementations()AnnotationFinderenableFindSubclasses()AnnotationFinderenableMetaAnnotations()java.util.List<java.lang.Class<?>>findAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<Parameter<java.lang.reflect.Constructor<?>>>findAnnotatedConstructorParameters(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<java.lang.reflect.Constructor>findAnnotatedConstructors(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<java.lang.reflect.Field>findAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<Parameter<java.lang.reflect.Method>>findAnnotatedMethodParameters(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<java.lang.reflect.Method>findAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<java.lang.Package>findAnnotatedPackages(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<java.lang.Class<?>>findClassesInPackage(java.lang.String packageName, boolean recursive)<T> java.util.List<java.lang.Class<? extends T>>findImplementations(java.lang.Class<T> clazz)java.util.List<java.lang.Class<?>>findInheritedAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Naive implementation - works extremelly slow O(n^3)java.util.List<Annotated<java.lang.Class<?>>>findMetaAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<Annotated<java.lang.reflect.Field>>findMetaAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)java.util.List<Annotated<java.lang.reflect.Method>>findMetaAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)<T> java.util.List<java.lang.Class<? extends T>>findSubclasses(java.lang.Class<T> clazz)java.util.List<java.lang.String>getAnnotatedClassNames()protected java.util.List<AnnotationFinder.Info>getAnnotationInfos(java.lang.String name)ArchivegetArchive()java.util.List<java.lang.String>getClassesNotLoaded()Returns a list of classes that could not be loaded in last invoked findAnnotated* method.booleanhasMetaAnnotations()protected java.util.List<AnnotationFinder.Info>initAnnotationInfos(java.lang.String name)booleanisAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)protected booleanisJvm(java.lang.String name)protected booleanisTracked(java.lang.String annotationType)AnnotationFinderlink()The link() method must be called to successfully use the findSubclasses and findImplementations methodsprotected voidlinkInterfaces(AnnotationFinder.ClassInfo classInfo)protected voidlinkParent(AnnotationFinder.ClassInfo classInfo)protected java.util.Map<java.lang.String,java.util.List<AnnotationFinder.Info>>newAnnotatedMap()protected java.util.Map<java.lang.String,AnnotationFinder.ClassInfo>newClassInfoMap()protected voidreadClassDef(java.lang.Class clazz)protected voidreadClassDef(java.lang.String className)protected voidreadClassDef(java.lang.String className, java.io.InputStream in)AnnotationFinderselect(java.lang.Class<?>... clazz)AnnotationFinderselect(java.lang.Iterable<java.lang.String> clazz)AnnotationFinderselect(java.lang.String... clazz)
-
-
-
Field Detail
-
annotated
protected final java.util.Map<java.lang.String,java.util.List<AnnotationFinder.Info>> annotated
-
classInfos
protected final java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> classInfos
-
originalInfos
protected final java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> originalInfos
-
-
Constructor Detail
-
AnnotationFinder
public AnnotationFinder(Archive archive, boolean checkRuntimeAnnotation)
- Parameters:
archive-checkRuntimeAnnotation- Has no effect on findMetaAnnotated* methods
-
AnnotationFinder
public AnnotationFinder(Archive archive)
-
-
Method Detail
-
newAnnotatedMap
protected java.util.Map<java.lang.String,java.util.List<AnnotationFinder.Info>> newAnnotatedMap()
-
newClassInfoMap
protected java.util.Map<java.lang.String,AnnotationFinder.ClassInfo> newClassInfoMap()
-
cleanOnNaked
protected boolean cleanOnNaked()
-
isTracked
protected boolean isTracked(java.lang.String annotationType)
-
hasMetaAnnotations
public boolean hasMetaAnnotations()
-
getAnnotatedClassNames
public java.util.List<java.lang.String> getAnnotatedClassNames()
- Specified by:
getAnnotatedClassNamesin interfaceIAnnotationFinder
-
getArchive
public Archive getArchive()
-
link
public AnnotationFinder link()
The link() method must be called to successfully use the findSubclasses and findImplementations methods- Returns:
- Throws:
java.io.IOException
-
enableMetaAnnotations
public AnnotationFinder enableMetaAnnotations()
-
enableFindImplementations
public AnnotationFinder enableFindImplementations()
-
enableFindSubclasses
public AnnotationFinder enableFindSubclasses()
-
linkParent
protected void linkParent(AnnotationFinder.ClassInfo classInfo)
-
isJvm
protected boolean isJvm(java.lang.String name)
-
linkInterfaces
protected void linkInterfaces(AnnotationFinder.ClassInfo classInfo)
-
isAnnotationPresent
public boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
isAnnotationPresentin interfaceIAnnotationFinder
-
getClassesNotLoaded
public java.util.List<java.lang.String> 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
public java.util.List<java.lang.Package> findAnnotatedPackages(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findAnnotatedPackagesin interfaceIAnnotationFinder
-
findAnnotatedClasses
public java.util.List<java.lang.Class<?>> findAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findAnnotatedClassesin interfaceIAnnotationFinder
-
findMetaAnnotatedClasses
public java.util.List<Annotated<java.lang.Class<?>>> findMetaAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findMetaAnnotatedClassesin interfaceIAnnotationFinder
-
findInheritedAnnotatedClasses
public java.util.List<java.lang.Class<?>> findInheritedAnnotatedClasses(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Naive implementation - works extremelly slow O(n^3)- Specified by:
findInheritedAnnotatedClassesin interfaceIAnnotationFinder- Parameters:
annotation-- Returns:
- list of directly or indirectly (inherited) annotated classes
-
findAnnotatedMethods
public java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findAnnotatedMethodsin interfaceIAnnotationFinder
-
findAnnotatedMethodParameters
public java.util.List<Parameter<java.lang.reflect.Method>> findAnnotatedMethodParameters(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
findMetaAnnotatedMethods
public java.util.List<Annotated<java.lang.reflect.Method>> findMetaAnnotatedMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findMetaAnnotatedMethodsin interfaceIAnnotationFinder
-
findMetaAnnotatedFields
public java.util.List<Annotated<java.lang.reflect.Field>> findMetaAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findMetaAnnotatedFieldsin interfaceIAnnotationFinder
-
findAnnotatedConstructors
public java.util.List<java.lang.reflect.Constructor> findAnnotatedConstructors(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findAnnotatedConstructorsin interfaceIAnnotationFinder
-
findAnnotatedConstructorParameters
public java.util.List<Parameter<java.lang.reflect.Constructor<?>>> findAnnotatedConstructorParameters(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
findAnnotatedFields
public java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
- Specified by:
findAnnotatedFieldsin interfaceIAnnotationFinder
-
findClassesInPackage
public java.util.List<java.lang.Class<?>> findClassesInPackage(java.lang.String packageName, boolean recursive)
- Specified by:
findClassesInPackagein interfaceIAnnotationFinder
-
findSubclasses
public <T> java.util.List<java.lang.Class<? extends T>> findSubclasses(java.lang.Class<T> clazz)
- Specified by:
findSubclassesin interfaceIAnnotationFinder
-
findImplementations
public <T> java.util.List<java.lang.Class<? extends T>> findImplementations(java.lang.Class<T> clazz)
- Specified by:
findImplementationsin interfaceIAnnotationFinder
-
getAnnotationInfos
protected java.util.List<AnnotationFinder.Info> getAnnotationInfos(java.lang.String name)
-
initAnnotationInfos
protected java.util.List<AnnotationFinder.Info> initAnnotationInfos(java.lang.String name)
-
readClassDef
protected void readClassDef(java.lang.String className)
-
readClassDef
protected void readClassDef(java.lang.String className, java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
readClassDef
protected void readClassDef(java.lang.Class clazz)
-
select
public AnnotationFinder select(java.lang.Class<?>... clazz)
-
select
public AnnotationFinder select(java.lang.String... clazz)
-
select
public AnnotationFinder select(java.lang.Iterable<java.lang.String> clazz)
-
-