Class ReflectionUtils


  • public class ReflectionUtils
    extends Object
    • Constructor Detail

      • ReflectionUtils

        public ReflectionUtils()
    • Method Detail

      • typeFromString

        public static Type typeFromString​(String type)
      • loadClassByName

        public static Class<?> loadClassByName​(String className)
                                        throws ClassNotFoundException
        Load Class by class name. If class not found in it's Class loader or one of the parent class loaders - delegate to the Thread's ContextClassLoader
        Parameters:
        className - Canonical class name
        Returns:
        Class definition of className
        Throws:
        ClassNotFoundException
      • isOverriddenMethod

        public static boolean isOverriddenMethod​(Method methodToFind,
                                                 Class<?> cls)
        Checks if the method methodToFind is the overridden method from the superclass or superinterface.
        Parameters:
        methodToFind - is method to check
        cls - is method class
        Returns:
        true if the method is overridden method
      • getOverriddenMethod

        public static Method getOverriddenMethod​(Method method)
        Returns overridden method from superclass if it exists. If method was not found returns null.
        Parameters:
        method - is method to find
        Returns:
        overridden method from superclass
      • findMethod

        public static Method findMethod​(Method methodToFind,
                                        Class<?> cls)
        Searches the method methodToFind in given class cls. If the method is found returns it, else return null.
        Parameters:
        methodToFind - is the method to search
        cls - is the class or interface where to search
        Returns:
        method if it is found
      • isInject

        public static boolean isInject​(List<Annotation> annotations)
      • isConstructorCompatible

        public static boolean isConstructorCompatible​(Constructor<?> constructor)
      • getDeclaredFields

        public static List<Field> getDeclaredFields​(Class<?> cls)
        Returns the list of declared fields from the class cls and its superclasses excluding Object class. If the field from child class hides the field from superclass, the field from superclass won't be added to the result list.
        Parameters:
        cls - is the processing class
        Returns:
        list of Fields
      • getAnnotation

        public static <A extends Annotation> A getAnnotation​(Method method,
                                                             Class<A> annotationClass)
        Returns an annotation by type from a method.
        Type Parameters:
        A - is the type of annotation
        Parameters:
        method - is the method to find
        annotationClass - is the type of annotation
        Returns:
        annotation if it is found
      • getAnnotation

        public static <A extends Annotation> A getAnnotation​(Class<?> cls,
                                                             Class<A> annotationClass)
      • getParameterAnnotations

        public static Annotation[][] getParameterAnnotations​(Method method)
      • isVoid

        public static boolean isVoid​(Type type)
        Checks if the type is void.
        Parameters:
        type - is the type to check
        Returns:
        true if the type is void