From 8638d30a004aad5904105794385058cfc65c7c3f 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 | 9 +++++++ .../util/ClassTypeInformationUnitTests.java | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index d7075911c..88a8a2fc4 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -181,6 +181,15 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation } /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#specialize(org.springframework.data.util.ClassTypeInformation) + */ + @Override + public TypeInformation specialize(ClassTypeInformation type) { + return isResolvedCompletely() ? 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 43ce4dea0..2f17a0574 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -392,6 +392,18 @@ public class ClassTypeInformationUnitTests { assertThat(information.getMapValueType().getType(), is(typeCompatibleWith(Integer.class))); } + @Test // DATACMNS-1138 + @SuppressWarnings("rawtypes") + public void usesTargetTypeForWildcardedBaseOnSpecialization() { + + ClassTypeInformation wrapper = ClassTypeInformation.from(WildcardedWrapper.class); + ClassTypeInformation concrete = ClassTypeInformation.from(SomeConcrete.class); + + TypeInformation property = wrapper.getProperty("wildcarded"); + + assertThat(property.specialize(concrete), is((TypeInformation) concrete)); + } + static class StringMapContainer extends MapContainer { } @@ -594,4 +606,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; + } }