public class AnnotationUtil extends Object
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Constructor and Description |
---|
AnnotationUtil() |
Modifier and Type | Method and Description |
---|---|
static Pair<Object,Field> |
getAnnotatedField(Object object,
Class<? extends Annotation> annotationClass,
String name)
Searches the [searchClass] for a field with the name [name] that is
marked by the annotation [annotationClass].
|
static List<Field> |
getAnnotatedFields(Class<?> searchClass,
Class<? extends Annotation> annotationClass)
Returns a list of all fields in [searchClass] marked with an annotation
[annotationClass].
|
static <Anno extends Annotation> |
getAnnotation(Field field,
Class<Anno> annotationClass)
Retrieves an annotation that is an instance of a specified annotation class.
|
static <Anno extends Annotation> |
getAnnotation(Method method,
Class<Anno> annotationClass)
Retrieves an annotation that is an instance of a specified annotation class.
|
public static Pair<Object,Field> getAnnotatedField(Object object, Class<? extends Annotation> annotationClass, String name) throws IllegalArgumentException, IllegalAccessException
public class X (@)CasaOptions int y; } public class Z { (@)CasaOptions(recurse=true) X x; }you can search for the y field in Z by calling getAnnotatedField(new Z(), CasaOptions.class, "x.y").
object
- The object who's class to search for the field nameannotationClass
- Only fields marked with annoation are searchedname
- The name of the fieldIllegalArgumentException
- This actually shouldn't be thrownIllegalAccessException
- If the field is found, but it's not accessiblepublic static List<Field> getAnnotatedFields(Class<?> searchClass, Class<? extends Annotation> annotationClass)
searchClass
- The object who's type is to be searched for the annotation.annotationClass
- The annotation to search forpublic static <Anno extends Annotation> Anno getAnnotation(Field field, Class<Anno> annotationClass)
Anno
- The annotation type to retrievefield
- the field to read for annotationsannotationClass
- The class object of the annotation type to retrievepublic static <Anno extends Annotation> Anno getAnnotation(Method method, Class<Anno> annotationClass)
Anno
- The annotation type to retrievemethod
- the method to read for annotationsannotationClass
- The class object of the annotation type to retrieve