org.modelmapper.internal.util
Class TypeResolver

java.lang.Object
  extended by org.modelmapper.internal.util.TypeResolver

public final class TypeResolver
extends Object

Enhanced type resolution utilities. Based on org.springframework.core.GenericTypeResolver.

Author:
Jonathan Halterman

Method Summary
static
<T,I extends T>
Class<?>
resolveArgument(Class<I> initialType, Class<T> targetType)
          Returns the raw class representing the type argument for the targetType resolved upwards from the initialType.
static Class<?> resolveArgument(Type genericType, Class<?> targetType)
          Resolves the type argument for the genericType using type variable information from the sourceType.
static
<T,I extends T>
Class<?>[]
resolveArguments(Class<I> initialType, Class<T> targetType)
          Returns an array of raw classes representing type arguments for the targetType resolved upwards from the initialType.
static Class<?>[] resolveArguments(Type genericType, Class<?> targetType)
          Resolves the arguments for the genericType using the type variable information for the targetType.
static Type resolveBound(TypeVariable<?> typeVariable)
          Resolves the first bound for the typeVariable, returning Object.class if none can be resolved.
static Class<?> resolveClass(Type genericType, Class<?> targetType)
          Resolves the raw class for the given genericType, using the type variable information from the targetType.
static Type resolveGenericType(Type initialType, Class<?> targetType)
          Resolves the generic Type for the targetType by walking the type hierarchy upwards from the initialType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resolveArgument

public static <T,I extends T> Class<?> resolveArgument(Class<I> initialType,
                                                       Class<T> targetType)
Returns the raw class representing the type argument for the targetType resolved upwards from the initialType. If no arguments can be resolved then Object.class is returned.

Parameters:
initialType - to resolve upwards from
targetType - to resolve arguments for
Returns:
type argument for initialType else null if no type arguments are declared
Throws:
IllegalArgumentException - if more or less than one type argument is resolved for the give types

resolveArgument

public static Class<?> resolveArgument(Type genericType,
                                       Class<?> targetType)
Resolves the type argument for the genericType using type variable information from the sourceType. If genericType is an instance of class, then genericType is returned. If no arguments can be resolved then Object.class is returned.

Parameters:
genericType - to resolve upwards from
targetType - to resolve arguments for
Returns:
type argument for initialType else null if no type arguments are declared
Throws:
IllegalArgumentException - if more or less than one type argument is resolved for the give types

resolveArguments

public static <T,I extends T> Class<?>[] resolveArguments(Class<I> initialType,
                                                          Class<T> targetType)
Returns an array of raw classes representing type arguments for the targetType resolved upwards from the initialType. Arguments for targetType that cannot be resolved to a Class are returned as Object.class. If no arguments can be resolved then null is returned.

Parameters:
initialType - to resolve upwards from
targetType - to resolve arguments for
Returns:
array of raw classes representing type arguments for initialType else null if no type arguments are declared

resolveArguments

public static Class<?>[] resolveArguments(Type genericType,
                                          Class<?> targetType)
Resolves the arguments for the genericType using the type variable information for the targetType. Returns null if genericType is not parameterized or if arguments cannot be resolved.


resolveGenericType

public static Type resolveGenericType(Type initialType,
                                      Class<?> targetType)
Resolves the generic Type for the targetType by walking the type hierarchy upwards from the initialType.


resolveClass

public static Class<?> resolveClass(Type genericType,
                                    Class<?> targetType)
Resolves the raw class for the given genericType, using the type variable information from the targetType.


resolveBound

public static Type resolveBound(TypeVariable<?> typeVariable)
Resolves the first bound for the typeVariable, returning Object.class if none can be resolved.



Copyright © 2011. All Rights Reserved.