Skip to content

Commit 93fac88

Browse files
committed
Undeprecate TypeVariableMap methods on GenericTypeResolver
Issue: SPR-15429 (cherry picked from commit 7fbc20e)
1 parent a3d199f commit 93fac88

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public static Class<?> resolveParameterType(MethodParameter methodParameter, Cla
8080
* @param method the method to introspect
8181
* @param clazz the class to resolve type variables against
8282
* @return the corresponding generic parameter or return type
83-
* @see #resolveReturnTypeForGenericMethod
8483
*/
8584
public static Class<?> resolveReturnType(Method method, Class<?> clazz) {
8685
Assert.notNull(method, "Method must not be null");
@@ -118,8 +117,9 @@ public static Class<?> resolveReturnType(Method method, Class<?> clazz) {
118117
* (may be {@code null})
119118
* @return the resolved target return type, the standard return type, or {@code null}
120119
* @since 3.2.5
121-
* @see #resolveReturnType
120+
* @deprecated as of Spring Framework 4.3.8, superseded by {@link ResolvableType} usage
122121
*/
122+
@Deprecated
123123
public static Class<?> resolveReturnTypeForGenericMethod(Method method, Object[] args, ClassLoader classLoader) {
124124
Assert.notNull(method, "Method must not be null");
125125
Assert.notNull(args, "Argument array must not be null");
@@ -250,24 +250,22 @@ public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIf
250250

251251
/**
252252
* Resolve the specified generic type against the given TypeVariable map.
253+
* <p>Used by Spring Data.
253254
* @param genericType the generic type to resolve
254255
* @param map the TypeVariable Map to resolved against
255256
* @return the type if it resolves to a Class, or {@code Object.class} otherwise
256-
* @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
257257
*/
258-
@Deprecated
259258
@SuppressWarnings("rawtypes")
260259
public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) {
261260
return ResolvableType.forType(genericType, new TypeVariableMapVariableResolver(map)).resolve(Object.class);
262261
}
263262

264263
/**
265264
* Build a mapping of {@link TypeVariable#getName TypeVariable names} to
266-
* {@link Class concrete classes} for the specified {@link Class}. Searches
267-
* all super types, enclosing types and interfaces.
268-
* @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
265+
* {@link Class concrete classes} for the specified {@link Class}.
266+
* Searches all super types, enclosing types and interfaces.
267+
* @see #resolveType(Type, Map)
269268
*/
270-
@Deprecated
271269
@SuppressWarnings("rawtypes")
272270
public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
273271
Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz);

spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@
3636
* @author Juergen Hoeller
3737
* @author Sam Brannen
3838
*/
39-
@SuppressWarnings({ "unchecked", "rawtypes" })
39+
@SuppressWarnings({"unchecked", "rawtypes"})
4040
public class GenericTypeResolverTests {
4141

4242
@Test
@@ -61,7 +61,7 @@ public void simpleCollectionSuperclassType() {
6161

6262
@Test
6363
public void nullIfNotResolvable() {
64-
GenericClass<String> obj = new GenericClass<String>();
64+
GenericClass<String> obj = new GenericClass<>();
6565
assertNull(resolveTypeArgument(obj.getClass(), GenericClass.class));
6666
}
6767

@@ -77,18 +77,17 @@ public void methodReturnTypes() {
7777
}
7878

7979
@Test
80-
@Deprecated
8180
public void testResolveType() {
8281
Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
8382
MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
8483
assertEquals(MyInterfaceType.class,
85-
resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
84+
resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<>()));
8685

8786
Method intArrMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerArrayInputMessage",
8887
MyInterfaceType[].class);
8988
MethodParameter intArrMessageMethodParam = new MethodParameter(intArrMessageMethod, 0);
9089
assertEquals(MyInterfaceType[].class,
91-
resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
90+
resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<>()));
9291

9392
Method genericArrMessageMethod = findMethod(MySimpleTypeWithMethods.class, "readGenericArrayInputMessage",
9493
Object[].class);
@@ -103,7 +102,6 @@ public void testBoundParameterizedType() {
103102
}
104103

105104
@Test
106-
@Deprecated
107105
public void testGetTypeVariableMap() throws Exception {
108106
Map<TypeVariable, Type> map;
109107

@@ -141,40 +139,35 @@ public void testGetTypeVariableMap() throws Exception {
141139
assertThat(x, equalTo((Type) Long.class));
142140
}
143141

144-
@Test
142+
@Test // SPR-11030
145143
public void getGenericsCannotBeResolved() throws Exception {
146-
// SPR-11030
147144
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
148145
assertNull(resolved);
149146
}
150147

151-
@Test
148+
@Test // SPR-11052
152149
public void getRawMapTypeCannotBeResolved() throws Exception {
153-
// SPR-11052
154150
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(Map.class, Map.class);
155151
assertNull(resolved);
156152
}
157153

158-
@Test
154+
@Test // SPR-11044
159155
public void getGenericsOnArrayFromParamCannotBeResolved() throws Exception {
160-
// SPR-11044
161156
MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(
162157
WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0);
163158
Class<?> resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class);
164159
assertThat(resolved, equalTo((Class<?>) Object[].class));
165160
}
166161

167-
@Test
162+
@Test // SPR-11044
168163
public void getGenericsOnArrayFromReturnCannotBeResolved() throws Exception {
169-
// SPR-11044
170164
Class<?> resolved = GenericTypeResolver.resolveReturnType(
171165
WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class);
172166
assertThat(resolved, equalTo((Class<?>) Object[].class));
173167
}
174168

175-
@Test
169+
@Test // SPR-11763
176170
public void resolveIncompleteTypeVariables() {
177-
// SPR-11763
178171
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(IdFixingRepository.class, Repository.class);
179172
assertNotNull(resolved);
180173
assertEquals(2, resolved.length);

0 commit comments

Comments
 (0)