Support for java.util.Optional within ObjectFactory/Provider

Includes support for arbitrary deep nesting levels in DependencyDescriptor's getDependencyType() and MethodParameter's getNestedParameterType().

Issue: SPR-11833
This commit is contained in:
Juergen Hoeller
2014-06-06 15:29:50 +02:00
parent 7d03daf8cb
commit 5cb3f8eada
4 changed files with 148 additions and 52 deletions

View File

@@ -260,19 +260,21 @@ public class MethodParameter {
public Class<?> getNestedParameterType() {
if (this.nestingLevel > 1) {
Type type = getGenericParameterType();
if (type instanceof ParameterizedType) {
Integer index = getTypeIndexForCurrentLevel();
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
Type arg = args[index != null ? index : args.length - 1];
for (int i = 2; i <= this.nestingLevel; i++) {
if (type instanceof ParameterizedType) {
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
Integer index = getTypeIndexForLevel(i);
type = args[index != null ? index : args.length - 1];
}
}
if (type instanceof Class) {
return (Class<?>) type;
}
else if (type instanceof ParameterizedType) {
Type arg = ((ParameterizedType) type).getRawType();
if (arg instanceof Class) {
return (Class<?>) arg;
}
else if (arg instanceof ParameterizedType) {
arg = ((ParameterizedType) arg).getRawType();
if (arg instanceof Class) {
return (Class<?>) arg;
}
}
}
return Object.class;
}