Class ReflectionHelper


  • public class ReflectionHelper
    extends java.lang.Object
    Utility class with useful methods to work with reflections
    Author:
    andrzej
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ReflectionHelper.Handler<A extends java.lang.annotation.Annotation,​T>  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean boundMatch​(java.lang.Class c1, java.lang.reflect.TypeVariable t2)  
      static boolean boundMatch​(java.lang.reflect.TypeVariable t1, java.lang.reflect.TypeVariable t2)  
      static boolean classMatchesClassWithParameters​(java.lang.Class clazz, java.lang.Class requiredType, java.lang.reflect.Type[] requiredTypeParams)  
      static boolean classMatchesType​(java.lang.Class clazz, java.lang.reflect.Type required)  
      static <A extends java.lang.annotation.Annotation,​T>
      java.util.Collection<T>
      collectAnnotatedMethods​(java.lang.Object consumer, java.lang.Class<A> annotationCls, ReflectionHelper.Handler<A,​T> handler)
      This method collects every method of consumer class annotated with passed annotation and for each of them executes implementation of Handler.
      static boolean compareTypes​(java.lang.reflect.Type expectedType, java.lang.reflect.Type actualType, java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> ownerExpectedTypesMap, java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> ownerActualTypesMap)  
      static java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> createGenericsTypeMap​(java.lang.Class<?> cls)  
      static java.lang.reflect.Type getCollectionParamter​(java.lang.reflect.Type genericType, java.lang.Class clazz)  
      static java.lang.Class<?> getItemClassOfGenericCollection​(java.lang.reflect.Field f)  
      • 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

      • boundMatch

        public static boolean boundMatch​(java.lang.Class c1,
                                         java.lang.reflect.TypeVariable t2)
      • boundMatch

        public static boolean boundMatch​(java.lang.reflect.TypeVariable t1,
                                         java.lang.reflect.TypeVariable t2)
      • classMatchesClassWithParameters

        public static boolean classMatchesClassWithParameters​(java.lang.Class clazz,
                                                              java.lang.Class requiredType,
                                                              java.lang.reflect.Type[] requiredTypeParams)
      • classMatchesType

        public static boolean classMatchesType​(java.lang.Class clazz,
                                               java.lang.reflect.Type required)
      • collectAnnotatedMethods

        public static <A extends java.lang.annotation.Annotation,​T> java.util.Collection<T> collectAnnotatedMethods​(java.lang.Object consumer,
                                                                                                                          java.lang.Class<A> annotationCls,
                                                                                                                          ReflectionHelper.Handler<A,​T> handler)
        This method collects every method of consumer class annotated with passed annotation and for each of them executes implementation of Handler.
      • compareTypes

        public static boolean compareTypes​(java.lang.reflect.Type expectedType,
                                           java.lang.reflect.Type actualType,
                                           java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> ownerExpectedTypesMap,
                                           java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> ownerActualTypesMap)
      • createGenericsTypeMap

        public static java.util.Map<java.lang.reflect.TypeVariable<?>,​java.lang.reflect.Type> createGenericsTypeMap​(java.lang.Class<?> cls)
      • getCollectionParamter

        public static java.lang.reflect.Type getCollectionParamter​(java.lang.reflect.Type genericType,
                                                                   java.lang.Class clazz)
      • getItemClassOfGenericCollection

        public static java.lang.Class<?> getItemClassOfGenericCollection​(java.lang.reflect.Field f)