DATACMNS-1138 - TypeInformation.specialize(…) now only specializes unresolved parameterized types.

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.
This commit is contained in:
Oliver Gierke
2017-08-11 15:29:17 +02:00
parent e7434a0e77
commit 8638d30a00
2 changed files with 33 additions and 0 deletions

View File

@@ -181,6 +181,15 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
}
/*
* (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)
*/

View File

@@ -392,6 +392,18 @@ public class ClassTypeInformationUnitTests {
assertThat(information.getMapValueType().getType(), is(typeCompatibleWith(Integer.class)));
}
@Test // DATACMNS-1138
@SuppressWarnings("rawtypes")
public void usesTargetTypeForWildcardedBaseOnSpecialization() {
ClassTypeInformation<WildcardedWrapper> wrapper = ClassTypeInformation.from(WildcardedWrapper.class);
ClassTypeInformation<SomeConcrete> concrete = ClassTypeInformation.from(SomeConcrete.class);
TypeInformation<?> property = wrapper.getProperty("wildcarded");
assertThat(property.specialize(concrete), is((TypeInformation) concrete));
}
static class StringMapContainer extends MapContainer<String> {
}
@@ -594,4 +606,16 @@ public class ClassTypeInformationUnitTests {
static interface SampleTraversable extends Traversable<Integer> {}
static interface SampleMap extends javaslang.collection.Map<String, Integer> {}
// DATACMNS-1138
static class SomeGeneric<T> {
T value;
}
static class SomeConcrete extends SomeGeneric<String> {}
static class WildcardedWrapper {
SomeGeneric<?> wildcarded;
}
}