Class AnnotationsUtils

java.lang.Object
org.daiitech.naftah.utils.reflect.AnnotationsUtils

public final class AnnotationsUtils extends Object
Utility class for working with Java annotations on methods, classes, and parameters.
Author:
Chakib Daii
  • Constructor Details

    • AnnotationsUtils

      private AnnotationsUtils()
      Private constructor to prevent instantiation. Throws NaftahBugError if 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:
      true if all specified annotations are present on the method, otherwise false.
    • getMethodAnnotations

      public static List<Annotation> getMethodAnnotations(Method method)
      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

      public static <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationClass)
      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 null if not.
    • getNaftahFunctionAnnotation

      public static NaftahFunction getNaftahFunctionAnnotation(Method method, boolean useQualifiedName, boolean useQualifiedAliases)
      Extracts the custom NaftahFunction representation from the NaftahFn annotation on the method.
      Parameters:
      method - The method annotated with NaftahFn.
      Returns:
      A NaftahFunction instance 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:
      true if all specified annotations are present on the class, otherwise false.
    • getClassAnnotations

      public static List<Annotation> getClassAnnotations(Class<?> aClass)
      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 null if not.
    • getNaftahFunctionProviderAnnotation

      public static NaftahFunctionProvider getNaftahFunctionProviderAnnotation(Class<?> aClass)
      Extracts the custom NaftahFunctionProvider representation from the NaftahFnProvider annotation on the class.
      Parameters:
      aClass - The class annotated with NaftahFnProvider.
      Returns:
      A NaftahFunctionProvider instance constructed from the annotation.
    • getParametersAnnotations

      public static List<Annotation> getParametersAnnotations(Parameter parameter)
      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 null if not.