Provide 'with implementationType' overloads

Provided overloaded versions of `forField` and `forMethodParameter` that
accept a `ResolvableType` implementation type (as opposed to a Class).

Primarily added to allow resolution against implementation types that
have been created programmatically using `forTypeWithGenerics`.

Issue: SPR-11218
This commit is contained in:
Phillip Webb
2014-01-17 11:45:11 -08:00
parent 7e6dbc24f6
commit 9076c70d47
2 changed files with 58 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -835,6 +835,23 @@ public final class ResolvableType implements Serializable {
return forType(null, new FieldTypeProvider(field), owner.asVariableResolver());
}
/**
* Return a {@link ResolvableType} for the specified {@link Field} with a given
* implementation.
* <p>Use this variant when the class that declares the field includes generic
* parameter variables that are satisfied by the implementation type.
* @param field the source field
* @param implementationType the implementation type
* @return a {@link ResolvableType} for the specified field
* @see #forField(Field)
*/
public static ResolvableType forField(Field field, ResolvableType implementationType) {
Assert.notNull(field, "Field must not be null");
implementationType = (implementationType == null ? NONE : implementationType);
ResolvableType owner = implementationType.as(field.getDeclaringClass());
return forType(null, new FieldTypeProvider(field), owner.asVariableResolver());
}
/**
* Return a {@link ResolvableType} for the specified {@link Field} with the
* given nesting level.
@@ -963,7 +980,25 @@ public final class ResolvableType implements Serializable {
* @see #forMethodParameter(Method, int)
*/
public static ResolvableType forMethodParameter(MethodParameter methodParameter) {
return forMethodParameter(methodParameter, null);
return forMethodParameter(methodParameter, (Type) null);
}
/**
* Return a {@link ResolvableType} for the specified {@link MethodParameter} with a
* given implementation type. Use this variant when the class that declares the method
* includes generic parameter variables that are satisfied by the implementation type.
* @param methodParameter the source method parameter (must not be {@code null})
* @param implementationType the implementation type
* @return a {@link ResolvableType} for the specified method parameter
* @see #forMethodParameter(MethodParameter)
*/
public static ResolvableType forMethodParameter(MethodParameter methodParameter, ResolvableType implementationType) {
Assert.notNull(methodParameter, "MethodParameter must not be null");
implementationType = (implementationType == null ? forType(methodParameter.getContainingClass()) : implementationType);
ResolvableType owner = implementationType.as(methodParameter.getDeclaringClass());
return forType(null, new MethodParameterTypeProvider(methodParameter),
owner.asVariableResolver()).getNested(methodParameter.getNestingLevel(),
methodParameter.typeIndexesPerLevel);
}
/**