Skip to content

Commit 48db42c

Browse files
committed
DATACMNS-1180 - Polishing.
Avoid premature resolution of type in TypeDiscoverer.createInfo(…) and thereby simplify constructor in ParameterizedTypeInformation.
1 parent baee26e commit 48db42c

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
5151
* @param type must not be {@literal null}
5252
* @param parent must not be {@literal null}
5353
*/
54-
public ParameterizedTypeInformation(ParameterizedType type, Class<?> resolvedType, TypeDiscoverer<?> parent) {
54+
public ParameterizedTypeInformation(ParameterizedType type, TypeDiscoverer<?> parent) {
5555

56-
super(type, parent, calculateTypeVariables(type, resolvedType, parent));
56+
super(type, parent, calculateTypeVariables(type, parent));
5757

5858
this.type = type;
5959
this.resolved = Lazy.of(() -> isResolvedCompletely());
@@ -248,13 +248,12 @@ private boolean isResolvedCompletely() {
248248
* declared.
249249
*
250250
* @param type must not be {@literal null}.
251-
* @param resolvedType must not be {@literal null}.
252251
* @param parent must not be {@literal null}.
253252
* @return will never be {@literal null}.
254253
*/
255-
private static Map<TypeVariable<?>, Type> calculateTypeVariables(ParameterizedType type, Class<?> resolvedType,
256-
TypeDiscoverer<?> parent) {
254+
private static Map<TypeVariable<?>, Type> calculateTypeVariables(ParameterizedType type, TypeDiscoverer<?> parent) {
257255

256+
Class<?> resolvedType = parent.resolveType(type);
258257
TypeVariable<?>[] typeParameters = resolvedType.getTypeParameters();
259258
Type[] arguments = type.getActualTypeArguments();
260259

src/main/java/org/springframework/data/util/TypeDiscoverer.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ protected TypeInformation<?> createInfo(Type fieldType) {
129129
return ClassTypeInformation.from((Class<?>) fieldType);
130130
}
131131

132-
Class<S> resolvedType = resolveType(fieldType);
133-
134132
if (fieldType instanceof ParameterizedType) {
135133

136134
ParameterizedType parameterizedType = (ParameterizedType) fieldType;
137-
return new ParameterizedTypeInformation(parameterizedType, resolvedType, this);
135+
return new ParameterizedTypeInformation(parameterizedType, this);
138136
}
139137

140138
if (fieldType instanceof TypeVariable) {

src/test/java/org/springframework/data/util/ParameterizedTypeInformationUnitTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.junit.runner.RunWith;
3333
import org.mockito.Mock;
3434
import org.mockito.junit.MockitoJUnitRunner;
35-
import org.springframework.core.GenericTypeResolver;
3635

3736
/**
3837
* Unit tests for {@link ParameterizedTypeInformation}.
@@ -44,12 +43,10 @@
4443
public class ParameterizedTypeInformationUnitTests {
4544

4645
@Mock ParameterizedType one;
47-
Class<?> resolvedOne;
4846

4947
@Before
5048
public void setUp() {
5149
when(one.getActualTypeArguments()).thenReturn(new Type[0]);
52-
this.resolvedOne = GenericTypeResolver.resolveType(one, emptyMap());
5350
}
5451

5552
@Test
@@ -58,8 +55,8 @@ public void considersTypeInformationsWithDifferingParentsNotEqual() {
5855
TypeDiscoverer<String> stringParent = new TypeDiscoverer<>(String.class, emptyMap());
5956
TypeDiscoverer<Object> objectParent = new TypeDiscoverer<>(Object.class, emptyMap());
6057

61-
ParameterizedTypeInformation<Object> first = new ParameterizedTypeInformation<>(one, resolvedOne, stringParent);
62-
ParameterizedTypeInformation<Object> second = new ParameterizedTypeInformation<>(one, resolvedOne, objectParent);
58+
ParameterizedTypeInformation<Object> first = new ParameterizedTypeInformation<>(one, stringParent);
59+
ParameterizedTypeInformation<Object> second = new ParameterizedTypeInformation<>(one, objectParent);
6360

6461
assertThat(first).isNotEqualTo(second);
6562
}
@@ -69,8 +66,8 @@ public void considersTypeInformationsWithSameParentsNotEqual() {
6966

7067
TypeDiscoverer<String> stringParent = new TypeDiscoverer<>(String.class, emptyMap());
7168

72-
ParameterizedTypeInformation<Object> first = new ParameterizedTypeInformation<>(one, resolvedOne, stringParent);
73-
ParameterizedTypeInformation<Object> second = new ParameterizedTypeInformation<>(one, resolvedOne, stringParent);
69+
ParameterizedTypeInformation<Object> first = new ParameterizedTypeInformation<>(one, stringParent);
70+
ParameterizedTypeInformation<Object> second = new ParameterizedTypeInformation<>(one, stringParent);
7471

7572
assertThat(first.equals(second)).isTrue();
7673
}

0 commit comments

Comments
 (0)