org.atmosphere.wasync.util
Class TypeResolver

java.lang.Object
  extended by org.atmosphere.wasync.util.TypeResolver

public final class TypeResolver
extends java.lang.Object

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

Author:
Jonathan Halterman

Nested Class Summary
static class TypeResolver.Unknown
          An unknown type.
 
Method Summary
static void disableCache()
          Disables the internal caching of TypeVariables.
static void enableCache()
          Enables the internal caching of TypeVariables.
static
<T,I extends T>
java.lang.Class<?>
resolveArgument(java.lang.Class<I> initialType, java.lang.Class<T> targetType)
          Returns the raw class representing the type argument for the targetType resolved upwards from the initialType.
static java.lang.Class<?> resolveArgument(java.lang.reflect.Type genericType, java.lang.Class<?> targetType)
          Resolves the type argument for the genericType using type variable information from the sourceType.
static
<T,I extends T>
java.lang.Class<?>[]
resolveArguments(java.lang.Class<I> initialType, java.lang.Class<T> targetType)
          Returns an array of raw classes representing type arguments for the targetType resolved upwards from the initialType.
static java.lang.Class<?>[] resolveArguments(java.lang.reflect.Type genericType, java.lang.Class<?> targetType)
          Resolves the arguments for the genericType using the type variable information for the targetType.
static java.lang.reflect.Type resolveBound(java.lang.reflect.TypeVariable<?> typeVariable)
          Resolves the first bound for the typeVariable, returning Unknown.class if none can be resolved.
static java.lang.Class<?> resolveClass(java.lang.reflect.Type genericType, java.lang.Class<?> targetType)
          Resolves the raw class for the given genericType, using the type variable information from the targetType.
static java.lang.reflect.Type resolveGenericType(java.lang.reflect.Type initialType, java.lang.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

enableCache

public static void enableCache()
Enables the internal caching of TypeVariables.


disableCache

public static void disableCache()
Disables the internal caching of TypeVariables.


resolveArgument

public static <T,I extends T> java.lang.Class<?> resolveArgument(java.lang.Class<I> initialType,
                                                                 java.lang.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 Unknown.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:
java.lang.IllegalArgumentException - if more or less than one type argument is resolved for the give types

resolveArgument

public static java.lang.Class<?> resolveArgument(java.lang.reflect.Type genericType,
                                                 java.lang.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 Unknown.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:
java.lang.IllegalArgumentException - if more or less than one type argument is resolved for the give types

resolveArguments

public static <T,I extends T> java.lang.Class<?>[] resolveArguments(java.lang.Class<I> initialType,
                                                                    java.lang.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 Unknown.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 java.lang.Class<?>[] resolveArguments(java.lang.reflect.Type genericType,
                                                    java.lang.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 java.lang.reflect.Type resolveGenericType(java.lang.reflect.Type initialType,
                                                        java.lang.Class<?> targetType)
Resolves the generic Type for the targetType by walking the type hierarchy upwards from the initialType.


resolveClass

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


resolveBound

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



Copyright © 2014. All Rights Reserved.