Provider injection works with generically typed collections of beans as well (SPR-9030)

This commit is contained in:
Juergen Hoeller
2012-02-08 16:29:00 +01:00
parent 9a61f36d3d
commit c55362c35e
4 changed files with 209 additions and 39 deletions

View File

@@ -21,6 +21,7 @@ import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.HashMap;
@@ -233,6 +234,29 @@ public class MethodParameter {
return this.genericParameterType;
}
public Class<?> getNestedParameterType() {
if (this.nestingLevel > 1) {
Type type = getGenericParameterType();
if (type instanceof ParameterizedType) {
Integer index = getTypeIndexForCurrentLevel();
Type arg = ((ParameterizedType) type).getActualTypeArguments()[index != null ? index : 0];
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;
}
else {
return getParameterType();
}
}
/**
* Return the annotations associated with the target method/constructor itself.
*/