/** * Return a {@link ResolvableType} for the specified {@link Type} backed by the given * owner type. * <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}. * @param type the source type or {@code null} * @param owner the owner type used to resolve variables * @return a {@link ResolvableType} for the specified {@link Type} and owner * @see #forType(Type) */ public static ResolvableType forType(@Nullable Type type, @Nullable ResolvableType owner) { VariableResolver variableResolver = null; if (owner != null) { variableResolver = owner.asVariableResolver(); } return forType(type, variableResolver); }
/** * 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, @Nullable ResolvableType implementationType) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = (implementationType != null ? implementationType : NONE); owner = owner.as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()); }
/** * Return a {@link ResolvableType} for the specified {@link Type} backed by the given * owner type. * <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}. * @param type the source type or {@code null} * @param owner the owner type used to resolve variables * @return a {@link ResolvableType} for the specified {@link Type} and owner * @see #forType(Type) */ public static ResolvableType forType(@Nullable Type type, @Nullable ResolvableType owner) { VariableResolver variableResolver = null; if (owner != null) { variableResolver = owner.asVariableResolver(); } return forType(type, variableResolver); }
/** * 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 class. * @param field the source field * @param implementationClass the implementation class * @return a {@link ResolvableType} for the specified field * @see #forField(Field) */ public static ResolvableType forField(Field field, Class<?> implementationClass) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = forType(implementationClass).as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()); }
/** * Return a {@link ResolvableType} for the specified {@link Field} with a given * implementation and the given nesting level. * <p>Use this variant when the class that declares the field includes generic * parameter variables that are satisfied by the implementation class. * @param field the source field * @param nestingLevel the nesting level (1 for the outer level; 2 for a nested * generic type; etc) * @param implementationClass the implementation class * @return a {@link ResolvableType} for the specified field * @see #forField(Field) */ public static ResolvableType forField(Field field, int nestingLevel, @Nullable Class<?> implementationClass) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = forType(implementationClass).as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()).getNested(nestingLevel); }
/** * 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, @Nullable ResolvableType implementationType) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = (implementationType != null ? implementationType : NONE); owner = owner.as(field.getDeclaringClass()); 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 class. * @param field the source field * @param implementationClass the implementation class * @return a {@link ResolvableType} for the specified field * @see #forField(Field) */ public static ResolvableType forField(Field field, Class<?> implementationClass) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = forType(implementationClass).as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()); }
/** * Return a {@link ResolvableType} for the specified {@link Field} with a given * implementation and the given nesting level. * <p>Use this variant when the class that declares the field includes generic * parameter variables that are satisfied by the implementation class. * @param field the source field * @param nestingLevel the nesting level (1 for the outer level; 2 for a nested * generic type; etc) * @param implementationClass the implementation class * @return a {@link ResolvableType} for the specified field * @see #forField(Field) */ public static ResolvableType forField(Field field, int nestingLevel, @Nullable Class<?> implementationClass) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = forType(implementationClass).as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()).getNested(nestingLevel); }
/** * Return a {@link ResolvableType} for the specified {@link MethodParameter}, * overriding the target type to resolve with a specific given type. * @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) * @return a {@link ResolvableType} for the specified method parameter * @see #forMethodParameter(Method, int) */ public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * 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, @Nullable ResolvableType implementationType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); implementationType = (implementationType != null ? implementationType : forType(methodParameter.getContainingClass())); ResolvableType owner = implementationType.as(methodParameter.getDeclaringClass()); return forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * Resolve the top-level parameter type of the given {@code MethodParameter}. * @param methodParameter the method parameter to resolve * @since 4.1.9 * @see MethodParameter#setParameterType */ static void resolveMethodParameter(MethodParameter methodParameter) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); methodParameter.setParameterType( forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).resolve()); }
@Test public void resolveTypeVariableFromTypeWithVariableResolver() throws Exception { Type sourceType = Methods.class.getMethod("typedReturn").getGenericReturnType(); ResolvableType type = ResolvableType.forType( sourceType, ResolvableType.forClass(TypedMethods.class).as(Methods.class).asVariableResolver()); assertThat(type.resolve(), equalTo((Class) String.class)); assertThat(type.getType().toString(), equalTo("T")); }
/** * Return a {@link ResolvableType} for the specified {@link MethodParameter}, * overriding the target type to resolve with a specific given type. * @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) * @return a {@link ResolvableType} for the specified method parameter * @see #forMethodParameter(Method, int) */ public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * Resolve the top-level parameter type of the given {@code MethodParameter}. * @param methodParameter the method parameter to resolve * @since 4.1.9 * @see MethodParameter#setParameterType */ static void resolveMethodParameter(MethodParameter methodParameter) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); methodParameter.setParameterType( forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).resolve()); }
/** * 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, @Nullable ResolvableType implementationType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); implementationType = (implementationType != null ? implementationType : forType(methodParameter.getContainingClass())); ResolvableType owner = implementationType.as(methodParameter.getDeclaringClass()); return forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * Return a {@link ResolvableType} for the specified {@link Type} backed by the given * owner type. * <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}. * @param type the source type or {@code null} * @param owner the owner type used to resolve variables * @return a {@link ResolvableType} for the specified {@link Type} and owner * @see #forType(Type) */ public static ResolvableType forType(@Nullable Type type, @Nullable ResolvableType owner) { VariableResolver variableResolver = null; if (owner != null) { variableResolver = owner.asVariableResolver(); } return forType(type, variableResolver); }
/** * 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 class. * @param field the source field * @param implementationClass the implementation class * @return a {@link ResolvableType} for the specified field * @see #forField(Field) */ public static ResolvableType forField(Field field, Class<?> implementationClass) { Assert.notNull(field, "Field must not be null"); ResolvableType owner = forType(implementationClass).as(field.getDeclaringClass()); return forType(null, new FieldTypeProvider(field), owner.asVariableResolver()); }
/** * Return a {@link ResolvableType} for the specified {@link MethodParameter}, * overriding the target type to resolve with a specific given type. * @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) * @return a {@link ResolvableType} for the specified method parameter * @see #forMethodParameter(Method, int) */ public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()). getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * Return a {@link ResolvableType} for the specified {@link MethodParameter}, overriding the * target type to resolve with a specific given type. * * @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) * @return a {@link ResolvableType} for the specified method parameter * @see #forMethodParameter(Method, int) */ public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()) .getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel); }
/** * Resolve the top-level parameter type of the given {@code MethodParameter}. * @param methodParameter the method parameter to resolve * @since 4.1.9 * @see MethodParameter#setParameterType */ static void resolveMethodParameter(MethodParameter methodParameter) { Assert.notNull(methodParameter, "MethodParameter must not be null"); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); methodParameter.setParameterType( forType(null, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).resolve()); }