Package io.hawt.util

Class ReflectionHelper


  • public final class ReflectionHelper
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean hasAnnotation​(java.lang.reflect.AnnotatedElement elem, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, boolean checkMetaAnnotations)
      Checks if a Class or Method are annotated with the given annotation
      static boolean hasMethodWithAnnotation​(java.lang.Class<?> type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, boolean checkMetaAnnotations)
      Returns true if the given type has a method with the given annotation
      static java.lang.Object invokeMethod​(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object... parameters)
      A helper method to invoke a method via reflection and wrap any exceptions as RuntimeException instances
      static <T> T newInstance​(java.lang.Class<T> type)
      A helper method to create a new instance of a type using the default constructor arguments.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectionHelper

        public ReflectionHelper()
    • Method Detail

      • newInstance

        public static <T> T newInstance​(java.lang.Class<T> type)
        A helper method to create a new instance of a type using the default constructor arguments.
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.reflect.Method method,
                                                    java.lang.Object instance,
                                                    java.lang.Object... parameters)
        A helper method to invoke a method via reflection and wrap any exceptions as RuntimeException instances
        Parameters:
        method - the method to invoke
        instance - the object instance (or null for static methods)
        parameters - the parameters to the method
        Returns:
        the result of the method invocation
      • hasMethodWithAnnotation

        public static boolean hasMethodWithAnnotation​(java.lang.Class<?> type,
                                                      java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                                      boolean checkMetaAnnotations)
        Returns true if the given type has a method with the given annotation
      • hasAnnotation

        public static boolean hasAnnotation​(java.lang.reflect.AnnotatedElement elem,
                                            java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                            boolean checkMetaAnnotations)
        Checks if a Class or Method are annotated with the given annotation
        Parameters:
        elem - the Class or Method to reflect on
        annotationType - the annotation type
        checkMetaAnnotations - check for meta annotations
        Returns:
        true if annotations is present