Class AnnotationsUtils
java.lang.Object
org.daiitech.naftah.utils.reflect.AnnotationsUtils
Utility class for working with Java annotations on methods, classes, and
parameters.
- Author:
- Chakib Daii
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
TgetClassAnnotation(Class<?> aClass, Class<T> annotationClass) Returns a specific annotation instance from the given class.static List<Annotation>getClassAnnotations(Class<?> aClass) Returns a list of all annotations present on the given class.static <T extends Annotation>
TgetMethodAnnotation(Method method, Class<T> annotationClass) Returns a specific annotation instance from the given method.static List<Annotation>getMethodAnnotations(Method method) Returns a list of all annotations declared on the given method.static NaftahFunctiongetNaftahFunctionAnnotation(Method method, boolean useQualifiedName, boolean useQualifiedAliases) Extracts the customNaftahFunctionrepresentation from theNaftahFnannotation on the method.static NaftahFunctionProvidergetNaftahFunctionProviderAnnotation(Class<?> aClass) Extracts the customNaftahFunctionProviderrepresentation from theNaftahFnProviderannotation on the class.static <T extends Annotation>
TgetParametersAnnotation(Parameter parameter, Class<T> annotationClass) Returns a specific annotation instance from the given method parameter.static List<Annotation>getParametersAnnotations(Parameter parameter) Returns a list of all annotations present on the given method parameter.static booleanisAnnotationsPresent(Class<?> aClass, Class<? extends Annotation>... annotations) Checks if the specified annotations are present on the given class.static booleanisAnnotationsPresent(Method method, Class<? extends Annotation>... annotations) Checks if the specified annotations are present on the given method.
-
Constructor Details
-
AnnotationsUtils
private AnnotationsUtils()Private constructor to prevent instantiation. ThrowsNaftahBugErrorif called.
-
-
Method Details
-
isAnnotationsPresent
@SafeVarargs public static boolean isAnnotationsPresent(Method method, Class<? extends Annotation>... annotations) Checks if the specified annotations are present on the given method.- Parameters:
method- The method to check.annotations- One or more annotation classes to verify.- Returns:
trueif all specified annotations are present on the method, otherwisefalse.
-
getMethodAnnotations
Returns a list of all annotations declared on the given method.- Parameters:
method- The method to inspect.- Returns:
- A list of annotations present on the method.
-
getMethodAnnotation
Returns a specific annotation instance from the given method.- Type Parameters:
T- The type of the annotation.- Parameters:
method- The method to inspect.annotationClass- The class of the annotation to retrieve.- Returns:
- The annotation instance if present, or
nullif not.
-
getNaftahFunctionAnnotation
public static NaftahFunction getNaftahFunctionAnnotation(Method method, boolean useQualifiedName, boolean useQualifiedAliases) Extracts the customNaftahFunctionrepresentation from theNaftahFnannotation on the method.- Parameters:
method- The method annotated withNaftahFn.- Returns:
- A
NaftahFunctioninstance constructed from the annotation.
-
isAnnotationsPresent
@SafeVarargs public static boolean isAnnotationsPresent(Class<?> aClass, Class<? extends Annotation>... annotations) Checks if the specified annotations are present on the given class.- Parameters:
aClass- The class to check.annotations- One or more annotation classes to verify.- Returns:
trueif all specified annotations are present on the class, otherwisefalse.
-
getClassAnnotations
Returns a list of all annotations present on the given class.- Parameters:
aClass- The class to inspect.- Returns:
- A list of annotations present on the class.
-
getClassAnnotation
public static <T extends Annotation> T getClassAnnotation(Class<?> aClass, Class<T> annotationClass) Returns a specific annotation instance from the given class.- Type Parameters:
T- The type of the annotation.- Parameters:
aClass- The class to inspect.annotationClass- The class of the annotation to retrieve.- Returns:
- The annotation instance if present, or
nullif not.
-
getNaftahFunctionProviderAnnotation
Extracts the customNaftahFunctionProviderrepresentation from theNaftahFnProviderannotation on the class.- Parameters:
aClass- The class annotated withNaftahFnProvider.- Returns:
- A
NaftahFunctionProviderinstance constructed from the annotation.
-
getParametersAnnotations
Returns a list of all annotations present on the given method parameter.- Parameters:
parameter- The method parameter to inspect.- Returns:
- A list of annotations present on the parameter.
-
getParametersAnnotation
public static <T extends Annotation> T getParametersAnnotation(Parameter parameter, Class<T> annotationClass) Returns a specific annotation instance from the given method parameter.- Type Parameters:
T- The type of the annotation.- Parameters:
parameter- The parameter to inspect.annotationClass- The class of the annotation to retrieve.- Returns:
- The annotation instance if present, or
nullif not.
-