List of usage examples for org.apache.commons.lang3.reflect TypeUtils getTypeArguments
public static Map<TypeVariable<?>, Type> getTypeArguments(final ParameterizedType type)
Retrieves all the type arguments for this parameterized type including owner hierarchy arguments such as Outer From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java From source file:org.evosuite.utils.generic.GenericAccessibleObject.javaUsage
public static Collection<Type> getParameterTypesForCollection(Class<?> type) {
if (isCollectionOrSequence(type)) {
Map<TypeVariable<?>, Type> m = TypeUtils
.getTypeArguments((ParameterizedType) type.getGenericSuperclass());
return m.values();
}//w w w . j a v a 2 s . c o m
return null;
}
/**
* Returns the exact return type of the given method in the given type. This
* may be different from <tt>m.getGenericReturnType()</tt> when the method
* was declared in a superclass, or <tt>type</tt> has a type parameter that
* is used in the return type, or <tt>type</tt> is a raw type.
*/// w w w.j ava 2 s. c o m
protected static Type getTypeFromExactReturnType(ParameterizedType returnType, ParameterizedType type) {
Map<TypeVariable<?>, Type> typeMap = TypeUtils.getTypeArguments(returnType);
Type[] actualParameters = new Type[type.getActualTypeArguments().length];
int num = 0;
for (TypeVariable<?> parameterType : ((Class<?>) type.getRawType()).getTypeParameters()) {
//for(Type parameterType : type.getActualTypeArguments()) {
// if(parameterType instanceof TypeVariable<?>) {
boolean replaced = false;
for (TypeVariable<?> var : typeMap.keySet()) {
// D'oh! Why the heck do we need this??
if (var.getName().equals(parameterType.getName())) {
//if(typeMap.containsKey(parameterType)) {
actualParameters[num] = typeMap.get(var);
replaced = true;
break;
//} else {
}
}
if (!replaced) {
actualParameters[num] = parameterType;
}
//}
// } else {
// LoggingUtils.getEvoLogger().info("Not a type variable "+parameterType);
// actualParameters[num] = parameterType;
// }
num++;
}
return new ParameterizedTypeImpl((Class<?>) type.getRawType(), actualParameters, null);
}