org.test4j.tools.commons
类 AnnotationHelper

java.lang.Object
  继承者 org.test4j.tools.commons.AnnotationHelper

public class AnnotationHelper
extends Object

Annotation工具类

作者:
darui.wudr

构造方法摘要
AnnotationHelper()
           
 
方法摘要
static
<T> T
getAnnotationPropertyValue(Method annotationProperty, Annotation annotation)
           
static
<T extends Annotation>
T
getClassLevelAnnotation(Class<T> annotationClass, Class clazz)
           
static
<S extends Annotation,T>
T
getClassLevelAnnotationProperty(Class<S> annotationClass, String annotationPropertyName, T defaultValue, Class clazz)
          获得class上annotation的属性值
static
<T extends Annotation>
Class
getClassWithAnnotation(Class<T> annotationClass, Class clazz)
           
static
<T extends Annotation>
Set<T>
getFieldLevelAnnotations(Class clazz, Class<T> annotation)
           
static
<T extends Annotation>
Set<Field>
getFieldsAnnotatedWith(Class<? extends Object> clazz, Class<T> annotation)
          Returns the given class's declared fields that are marked with the given annotation
static
<T extends Annotation>
Set<T>
getMethodLevelAnnotations(Class clazz, Class<T> annotation)
           
static
<T extends Annotation>
T
getMethodOrClassLevelAnnotation(Class<T> annotationClass, Method method, Class clazz)
           
static
<S extends Annotation,T>
T
getMethodOrClassLevelAnnotationProperty(Class<S> annotationClass, String annotationPropertyName, T defaultValue, Method method, Class clazz)
          获得方法或者class上annotation的属性值
static
<T extends Annotation>
Set<Method>
getMethodsAnnotatedWith(Class clazz, Class<T> annotation)
          Returns the given class's (and superclasses) declared methods that are marked with the given annotation
static
<T extends Annotation>
Set<Method>
getMethodsAnnotatedWith(Class clazz, Class<T> annotation, boolean includeInherited)
          Returns the given class's declared methods that are marked with the given annotation
static boolean hasClassMethodOrFieldLevelAnnotation(Class clazz, Class<? extends Annotation> annotation)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

AnnotationHelper

public AnnotationHelper()
方法详细信息

getFieldsAnnotatedWith

public static <T extends Annotation> Set<Field> getFieldsAnnotatedWith(Class<? extends Object> clazz,
                                                                       Class<T> annotation)
Returns the given class's declared fields that are marked with the given annotation

参数:
clazz - The class, not null
annotation - The annotation, not null
返回:
A List containing fields annotated with the given annotation, empty list if none found

getMethodsAnnotatedWith

public static <T extends Annotation> Set<Method> getMethodsAnnotatedWith(Class clazz,
                                                                         Class<T> annotation)
Returns the given class's (and superclasses) declared methods that are marked with the given annotation

参数:
clazz - The class, not null
annotation - The annotation, not null
返回:
A List containing methods annotated with the given annotation, empty list if none found

getMethodLevelAnnotations

public static <T extends Annotation> Set<T> getMethodLevelAnnotations(Class clazz,
                                                                      Class<T> annotation)

getFieldLevelAnnotations

public static <T extends Annotation> Set<T> getFieldLevelAnnotations(Class clazz,
                                                                     Class<T> annotation)

getMethodsAnnotatedWith

public static <T extends Annotation> Set<Method> getMethodsAnnotatedWith(Class clazz,
                                                                         Class<T> annotation,
                                                                         boolean includeInherited)
Returns the given class's declared methods that are marked with the given annotation

参数:
clazz - The class, not null
annotation - The annotation, not null
includeInherited - True for also looking for methods in super-classes
返回:
A List containing methods annotated with the given annotation, empty list if none found

getMethodOrClassLevelAnnotation

public static <T extends Annotation> T getMethodOrClassLevelAnnotation(Class<T> annotationClass,
                                                                       Method method,
                                                                       Class clazz)

getClassLevelAnnotation

public static <T extends Annotation> T getClassLevelAnnotation(Class<T> annotationClass,
                                                               Class clazz)

getClassWithAnnotation

public static <T extends Annotation> Class getClassWithAnnotation(Class<T> annotationClass,
                                                                  Class clazz)

getMethodOrClassLevelAnnotationProperty

public static <S extends Annotation,T> T getMethodOrClassLevelAnnotationProperty(Class<S> annotationClass,
                                                                                 String annotationPropertyName,
                                                                                 T defaultValue,
                                                                                 Method method,
                                                                                 Class clazz)
获得方法或者class上annotation的属性值

类型参数:
S -
T -
参数:
annotationClass - 要获取属性的Annotation class
annotationPropertyName - 要获取的属性值的属性名称
defaultValue - 属性的默认值
method - 要获取Annotation属性的方法
clazz - 要获取Annotation属性的类
返回:

getClassLevelAnnotationProperty

public static <S extends Annotation,T> T getClassLevelAnnotationProperty(Class<S> annotationClass,
                                                                         String annotationPropertyName,
                                                                         T defaultValue,
                                                                         Class clazz)
获得class上annotation的属性值

类型参数:
S -
T -
参数:
annotationClass - 要获取属性的Annotation class
annotationPropertyName - 要获取的属性值的属性名称
defaultValue - 要获取Annotation属性的方法
clazz - 要获取Annotation属性的类
返回:

getAnnotationPropertyValue

public static <T> T getAnnotationPropertyValue(Method annotationProperty,
                                               Annotation annotation)

hasClassMethodOrFieldLevelAnnotation

public static boolean hasClassMethodOrFieldLevelAnnotation(Class clazz,
                                                           Class<? extends Annotation> annotation)


Copyright © 2013. All rights reserved.