forked from coekie/gentyref
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Coming from coekie#5 (comment)
I gave it a spin and came up with this:
public static Type getResolvedReturnType(Method m, Type declaringType) {
return resolveTypeVariableIfNecessary(GenericTypeReflector.getReturnType(m, declaringType));
}
public static Type getResolvedFieldType(Field f, Type declaringType) {
return resolveTypeVariableIfNecessary(GenericTypeReflector.getFieldType(f, declaringType));
}
public static List<Type> getResolvedParameterTypes(Method m, Type declaringType) {
return Arrays.stream(GenericTypeReflector.getParameterTypes(m, declaringType))
.map(ReflectionUtil::resolveTypeVariableIfNecessary)
.collect(Collectors.toList());
}
private static Type resolveTypeVariableIfNecessary(Type returnType) {
if (returnType instanceof TypeVariable) {
AnnotatedType annotatedType = GenericTypeReflector.annotate(returnType);
return GenericTypeReflector.reduceBounded(annotatedType).getType();
}
return returnType;
}it seems to work, but I'm not sure its the best way. You can see the full change here https://github.com/leonard84/spock/tree/replace_gentyref_with_geantyref
I think that it might have value to have something like this in GenericTypeReflector directly, this way it could be optimized as well, the current implementation has to re-annotate the type that was discarded in GenericTypeReflector internally.
Metadata
Metadata
Assignees
Labels
No labels