Undeprecate TypeVariableMap methods on GenericTypeResolver
Issue: SPR-15429
(cherry picked from commit 7fbc20e)
			
			
This commit is contained in:
		
							parent
							
								
									a3d199f4dd
								
							
						
					
					
						commit
						93fac8882f
					
				| 
						 | 
					@ -80,7 +80,6 @@ public abstract class GenericTypeResolver {
 | 
				
			||||||
	 * @param method the method to introspect
 | 
						 * @param method the method to introspect
 | 
				
			||||||
	 * @param clazz the class to resolve type variables against
 | 
						 * @param clazz the class to resolve type variables against
 | 
				
			||||||
	 * @return the corresponding generic parameter or return type
 | 
						 * @return the corresponding generic parameter or return type
 | 
				
			||||||
	 * @see #resolveReturnTypeForGenericMethod
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static Class<?> resolveReturnType(Method method, Class<?> clazz) {
 | 
						public static Class<?> resolveReturnType(Method method, Class<?> clazz) {
 | 
				
			||||||
		Assert.notNull(method, "Method must not be null");
 | 
							Assert.notNull(method, "Method must not be null");
 | 
				
			||||||
| 
						 | 
					@ -118,8 +117,9 @@ public abstract class GenericTypeResolver {
 | 
				
			||||||
	 * (may be {@code null})
 | 
						 * (may be {@code null})
 | 
				
			||||||
	 * @return the resolved target return type, the standard return type, or {@code null}
 | 
						 * @return the resolved target return type, the standard return type, or {@code null}
 | 
				
			||||||
	 * @since 3.2.5
 | 
						 * @since 3.2.5
 | 
				
			||||||
	 * @see #resolveReturnType
 | 
						 * @deprecated as of Spring Framework 4.3.8, superseded by {@link ResolvableType} usage
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
 | 
						@Deprecated
 | 
				
			||||||
	public static Class<?> resolveReturnTypeForGenericMethod(Method method, Object[] args, ClassLoader classLoader) {
 | 
						public static Class<?> resolveReturnTypeForGenericMethod(Method method, Object[] args, ClassLoader classLoader) {
 | 
				
			||||||
		Assert.notNull(method, "Method must not be null");
 | 
							Assert.notNull(method, "Method must not be null");
 | 
				
			||||||
		Assert.notNull(args, "Argument array must not be null");
 | 
							Assert.notNull(args, "Argument array must not be null");
 | 
				
			||||||
| 
						 | 
					@ -250,12 +250,11 @@ public abstract class GenericTypeResolver {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Resolve the specified generic type against the given TypeVariable map.
 | 
						 * Resolve the specified generic type against the given TypeVariable map.
 | 
				
			||||||
 | 
						 * <p>Used by Spring Data.
 | 
				
			||||||
	 * @param genericType the generic type to resolve
 | 
						 * @param genericType the generic type to resolve
 | 
				
			||||||
	 * @param map the TypeVariable Map to resolved against
 | 
						 * @param map the TypeVariable Map to resolved against
 | 
				
			||||||
	 * @return the type if it resolves to a Class, or {@code Object.class} otherwise
 | 
						 * @return the type if it resolves to a Class, or {@code Object.class} otherwise
 | 
				
			||||||
	 * @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@Deprecated
 | 
					 | 
				
			||||||
	@SuppressWarnings("rawtypes")
 | 
						@SuppressWarnings("rawtypes")
 | 
				
			||||||
	public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) {
 | 
						public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) {
 | 
				
			||||||
		return ResolvableType.forType(genericType, new TypeVariableMapVariableResolver(map)).resolve(Object.class);
 | 
							return ResolvableType.forType(genericType, new TypeVariableMapVariableResolver(map)).resolve(Object.class);
 | 
				
			||||||
| 
						 | 
					@ -263,11 +262,10 @@ public abstract class GenericTypeResolver {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Build a mapping of {@link TypeVariable#getName TypeVariable names} to
 | 
						 * Build a mapping of {@link TypeVariable#getName TypeVariable names} to
 | 
				
			||||||
	 * {@link Class concrete classes} for the specified {@link Class}. Searches
 | 
						 * {@link Class concrete classes} for the specified {@link Class}.
 | 
				
			||||||
	 * all super types, enclosing types and interfaces.
 | 
						 * Searches all super types, enclosing types and interfaces.
 | 
				
			||||||
	 * @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
 | 
						 * @see #resolveType(Type, Map)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@Deprecated
 | 
					 | 
				
			||||||
	@SuppressWarnings("rawtypes")
 | 
						@SuppressWarnings("rawtypes")
 | 
				
			||||||
	public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
 | 
						public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
 | 
				
			||||||
		Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz);
 | 
							Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2002-2015 the original author or authors.
 | 
					 * Copyright 2002-2017 the original author or authors.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 * you may not use this file except in compliance with the License.
 | 
					 * you may not use this file except in compliance with the License.
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,7 @@ import static org.springframework.util.ReflectionUtils.*;
 | 
				
			||||||
 * @author Juergen Hoeller
 | 
					 * @author Juergen Hoeller
 | 
				
			||||||
 * @author Sam Brannen
 | 
					 * @author Sam Brannen
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
 | 
					@SuppressWarnings({"unchecked", "rawtypes"})
 | 
				
			||||||
public class GenericTypeResolverTests {
 | 
					public class GenericTypeResolverTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					@ -61,7 +61,7 @@ public class GenericTypeResolverTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void nullIfNotResolvable() {
 | 
						public void nullIfNotResolvable() {
 | 
				
			||||||
		GenericClass<String> obj = new GenericClass<String>();
 | 
							GenericClass<String> obj = new GenericClass<>();
 | 
				
			||||||
		assertNull(resolveTypeArgument(obj.getClass(), GenericClass.class));
 | 
							assertNull(resolveTypeArgument(obj.getClass(), GenericClass.class));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,18 +77,17 @@ public class GenericTypeResolverTests {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	@Deprecated
 | 
					 | 
				
			||||||
	public void testResolveType() {
 | 
						public void testResolveType() {
 | 
				
			||||||
		Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
 | 
							Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
 | 
				
			||||||
		MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
 | 
							MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
 | 
				
			||||||
		assertEquals(MyInterfaceType.class,
 | 
							assertEquals(MyInterfaceType.class,
 | 
				
			||||||
				resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
 | 
									resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<>()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Method intArrMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerArrayInputMessage",
 | 
							Method intArrMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerArrayInputMessage",
 | 
				
			||||||
				MyInterfaceType[].class);
 | 
									MyInterfaceType[].class);
 | 
				
			||||||
		MethodParameter intArrMessageMethodParam = new MethodParameter(intArrMessageMethod, 0);
 | 
							MethodParameter intArrMessageMethodParam = new MethodParameter(intArrMessageMethod, 0);
 | 
				
			||||||
		assertEquals(MyInterfaceType[].class,
 | 
							assertEquals(MyInterfaceType[].class,
 | 
				
			||||||
				resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
 | 
									resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<>()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Method genericArrMessageMethod = findMethod(MySimpleTypeWithMethods.class, "readGenericArrayInputMessage",
 | 
							Method genericArrMessageMethod = findMethod(MySimpleTypeWithMethods.class, "readGenericArrayInputMessage",
 | 
				
			||||||
				Object[].class);
 | 
									Object[].class);
 | 
				
			||||||
| 
						 | 
					@ -103,7 +102,6 @@ public class GenericTypeResolverTests {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	@Deprecated
 | 
					 | 
				
			||||||
	public void testGetTypeVariableMap() throws Exception {
 | 
						public void testGetTypeVariableMap() throws Exception {
 | 
				
			||||||
		Map<TypeVariable, Type> map;
 | 
							Map<TypeVariable, Type> map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,40 +139,35 @@ public class GenericTypeResolverTests {
 | 
				
			||||||
		assertThat(x, equalTo((Type) Long.class));
 | 
							assertThat(x, equalTo((Type) Long.class));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test  // SPR-11030
 | 
				
			||||||
	public void getGenericsCannotBeResolved() throws Exception {
 | 
						public void getGenericsCannotBeResolved() throws Exception {
 | 
				
			||||||
		// SPR-11030
 | 
					 | 
				
			||||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
 | 
							Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
 | 
				
			||||||
		assertNull(resolved);
 | 
							assertNull(resolved);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test  // SPR-11052
 | 
				
			||||||
	public void getRawMapTypeCannotBeResolved() throws Exception {
 | 
						public void getRawMapTypeCannotBeResolved() throws Exception {
 | 
				
			||||||
		// SPR-11052
 | 
					 | 
				
			||||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(Map.class, Map.class);
 | 
							Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(Map.class, Map.class);
 | 
				
			||||||
		assertNull(resolved);
 | 
							assertNull(resolved);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test  // SPR-11044
 | 
				
			||||||
	public void getGenericsOnArrayFromParamCannotBeResolved() throws Exception {
 | 
						public void getGenericsOnArrayFromParamCannotBeResolved() throws Exception {
 | 
				
			||||||
		// SPR-11044
 | 
					 | 
				
			||||||
		MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(
 | 
							MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(
 | 
				
			||||||
				WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0);
 | 
									WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0);
 | 
				
			||||||
		Class<?> resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class);
 | 
							Class<?> resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class);
 | 
				
			||||||
		assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
							assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test  // SPR-11044
 | 
				
			||||||
	public void getGenericsOnArrayFromReturnCannotBeResolved() throws Exception {
 | 
						public void getGenericsOnArrayFromReturnCannotBeResolved() throws Exception {
 | 
				
			||||||
		// SPR-11044
 | 
					 | 
				
			||||||
		Class<?> resolved = GenericTypeResolver.resolveReturnType(
 | 
							Class<?> resolved = GenericTypeResolver.resolveReturnType(
 | 
				
			||||||
				WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class);
 | 
									WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class);
 | 
				
			||||||
		assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
							assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test  // SPR-11763
 | 
				
			||||||
	public void resolveIncompleteTypeVariables() {
 | 
						public void resolveIncompleteTypeVariables() {
 | 
				
			||||||
		// SPR-11763
 | 
					 | 
				
			||||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(IdFixingRepository.class, Repository.class);
 | 
							Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(IdFixingRepository.class, Repository.class);
 | 
				
			||||||
		assertNotNull(resolved);
 | 
							assertNotNull(resolved);
 | 
				
			||||||
		assertEquals(2, resolved.length);
 | 
							assertEquals(2, resolved.length);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue