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: 1881759 $ $Date: 2020-09-16 10:29:43 +0200 (Wed, 16 Sep 2020) $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
class
class
class
static interface
class
class
class
class
class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
protected final Map<String,
List<AnnotationFinder.Info>> private final Archive
private static final int
private final boolean
protected final Map<String,
AnnotationFinder.ClassInfo> private boolean
private final Set<Class<? extends Annotation>>
protected final Map<String,
AnnotationFinder.ClassInfo> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
AnnotationFinder
(AnnotationFinder parent, Iterable<String> classNames) AnnotationFinder
(Archive archive) AnnotationFinder
(Archive archive, boolean checkRuntimeAnnotation) -
Method Summary
Modifier and TypeMethodDescription_findSubclasses
(Class<T> clazz) protected boolean
private 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> void
findSubclasses
(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.boolean
private boolean
private void
index
(List<? extends AnnotationFinder.Info> infos) private void
index
(AnnotationFinder.AnnotationInfo annotationInfo, AnnotationFinder.Info info) private void
protected List<AnnotationFinder.Info>
initAnnotationInfos
(String name) boolean
isAnnotationPresent
(Class<? extends Annotation> annotation) protected boolean
private static boolean
isMetaAnnotation
(Class<? extends Annotation> clazz) private boolean
isMetaRoot
(AnnotationFinder.ClassInfo classInfo) private static boolean
isMetatypeAnnotation
(Class<? extends Annotation> type) private static boolean
isSelfAnnotated
(Class<? extends Annotation> type, String name) private boolean
isSelfAnnotated
(AnnotationFinder.ClassInfo classInfo, String metatype) protected boolean
link()
The link() method must be called to successfully use the findSubclasses and findImplementations methodsprotected void
linkInterfaces
(AnnotationFinder.ClassInfo classInfo) private void
protected void
linkParent
(AnnotationFinder.ClassInfo classInfo) protected Map<String,
List<AnnotationFinder.Info>> protected Map<String,
AnnotationFinder.ClassInfo> protected void
readClassDef
(Class clazz) protected void
readClassDef
(String className) protected void
readClassDef
(String className, InputStream in) private void
private void
resolveAnnotations
(List<String> scanned) Used to support meta annotationsprivate void
resolveAnnotations
(AnnotationFinder parent, List<String> scanned) private static boolean
validTarget
(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:
getAnnotatedClassNames
in 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:
ClassNotFoundException
IOException
-
linkMetaAnnotations
private void linkMetaAnnotations() -
isMetaRoot
-
isSelfAnnotated
-
hasName
-
linkParent
-
isJvm
-
linkInterfaces
-
isAnnotationPresent
- Specified by:
isAnnotationPresent
in 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:
getClassesNotLoaded
in interfaceIAnnotationFinder
- Returns:
- an unmodifiable live view of classes that could not be loaded in previous findAnnotated* call.
-
findAnnotatedPackages
- Specified by:
findAnnotatedPackages
in interfaceIAnnotationFinder
-
findAnnotatedClasses
- Specified by:
findAnnotatedClasses
in interfaceIAnnotationFinder
-
findMetaAnnotatedClasses
- Specified by:
findMetaAnnotatedClasses
in interfaceIAnnotationFinder
-
isMetaAnnotation
-
isMetatypeAnnotation
-
isSelfAnnotated
-
validTarget
-
findMetaAnnotatedClasses
-
findInheritedAnnotatedClasses
Naive implementation - works extremelly slow O(n^3)- Specified by:
findInheritedAnnotatedClasses
in interfaceIAnnotationFinder
- Parameters:
annotation
-- Returns:
- list of directly or indirectly (inherited) annotated classes
-
findAnnotatedMethods
- Specified by:
findAnnotatedMethods
in interfaceIAnnotationFinder
-
findAnnotatedMethodParameters
public List<Parameter<Method>> findAnnotatedMethodParameters(Class<? extends Annotation> annotation) -
findMetaAnnotatedMethods
- Specified by:
findMetaAnnotatedMethods
in interfaceIAnnotationFinder
-
findMetaAnnotatedMethods
-
findMetaAnnotatedFields
- Specified by:
findMetaAnnotatedFields
in interfaceIAnnotationFinder
-
findMetaAnnotatedFields
-
findAnnotatedConstructors
- Specified by:
findAnnotatedConstructors
in interfaceIAnnotationFinder
-
findAnnotatedConstructorParameters
public List<Parameter<Constructor<?>>> findAnnotatedConstructorParameters(Class<? extends Annotation> annotation) -
findAnnotatedFields
- Specified by:
findAnnotatedFields
in interfaceIAnnotationFinder
-
findClassesInPackage
- Specified by:
findClassesInPackage
in interfaceIAnnotationFinder
-
findSubclasses
- Specified by:
findSubclasses
in interfaceIAnnotationFinder
-
findSubclasses
private <T> void findSubclasses(AnnotationFinder.ClassInfo classInfo, List<Class<? extends T>> found, Class<T> clazz) -
_findSubclasses
-
findImplementations
- Specified by:
findImplementations
in interfaceIAnnotationFinder
-
collectImplementations
-
getAnnotationInfos
-
initAnnotationInfos
-
readClassDef
-
readClassDef
- Throws:
IOException
-
readClassDef
-
select
-
select
-
select
-
index
-