From b67dbe66ef43e6faca7886a36ebc6f9e9a1fd8f4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 1 Aug 2019 14:25:26 +0200 Subject: [PATCH] Revise use of ResolvableType in MethodParameter Includes consistent use of getContainingClass() --- .../org/springframework/core/MethodParameter.java | 15 +++++---------- .../org/springframework/core/ResolvableType.java | 13 +++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 0b4d3e968c8..6c1e1068d0d 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -160,9 +160,7 @@ public class MethodParameter { * @param containingClass the containing class * @since 5.2 */ - MethodParameter(Executable executable, int parameterIndex, - @Nullable Class containingClass) { - + MethodParameter(Executable executable, int parameterIndex, @Nullable Class containingClass) { Assert.notNull(executable, "Executable must not be null"); this.executable = executable; this.parameterIndex = validateIndex(executable, parameterIndex); @@ -488,9 +486,7 @@ public class MethodParameter { if (paramType != null) { return paramType; } - if (this.containingClass != null) { - paramType = ResolvableType.forMethodParameter(this, null, 1, null).resolve(); - } + paramType = ResolvableType.forMethodParameter(this, null, 1).resolve(); if (paramType == null) { paramType = computeParameterType(); } @@ -760,7 +756,7 @@ public class MethodParameter { return false; } MethodParameter otherParam = (MethodParameter) other; - return (this.containingClass == otherParam.containingClass && + return (getContainingClass() == otherParam.getContainingClass() && ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) && this.nestingLevel == otherParam.nestingLevel && this.parameterIndex == otherParam.parameterIndex && @@ -925,11 +921,10 @@ public class MethodParameter { KFunction function = ReflectJvmMapping.getKotlinFunction(method); if (function != null && function.isSuspend()) { Type paramType = ReflectJvmMapping.getJavaType(function.getReturnType()); - Class paramClass = ResolvableType.forType(paramType).resolve(); - Assert.notNull(paramClass, "Type " + paramType + "can't be resolved to a class"); - return paramClass; + return ResolvableType.forType(paramType).resolve(method.getReturnType()); } return method.getReturnType(); } } + } diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 055b81ee225..720e4eb56e7 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1300,10 +1300,7 @@ public class ResolvableType implements Serializable { */ public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); - int nestingLevel = methodParameter.getNestingLevel(); - Map typeIndexesPerLevel = methodParameter.typeIndexesPerLevel; - return forMethodParameter(methodParameter, targetType, nestingLevel, - typeIndexesPerLevel); + return forMethodParameter(methodParameter, targetType, methodParameter.getNestingLevel()); } /** @@ -1313,16 +1310,16 @@ public class ResolvableType implements Serializable { * @param methodParameter the source method parameter (must not be {@code null}) * @param targetType the type to resolve (a part of the method parameter's type) * @param nestingLevel the nesting level to use - * @param typeIndexesPerLevel the type indexes per nesting level * @return a {@link ResolvableType} for the specified method parameter * @since 5.2 * @see #forMethodParameter(Method, int) */ - static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType, - int nestingLevel, @Nullable Map typeIndexesPerLevel) { + static ResolvableType forMethodParameter( + MethodParameter methodParameter, @Nullable Type targetType, int nestingLevel) { + ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). - getNested(nestingLevel, typeIndexesPerLevel); + getNested(nestingLevel, methodParameter.typeIndexesPerLevel); } /**