Package de.bild.codec

Class ReflectionHelper

java.lang.Object
de.bild.codec.ReflectionHelper

public abstract class ReflectionHelper extends Object
  • Method Details

    • getDeclaredAndInheritedFieldTypePairs

      public static List<FieldTypePair> getDeclaredAndInheritedFieldTypePairs(Type type, boolean returnFinalFields)
      calculates all fields of class hierarchy
      Parameters:
      type - the value type
      returnFinalFields - indicate if final fields should be retuned as well
      Returns:
      all declared and all inherited declared fields of given type
    • getDeclaredAndInheritedFieldTypePair

      public static FieldTypePair getDeclaredAndInheritedFieldTypePair(Type type, String fieldName)
      Finds a field with fully resolved type within the given type
      Parameters:
      type - any type generic or simply a class
      fieldName - a name of a field within that type
      Returns:
      null, or the resolved FieldTypePair
    • calculateInferredTypeParameters

      public static Map<String,Type> calculateInferredTypeParameters(Class clazz, Type[] actualTypeParameters)
      Calculates the map of inferred type parameters for the given class based upon the given array of known type parameters from the class hierarchy
      Parameters:
      clazz - the class to work on
      actualTypeParameters - array of type parameters
      Returns:
      a Map of inferred types, that maps type variable names to real types
    • inferRealType

      public static Type inferRealType(Type type, Map<String,Type> realTypeMap)
    • getDeclaredAndInheritedMethods

      public static List<MethodTypePair> getDeclaredAndInheritedMethods(Type type)
    • getIdFieldIfPresent

      public static FieldTypePair getIdFieldIfPresent(Class clazz)
    • getLockingVersionFieldIfPresent

      public static FieldTypePair getLockingVersionFieldIfPresent(Class clazz)
    • findInterface

      public static Type findInterface(Type type, Class interfaceToFind)
      Example:
       
            static class ValueClass {}
            static class SomeOtherClass<V extends ValueClass> extends ArrayList<V> implements List<V> {}
            static class SomeSpecializedList extends SomeOtherClass<ValueClass> {}
        
       
      Parameters:
      type - e.g. SomeSpecializedList
      interfaceToFind - example List.class
      Returns:
      the parameterized interface, e.g. List<ValueClass>
    • extractRawClass

      public static Class extractRawClass(Type type)
      Parameters:
      type - type to be examined
      Returns:
      The raw class of the given type or if type is a class, the class itself will be returned