Reuse ResolvableType in getDependencyType

See gh-24525
This commit is contained in:
陈其苗 2020-02-14 22:40:47 +08:00 committed by Stephane Nicoll
parent f64ede3c83
commit b69ab8d568
1 changed files with 2 additions and 19 deletions

View File

@ -21,8 +21,6 @@ import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Optional;
@ -365,23 +363,8 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
public Class<?> getDependencyType() {
if (this.field != null) {
if (this.nestingLevel > 1) {
Type type = this.field.getGenericType();
for (int i = 2; i <= this.nestingLevel; i++) {
if (type instanceof ParameterizedType) {
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
type = args[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;
}
}
return Object.class;
Class<?> clazz = getResolvableType().getRawClass();
return clazz != null ? clazz : Object.class;
}
else {
return this.field.getType();