Class Reflections

java.lang.Object
com.thewinterframework.utils.reflect.Reflections

public class Reflections extends Object
Utility class for reflection operations.
  • Constructor Details

    • Reflections

      public Reflections()
  • Method Details

    • findMethodsWith

      public static <T extends Annotation> List<AnnotatedMethodHandle<T>> findMethodsWith(Class<?> clazz, Class<T> annotation) throws IllegalAccessException, NoSuchMethodException
      Finds all methods in a class that are annotated with a specific annotation, or with an annotation that is itself annotated with that annotation (meta-annotation).
      Type Parameters:
      T - The annotation type.
      Parameters:
      clazz - The class to search in.
      annotation - The annotation or meta-annotation to search for.
      Returns:
      A list of annotated method handles.
      Throws:
      IllegalAccessException - If the method cannot be accessed.
      NoSuchMethodException - If the method does not exist.
    • findClassAnnotations

      public static <T extends Annotation> List<Annotation> findClassAnnotations(Class<?> clazz, Class<T> metaAnnotation)
      Finds all annotations of a class that are annotated with a specific meta-annotation.
      Type Parameters:
      T - The annotation type.
      Parameters:
      clazz - The class to get the annotations from.
      metaAnnotation - The meta-annotation to get the annotations from.
      Returns:
      The annotations.
    • findMethodParameters

      public static List<com.google.inject.Key<?>> findMethodParameters(Method method)
      Finds the parameters of a method.
      Parameters:
      method - The method to find the parameters of.
      Returns:
      A list of keys representing the parameters.
    • injectKeys

      public static Object[] injectKeys(Class<?> instance, List<com.google.inject.Key<?>> keys, com.google.inject.Injector injector)
      Injects the keys into the injector and returns the objects.
      Parameters:
      instance - The instance to inject the keys into.
      keys - The keys to inject.
      injector - The injector to get the instances from.
      Returns:
      The objects.
    • getGenericType

      public static Type getGenericType(Class<?> clazz, Class<?> interfaze, int index)
      Gets the generic type of class that implements an interface.
      Parameters:
      clazz - The class to get the generic type from.
      interfaze - The interface to get the generic type from.
      index - The index of the generic type.
      Returns:
      The generic type.
    • toClass

      public static Class<?> toClass(Type type)
      Converts a type to a class.
      Parameters:
      type - The type to convert.
      Returns:
      The class.
    • findBindingAnnotation

      public static Annotation findBindingAnnotation(AnnotatedElement element)
      Finds the binding annotation of an element.
      Parameters:
      element - The element to find the binding annotation of.
      Returns:
      The binding annotation.