Browse Source

Revise use of ResolvableType in MethodParameter

Includes consistent use of getContainingClass()
pull/23401/head
Juergen Hoeller 6 years ago
parent
commit
b67dbe66ef
  1. 15
      spring-core/src/main/java/org/springframework/core/MethodParameter.java
  2. 13
      spring-core/src/main/java/org/springframework/core/ResolvableType.java

15
spring-core/src/main/java/org/springframework/core/MethodParameter.java

@ -160,9 +160,7 @@ public class MethodParameter { @@ -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 { @@ -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 { @@ -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 { @@ -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();
}
}
}

13
spring-core/src/main/java/org/springframework/core/ResolvableType.java

@ -1300,10 +1300,7 @@ public class ResolvableType implements Serializable { @@ -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<Integer, Integer> typeIndexesPerLevel = methodParameter.typeIndexesPerLevel;
return forMethodParameter(methodParameter, targetType, nestingLevel,
typeIndexesPerLevel);
return forMethodParameter(methodParameter, targetType, methodParameter.getNestingLevel());
}
/**
@ -1313,16 +1310,16 @@ public class ResolvableType implements Serializable { @@ -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<Integer, Integer> 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);
}
/**

Loading…
Cancel
Save