From fab854c906abe5ca5c2660fb0fe01e95314f6502 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 11 Aug 2017 15:29:17 +0200 Subject: [PATCH] =?UTF-8?q?DATACMNS-1138=20-=20TypeInformation.specialize(?= =?UTF-8?q?=E2=80=A6)=20now=20only=20specializes=20unresolved=20parameteri?= =?UTF-8?q?zed=20types.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Type specialization - i.e. enrichment of a raw type with a current generic context - is now only done if the current type is not yet resolved completely. This allows wildcarded target references to just fall back to the type to specialize, which will then by definition carry more generics information than the one to be specialized. --- .../util/ParameterizedTypeInformation.java | 10 ++++++++ .../util/ClassTypeInformationUnitTests.java | 25 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index 55e0ba812..7eb2db7fb 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -184,6 +184,16 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation return createInfo(type.getActualTypeArguments()[0]); } + /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#specialize(org.springframework.data.util.ClassTypeInformation) + */ + @Override + @SuppressWarnings("unchecked") + public TypeInformation specialize(ClassTypeInformation type) { + return isResolvedCompletely() ? (TypeInformation) type : super.specialize(type); + } + /* * (non-Javadoc) * @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object) diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index 1ad870e38..c7e5bf3de 100755 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -16,7 +16,7 @@ package org.springframework.data.util; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.util.ClassTypeInformation.*; +import static org.springframework.data.util.ClassTypeInformation.from; import javaslang.collection.Traversable; @@ -399,6 +399,17 @@ public class ClassTypeInformationUnitTests { assertThat(information.getMapValueType().getType()).isAssignableFrom(Integer.class); } + @Test // DATACMNS-1138 + public void usesTargetTypeForWildcardedBaseOnSpecialization() { + + ClassTypeInformation wrapper = ClassTypeInformation.from(WildcardedWrapper.class); + ClassTypeInformation concrete = ClassTypeInformation.from(SomeConcrete.class); + + TypeInformation property = wrapper.getRequiredProperty("wildcarded"); + + assertThat(property.specialize(concrete)).isEqualTo(concrete); + } + static class StringMapContainer extends MapContainer { } @@ -601,4 +612,16 @@ public class ClassTypeInformationUnitTests { static interface SampleTraversable extends Traversable {} static interface SampleMap extends javaslang.collection.Map {} + + // DATACMNS-1138 + + static class SomeGeneric { + T value; + } + + static class SomeConcrete extends SomeGeneric {} + + static class WildcardedWrapper { + SomeGeneric wildcarded; + } }