Skip to content

Commit

Permalink
Merge pull request spring-projects#24525 from chenqimiao
Browse files Browse the repository at this point in the history
* pr/24525:
  Polish "Reuse ResolvableType in getDependencyType"
  Reuse ResolvableType in getDependencyType

Closes spring-projectsgh-24525
  • Loading branch information
snicoll committed Dec 21, 2021
2 parents f64ede3 + f1fe16e commit 544e9bb
Showing 1 changed file with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
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;

Expand Down Expand Up @@ -365,23 +363,8 @@ public String getDependencyName() {
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();
Expand Down

0 comments on commit 544e9bb

Please sign in to comment.