Browse Source

Merge pull request #24525 from chenqimiao

* pr/24525:
  Polish "Reuse ResolvableType in getDependencyType"
  Reuse ResolvableType in getDependencyType

Closes gh-24525
pull/27848/head
Stephane Nicoll 4 years ago
parent
commit
544e9bb403
  1. 21
      spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

21
spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

@ -21,8 +21,6 @@ import java.io.ObjectInputStream; @@ -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 @@ -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();

Loading…
Cancel
Save