com.twitter.common.args
Class TypeUtil

java.lang.Object
  extended by com.twitter.common.args.TypeUtil

public final class TypeUtil
extends Object

Utility class to extract generic type information. TODO(William Farner): Move this into a common library, integrate with EasyMockTest.Clazz.


Method Summary
static Type extractTypeToken(Type type)
          Extracts the actual type parameter for a singly parameterized type.
static Class<?> getRawType(Type type)
          Finds the raw class of type.
static Type getTypeParam(Field field)
          Gets the type parameter from a field.
static List<Type> getTypeParams(Type type)
          Gets the types that a type is type-parameterized with, in declaration order.
static TypeToken<?> getTypeParamTypeToken(Field field)
          Convenience method to call getTypeParam(Field), with the requirement that there is exactly one type parameter on the field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTypeParams

public static List<Type> getTypeParams(Type type)
Gets the types that a type is type-parameterized with, in declaration order.

Parameters:
type - The type to extract type parameters from.
Returns:
The types that type is parameterized with.

getRawType

public static Class<?> getRawType(Type type)
Finds the raw class of type.

Parameters:
type - The type to get the raw class of.
Returns:
The raw class of type.

getTypeParamTypeToken

public static TypeToken<?> getTypeParamTypeToken(Field field)
Convenience method to call getTypeParam(Field), with the requirement that there is exactly one type parameter on the field.

Parameters:
field - The field to extract type parameters from.
Returns:
The raw classes of types that field is parameterized with.

getTypeParam

public static Type getTypeParam(Field field)
Gets the type parameter from a field. Assumes that there is at least one type parameter.

Parameters:
field - The field to extract the type parameter from.
Returns:
The field type parameter.

extractTypeToken

public static Type extractTypeToken(Type type)
Extracts the actual type parameter for a singly parameterized type.

Parameters:
type - The parameterized type to extract the type argument from.
Returns:
The type of the single specified type parameter for type.
Throws:
IllegalArgumentException - if the supplied type does not have exactly one specified type parameter