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 clazz the class to resolve type variables against
 | 
			
		||||
	 * @return the corresponding generic parameter or return type
 | 
			
		||||
	 * @see #resolveReturnTypeForGenericMethod
 | 
			
		||||
	 */
 | 
			
		||||
	public static Class<?> resolveReturnType(Method method, Class<?> clazz) {
 | 
			
		||||
		Assert.notNull(method, "Method must not be null");
 | 
			
		||||
| 
						 | 
				
			
			@ -118,8 +117,9 @@ public abstract class GenericTypeResolver {
 | 
			
		|||
	 * (may be {@code null})
 | 
			
		||||
	 * @return the resolved target return type, the standard return type, or {@code null}
 | 
			
		||||
	 * @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) {
 | 
			
		||||
		Assert.notNull(method, "Method 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.
 | 
			
		||||
	 * <p>Used by Spring Data.
 | 
			
		||||
	 * @param genericType the generic type to resolve
 | 
			
		||||
	 * @param map the TypeVariable Map to resolved against
 | 
			
		||||
	 * @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")
 | 
			
		||||
	public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) {
 | 
			
		||||
		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
 | 
			
		||||
	 * {@link Class concrete classes} for the specified {@link Class}. Searches
 | 
			
		||||
	 * all super types, enclosing types and interfaces.
 | 
			
		||||
	 * @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
 | 
			
		||||
	 * {@link Class concrete classes} for the specified {@link Class}.
 | 
			
		||||
	 * Searches all super types, enclosing types and interfaces.
 | 
			
		||||
	 * @see #resolveType(Type, Map)
 | 
			
		||||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	@SuppressWarnings("rawtypes")
 | 
			
		||||
	public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> 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");
 | 
			
		||||
 * 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 Sam Brannen
 | 
			
		||||
 */
 | 
			
		||||
@SuppressWarnings({ "unchecked", "rawtypes" })
 | 
			
		||||
@SuppressWarnings({"unchecked", "rawtypes"})
 | 
			
		||||
public class GenericTypeResolverTests {
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ public class GenericTypeResolverTests {
 | 
			
		|||
 | 
			
		||||
	@Test
 | 
			
		||||
	public void nullIfNotResolvable() {
 | 
			
		||||
		GenericClass<String> obj = new GenericClass<String>();
 | 
			
		||||
		GenericClass<String> obj = new GenericClass<>();
 | 
			
		||||
		assertNull(resolveTypeArgument(obj.getClass(), GenericClass.class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -77,18 +77,17 @@ public class GenericTypeResolverTests {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public void testResolveType() {
 | 
			
		||||
		Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
 | 
			
		||||
		MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
 | 
			
		||||
		assertEquals(MyInterfaceType.class,
 | 
			
		||||
				resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
 | 
			
		||||
				resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<>()));
 | 
			
		||||
 | 
			
		||||
		Method intArrMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerArrayInputMessage",
 | 
			
		||||
				MyInterfaceType[].class);
 | 
			
		||||
		MethodParameter intArrMessageMethodParam = new MethodParameter(intArrMessageMethod, 0);
 | 
			
		||||
		assertEquals(MyInterfaceType[].class,
 | 
			
		||||
				resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
 | 
			
		||||
				resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<>()));
 | 
			
		||||
 | 
			
		||||
		Method genericArrMessageMethod = findMethod(MySimpleTypeWithMethods.class, "readGenericArrayInputMessage",
 | 
			
		||||
				Object[].class);
 | 
			
		||||
| 
						 | 
				
			
			@ -103,7 +102,6 @@ public class GenericTypeResolverTests {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public void testGetTypeVariableMap() throws Exception {
 | 
			
		||||
		Map<TypeVariable, Type> map;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -141,40 +139,35 @@ public class GenericTypeResolverTests {
 | 
			
		|||
		assertThat(x, equalTo((Type) Long.class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Test  // SPR-11030
 | 
			
		||||
	public void getGenericsCannotBeResolved() throws Exception {
 | 
			
		||||
		// SPR-11030
 | 
			
		||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
 | 
			
		||||
		assertNull(resolved);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Test  // SPR-11052
 | 
			
		||||
	public void getRawMapTypeCannotBeResolved() throws Exception {
 | 
			
		||||
		// SPR-11052
 | 
			
		||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(Map.class, Map.class);
 | 
			
		||||
		assertNull(resolved);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Test  // SPR-11044
 | 
			
		||||
	public void getGenericsOnArrayFromParamCannotBeResolved() throws Exception {
 | 
			
		||||
		// SPR-11044
 | 
			
		||||
		MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(
 | 
			
		||||
				WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0);
 | 
			
		||||
		Class<?> resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class);
 | 
			
		||||
		assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Test  // SPR-11044
 | 
			
		||||
	public void getGenericsOnArrayFromReturnCannotBeResolved() throws Exception {
 | 
			
		||||
		// SPR-11044
 | 
			
		||||
		Class<?> resolved = GenericTypeResolver.resolveReturnType(
 | 
			
		||||
				WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class);
 | 
			
		||||
		assertThat(resolved, equalTo((Class<?>) Object[].class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	@Test  // SPR-11763
 | 
			
		||||
	public void resolveIncompleteTypeVariables() {
 | 
			
		||||
		// SPR-11763
 | 
			
		||||
		Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(IdFixingRepository.class, Repository.class);
 | 
			
		||||
		assertNotNull(resolved);
 | 
			
		||||
		assertEquals(2, resolved.length);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue