public class AnnotationUtil
extends java.lang.Object
Provides utility methods to deal with annotations.
| Constructor and Description |
|---|
AnnotationUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends java.lang.annotation.Annotation> |
createAnnotation(java.lang.Class<T> clazz)
Create an annotation instance from annotation class.
|
static <T extends java.lang.annotation.Annotation> |
declaredAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<T> annoClass)
Return declared annotation with type
annoClass from an AnnotatedElement. |
static int |
hashCode(java.lang.annotation.Annotation a)
Generate a hash code for the given annotation using the algorithm presented in the
Annotation.hashCode() API docs. |
static int |
hashMember(java.lang.String name,
java.lang.Object value)
Helper method for generating a hash code for a member of an annotation.
|
static <T extends java.lang.annotation.Annotation> |
tagAnnotation(java.lang.annotation.Annotation annotation,
java.lang.Class<T> tagClass)
Returns the
Annotation tagged on another annotation instance. |
public static <T extends java.lang.annotation.Annotation> T declaredAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<T> annoClass)
Return declared annotation with type annoClass from an AnnotatedElement.
T - the generic type of the annotation classannotatedElement - the annotated element (could be class, method or field)annoClass - the annotation classnull if not foundpublic static <T extends java.lang.annotation.Annotation> T tagAnnotation(java.lang.annotation.Annotation annotation,
java.lang.Class<T> tagClass)
Returns the Annotation tagged on another annotation instance.
T - the generic type of the expected annotationannotation - the annotation instancetagClass - the expected annotation classtagClasspublic static <T extends java.lang.annotation.Annotation> T createAnnotation(java.lang.Class<T> clazz)
Create an annotation instance from annotation class.
T - the generic type of the annoationclazz - the annotation classpublic static int hashCode(java.lang.annotation.Annotation a)
Generate a hash code for the given annotation using the algorithm presented in the Annotation.hashCode() API docs.
a - the Annotation for a hash code calculation is desired, not nulljava.lang.RuntimeException - if an Exception is encountered during annotation member accessjava.lang.IllegalStateException - if an annotation method invocation returns nullpublic static int hashMember(java.lang.String name,
java.lang.Object value)
Helper method for generating a hash code for a member of an annotation.
name - the name of the membervalue - the value of the memberCopyright © 2016–2017 OSGL (Open Source General Library). All rights reserved.