Package org.apache.webbeans.util
Class AnnotationUtil
- java.lang.Object
-
- org.apache.webbeans.util.AnnotationUtil
-
public final class AnnotationUtil extends Object
Utility class related withAnnotationoperations.- Since:
- 1.0
- Author:
- Gurkan Erdogdu
-
-
Field Summary
Fields Modifier and Type Field Description static Annotation[]DEFAULT_AND_ANY_ANNOTATION_ARRAYstatic Set<Annotation>DEFAULT_AND_ANY_ANNOTATION_SETstatic Annotation[]EMPTY_ANNOTATION_ARRAYstatic Object[]EMPTY_OBJECT_ARRAY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Annotation[]asArray(Collection<Annotation> set)static <T extends Annotation>
TgetAnnotation(Annotation[] anns, Class<T> annotation)get the annotation of the given type from the array.static <T extends Annotation>
TgetAnnotation(Set<Annotation> annotations, Class<T> annotationClass)Search in the given Set of Annotations for the one with the given AnnotationClass.static intgetCdiAnnotationHashCode(Annotation annotation)Computes a hash code for the specified cdi annoation. cdi annotations may either be qualifiers or interceptor bindings.static Class<?>getDeclaringClass(Annotation declaredAnnotation, Class<?> typeHierarchy)Returns the declaring class for the specified annotation, using the specified type hierarchy.static <X> jakarta.enterprise.inject.spi.AnnotatedParameter<X>getFirstAnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedMethod<X> annotatedMethod, Class<? extends Annotation> annotation)static Annotation[]getMetaAnnotations(Annotation[] anns, Class<? extends Annotation> metaAnnotation)Returns a subset of annotations that are annotated with the specified meta-annotationstatic <X> booleanhasAnnotatedMethodParameterAnnotation(jakarta.enterprise.inject.spi.AnnotatedMethod<X> annotatedMethod, Class<? extends Annotation> clazz)static booleanhasAnnotation(Annotation[] anns, Class<? extends Annotation> annotation)static booleanhasAnnotation(Set<Annotation> anns, Class<? extends Annotation> annotation)static booleanhasClassAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)Check whether or not class contains the given annotation.static booleanhasMetaAnnotation(Annotation[] anns, Class<? extends Annotation> metaAnnotation)static booleanhasMethodAnnotation(Method method, Class<? extends Annotation> clazz)Check given annotation exist on the method.static AnnotationhasOwbInjectableResource(Annotation[] annotations)static booleanisCdiAnnotationEqual(jakarta.enterprise.inject.spi.AnnotatedType<?> at, Annotation annotation1, Annotation annotation2)Checks if the given cdi annotations are equal. cdi annotations may either be qualifiers or interceptor bindings.static booleanisCdiAnnotationEqual(Annotation annotation1, Annotation annotation2)static booleanisDeclaringClass(Class<?> declaringClass, Annotation declaredAnnotation)Checks, if the given class declares the specified annotation
-
-
-
Field Detail
-
EMPTY_ANNOTATION_ARRAY
public static final Annotation[] EMPTY_ANNOTATION_ARRAY
-
EMPTY_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
-
DEFAULT_AND_ANY_ANNOTATION_ARRAY
public static final Annotation[] DEFAULT_AND_ANY_ANNOTATION_ARRAY
-
DEFAULT_AND_ANY_ANNOTATION_SET
public static final Set<Annotation> DEFAULT_AND_ANY_ANNOTATION_SET
-
-
Method Detail
-
isDeclaringClass
public static boolean isDeclaringClass(Class<?> declaringClass, Annotation declaredAnnotation)
Checks, if the given class declares the specified annotation
-
getDeclaringClass
public static Class<?> getDeclaringClass(Annotation declaredAnnotation, Class<?> typeHierarchy)
Returns the declaring class for the specified annotation, using the specified type hierarchy.
-
hasMethodAnnotation
public static boolean hasMethodAnnotation(Method method, Class<? extends Annotation> clazz)
Check given annotation exist on the method. Utility method to get around some errors caused by interactions between the Equinox class loaders and the OpenJPA transformation process. There is a window where the OpenJPA transformation process can cause an annotation being processed to get defined in a classloader during the actual defineClass call for that very class (e.g., recursively). This results in a LinkageError exception. If we see one of these, retry the request. Since the annotation will be defined on the second pass, this should succeed. If we get a second exception, then it's likely some other problem.- Parameters:
method- methodclazz- annotation class- Returns:
- true or false
-
hasAnnotatedMethodParameterAnnotation
public static <X> boolean hasAnnotatedMethodParameterAnnotation(jakarta.enterprise.inject.spi.AnnotatedMethod<X> annotatedMethod, Class<? extends Annotation> clazz)
-
getFirstAnnotatedParameter
public static <X> jakarta.enterprise.inject.spi.AnnotatedParameter<X> getFirstAnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedMethod<X> annotatedMethod, Class<? extends Annotation> annotation)
-
isCdiAnnotationEqual
public static boolean isCdiAnnotationEqual(jakarta.enterprise.inject.spi.AnnotatedType<?> at, Annotation annotation1, Annotation annotation2)Checks if the given cdi annotations are equal. cdi annotations may either be qualifiers or interceptor bindings. CDI annotations are equal if they have the same annotationType and all their methods, except those annotated with @Nonbinding, return the same value.- Parameters:
annotation1-annotation2-- Returns:
-
isCdiAnnotationEqual
public static boolean isCdiAnnotationEqual(Annotation annotation1, Annotation annotation2)
-
getCdiAnnotationHashCode
public static int getCdiAnnotationHashCode(Annotation annotation)
Computes a hash code for the specified cdi annoation. cdi annotations may either be qualifiers or interceptor bindings. The hash code of CDI annotations consists of the hash code of the annotationType and all its method values, except those annotated with @Nonbinding.- Parameters:
annotation-- Returns:
-
hasClassAnnotation
public static boolean hasClassAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
Check whether or not class contains the given annotation.- Parameters:
clazz- class instanceannotation- annotation class- Returns:
- return true or false
-
hasMetaAnnotation
public static boolean hasMetaAnnotation(Annotation[] anns, Class<? extends Annotation> metaAnnotation)
-
hasAnnotation
public static boolean hasAnnotation(Annotation[] anns, Class<? extends Annotation> annotation)
-
hasAnnotation
public static boolean hasAnnotation(Set<Annotation> anns, Class<? extends Annotation> annotation)
-
getAnnotation
public static <T extends Annotation> T getAnnotation(Annotation[] anns, Class<T> annotation)
get the annotation of the given type from the array.- Parameters:
anns-annotation-- Returns:
- the Annotation with the given type or
nullif no such found.
-
getMetaAnnotations
public static Annotation[] getMetaAnnotations(Annotation[] anns, Class<? extends Annotation> metaAnnotation)
Returns a subset of annotations that are annotated with the specified meta-annotation- Parameters:
anns-metaAnnotation-- Returns:
-
getAnnotation
public static <T extends Annotation> T getAnnotation(Set<Annotation> annotations, Class<T> annotationClass)
Search in the given Set of Annotations for the one with the given AnnotationClass.- Parameters:
annotations- to scanannotationClass- to search for- Returns:
- the annotation with the given annotationClass or
nullif not found.
-
hasOwbInjectableResource
public static Annotation hasOwbInjectableResource(Annotation[] annotations)
-
asArray
public static Annotation[] asArray(Collection<Annotation> set)
-
-