Browse Source

SPR-6977: added support for array parameter types

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3091 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Christian Dupuis 16 years ago
parent
commit
b81adebd6e
  1. 30
      org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java

30
org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java

@ -18,6 +18,7 @@ package org.springframework.core; @@ -18,6 +18,7 @@ package org.springframework.core;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
@ -146,14 +147,7 @@ public abstract class GenericTypeResolver { @@ -146,14 +147,7 @@ public abstract class GenericTypeResolver {
Class[] result = new Class[typeArgs.length];
for (int i = 0; i < typeArgs.length; i++) {
Type arg = typeArgs[i];
if (arg instanceof TypeVariable) {
TypeVariable tv = (TypeVariable) arg;
arg = getTypeVariableMap(ownerClass).get(tv);
if (arg == null) {
arg = extractBoundForTypeVariable(tv);
}
}
result[i] = (arg instanceof Class ? (Class) arg : Object.class);
result[i] = extractClass(ownerClass, arg);
}
return result;
}
@ -169,6 +163,26 @@ public abstract class GenericTypeResolver { @@ -169,6 +163,26 @@ public abstract class GenericTypeResolver {
}
return null;
}
private static Class extractClass(Class ownerClass, Type arg) {
if (arg instanceof TypeVariable) {
TypeVariable tv = (TypeVariable) arg;
arg = getTypeVariableMap(ownerClass).get(tv);
if (arg == null) {
arg = extractBoundForTypeVariable(tv);
}
else {
arg = extractClass(ownerClass, arg);
}
}
else if (arg instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) arg;
Type gt = gat.getGenericComponentType();
Class<?> componentClass = extractClass(ownerClass, gt);
arg = Array.newInstance(componentClass, 0).getClass();
}
return (arg instanceof Class ? (Class) arg : Object.class);
}
/**

Loading…
Cancel
Save