Interface GenericsResolver
-
- All Known Implementing Classes:
GenericsResolverImpl,GuavaGenericsResolver
public interface GenericsResolver
Methods related to the use of Java 5+ generics. Instances should be obtained through
GenericsResolver.Provider.getInstance().If you have exceptions or bad results with classes using Generics, such as exceptions or missing BeanModel properties, you should try adding the
genericsresolver-guavaTapestry subproject to our classpath.- Since:
- 5.5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classGenericsResolver.ProviderConvenience class for getting aGenericsResolverinstance.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ClassasClass(Type actualType)Get the class represented by the reflected type.TypeextractActualType(Type containingType, Field field)Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type.TypeextractActualType(Type containingType, Method method)Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type.ClassextractGenericFieldType(Class containingClass, Field field)Analyzes the field in the context of containingClass and returns the Class that is represented by the field's generic type.Class<?>extractGenericReturnType(Class<?> containingClass, Method method)Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type.Typeresolve(Type type, Type containingType)Resolves the type parameter based on the context of the containingType.
-
-
-
Method Detail
-
extractGenericReturnType
Class<?> extractGenericReturnType(Class<?> containingClass, Method method)
Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type. Any parameter information in the generic return type is lost. If you want to preserve the type parameters of the return type consider usingextractActualType(java.lang.reflect.Type, java.lang.reflect.Method).- Parameters:
containingClass- class which either contains or inherited the methodmethod- method from which to extract the return type- Returns:
- the class represented by the methods generic return type, resolved based on the context .
- See Also:
resolve(java.lang.reflect.Type,java.lang.reflect.Type),asClass(java.lang.reflect.Type)
-
extractGenericFieldType
Class extractGenericFieldType(Class containingClass, Field field)
Analyzes the field in the context of containingClass and returns the Class that is represented by the field's generic type. Any parameter information in the generic type is lost, if you want to preserve the type parameters of the return type consider using #getTypeVariableIndex(java.lang.reflect.TypeVariable).- Parameters:
containingClass- class which either contains or inherited the fieldfield- field from which to extract the type- Returns:
- the class represented by the field's generic type, resolved based on the containingClass.
- See Also:
extractActualType(java.lang.reflect.Type, java.lang.reflect.Field),resolve(java.lang.reflect.Type,java.lang.reflect.Type),asClass(java.lang.reflect.Type)
-
extractActualType
Type extractActualType(Type containingType, Method method)
Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type. Any parameter information in the generic return type is lost.- Parameters:
containingType- Type which is/represents the class that either contains or inherited the methodmethod- method from which to extract the generic return type- Returns:
- the generic type represented by the methods generic return type, resolved based on the containingType.
- See Also:
resolve(java.lang.reflect.Type,java.lang.reflect.Type)
-
extractActualType
Type extractActualType(Type containingType, Field field)
Analyzes the method in the context of containingClass and returns the Class that is represented by the method's generic return type. Any parameter information in the generic return type is lost.- Parameters:
containingType- Type which is/represents the class that either contains or inherited the fieldfield- field from which to extract the generic return type- Returns:
- the generic type represented by the methods generic return type, resolved based on the containingType.
- See Also:
resolve(java.lang.reflect.Type,java.lang.reflect.Type)
-
resolve
Type resolve(Type type, Type containingType)
Resolves the type parameter based on the context of the containingType.TypeVariablewill be unwrapped to the type argument resolved form the class hierarchy. This may be something other than a simple Class if the type argument is a ParameterizedType for instance (e.g.List<E>; List<Map<Long, String>>, E would be returned as a ParameterizedType with the raw type Map and type arguments Long and String.- Parameters:
type- the generic type (ParameterizedType, GenericArrayType, WildcardType, TypeVariable) to be resolvedcontainingType- the type which his- Returns:
- the type resolved to the best of our ability.
-
asClass
Class asClass(Type actualType)
Get the class represented by the reflected type. This method is lossy; You cannot recover the type information from the class that is returned.TypeVariablethe first bound is returned. If your type variable extends multiple interfaces that information is lost.WildcardTypethe first lower bound is returned. If the wildcard is defined with upper bounds thenObjectis returned.- Parameters:
actualType- a Class, ParameterizedType, GenericArrayType- Returns:
- the un-parameterized class associated with the type.
-
-