Class GenericsUtil
java.lang.Object
org.apache.camel.maven.packaging.generics.GenericsUtil
Utility classes for generic type operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsTypeVariable(Type type) static booleancontainTypeVariable(Type[] types) getDirectTypeClosure(Type type, Type actualType) static ParameterizedTypegetParameterizedType(Type type) static <T> Class<T> getRawType(Type type) getTypeClosure(Type actualType) getTypeClosure(Type type, Type actualType) Returns the type closure for the specified parameters.static booleanhasTypeParameters(Type type) static booleanisAssignableFrom(boolean isDelegateOrEvent, boolean isProducer, Type requiredType, Type beanType) 5.2.3 and 5.2.4static Type[]resolveParameterTypes(Class<?> subclass, Method method) Resolves the actual parameter generics of the specified method for the type hierarchy specified by the given subclassstatic TyperesolveSetterType(Class<?> subclass, Method method) Resolves the actual type of the specified field for the type hierarchy specified by the given subclassstatic TyperesolveType(Class<?> subclass, Field field) Resolves the actual type of the specified field for the type hierarchy specified by the given subclassstatic TyperesolveType(Type type, Type actualType, Collection<TypeVariable<?>> seen) static Type[]resolveTypes(Type[] types, Type actualType) static Type[]resolveTypes(Type[] types, Type actualType, Collection<TypeVariable<?>> seen)
-
Method Details
-
isAssignableFrom
public static boolean isAssignableFrom(boolean isDelegateOrEvent, boolean isProducer, Type requiredType, Type beanType) 5.2.3 and 5.2.4 -
containsTypeVariable
- Returns:
- true, if the specified type declaration contains an unresolved type variable.
-
containTypeVariable
-
resolveType
Resolves the actual type of the specified field for the type hierarchy specified by the given subclass -
resolveSetterType
Resolves the actual type of the specified field for the type hierarchy specified by the given subclass -
resolveParameterTypes
Resolves the actual parameter generics of the specified method for the type hierarchy specified by the given subclass -
resolveType
-
resolveTypes
-
resolveTypes
-
getTypeClosure
-
getTypeClosure
Returns the type closure for the specified parameters.Example 1:
Take the following classes:
public class Foo{ private T t; } public class Bar extends Foo { } To get the type closure of T in the context of Bar (which is {Number.class, Object.class}), you have to call this method like
GenericUtil.getTypeClosure(Foo.class.getDeclaredField("t").getType(), Bar.class, Foo.class);Example 2:
Take the following classes:
public class Foo{ private T t; } public class Bar extends Foo { } To get the type closure of Bar
in the context of Foo (which are besides Object.class the ParameterizedTypes Bar and Foo ), you have to call this method like GenericUtil.getTypeClosure(Foo.class, new TypeLiteralinvalid input: '<'Foo>() {}.getType(), Bar.class); - Parameters:
type- the type to get the closure foractualType- the context to bind type variables- Returns:
- the type closure
-
getDirectTypeClosure
-
hasTypeParameters
-
getParameterizedType
-
getRawType
-