Skip to content

Commit b55f098

Browse files
committed
Remove references to ClassTypeInformation from TypeInformation.
Closes #2703
1 parent 1ff6e39 commit b55f098

File tree

9 files changed

+43
-89
lines changed

9 files changed

+43
-89
lines changed

src/main/java/org/springframework/data/convert/MappingContextTypeInformationMapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.data.mapping.PersistentEntity;
2323
import org.springframework.data.mapping.PersistentProperty;
2424
import org.springframework.data.mapping.context.MappingContext;
25-
import org.springframework.data.util.ClassTypeInformation;
2625
import org.springframework.data.util.TypeInformation;
2726
import org.springframework.lang.Nullable;
2827
import org.springframework.util.Assert;
@@ -38,7 +37,7 @@
3837
*/
3938
public class MappingContextTypeInformationMapper implements TypeInformationMapper {
4039

41-
private final Map<ClassTypeInformation<?>, Alias> typeMap;
40+
private final Map<TypeInformation<?>, Alias> typeMap;
4241
private final MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext;
4342

4443
/**
@@ -79,7 +78,7 @@ public Alias createAliasFor(TypeInformation<?> type) {
7978
* @param key must not be {@literal null}.
8079
* @param alias can be {@literal null}.
8180
*/
82-
private Alias verify(ClassTypeInformation<?> key, Alias alias) {
81+
private Alias verify(TypeInformation<?> key, Alias alias) {
8382

8483
// Reject second alias for same type
8584

@@ -113,7 +112,7 @@ private Alias verify(ClassTypeInformation<?> key, Alias alias) {
113112
@Override
114113
public TypeInformation<?> resolveTypeFrom(Alias alias) {
115114

116-
for (Map.Entry<ClassTypeInformation<?>, Alias> entry : typeMap.entrySet()) {
115+
for (Map.Entry<TypeInformation<?>, Alias> entry : typeMap.entrySet()) {
117116
if (entry.getValue().hasSamePresentValueAs(alias)) {
118117
return entry.getKey();
119118
}

src/main/java/org/springframework/data/convert/ValueConversionContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.convert;
1717

1818
import org.springframework.data.mapping.PersistentProperty;
19-
import org.springframework.data.util.ClassTypeInformation;
2019
import org.springframework.data.util.TypeInformation;
2120
import org.springframework.lang.NonNull;
2221
import org.springframework.lang.Nullable;
@@ -65,7 +64,7 @@ default Object write(@Nullable Object value) {
6564
* @return can be {@literal null}.
6665
* @throws IllegalStateException if value cannot be written as an instance of {@link Class type}.
6766
* @see #write(Object, TypeInformation)
68-
* @see ClassTypeInformation
67+
* @see TypeInformation
6968
*/
7069
@Nullable
7170
default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
@@ -115,7 +114,7 @@ default Object read(@Nullable Object value) {
115114
* @return can be {@literal null}.
116115
* @throws IllegalStateException if value cannot be read as an instance of {@link Class type}.
117116
* @see #read(Object, TypeInformation)
118-
* @see ClassTypeInformation
117+
* @see TypeInformation
119118
*/
120119
@Nullable
121120
default <T> T read(@Nullable Object value, @NonNull Class<T> target) {

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
2727

28-
import org.springframework.data.util.ClassTypeInformation;
2928
import org.springframework.data.util.Streamable;
3029
import org.springframework.data.util.TypeInformation;
3130
import org.springframework.lang.Nullable;

src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.data.mapping.PersistentPropertyPaths;
2929
import org.springframework.data.mapping.PropertyHandler;
3030
import org.springframework.data.mapping.PropertyPath;
31-
import org.springframework.data.util.ClassTypeInformation;
3231
import org.springframework.data.util.Pair;
3332
import org.springframework.data.util.StreamUtils;
3433
import org.springframework.data.util.TypeInformation;

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
* @author Christoph Strobl
3434
* @deprecated since 3.0 to go package protected at some point. Refer to {@link TypeInformation} only.
3535
*/
36-
@Deprecated
36+
@Deprecated(since = "3.0", forRemoval = true)
3737
@SuppressWarnings({ "rawtypes", "unchecked" })
3838
public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
3939

4040
private static final ConcurrentLruCache<ResolvableType, ClassTypeInformation<?>> cache = new ConcurrentLruCache<>(64,
4141
ClassTypeInformation::new);
4242

43-
@Deprecated public static final ClassTypeInformation<Collection> COLLECTION;
44-
@Deprecated public static final ClassTypeInformation<List> LIST;
45-
@Deprecated public static final ClassTypeInformation<Set> SET;
46-
@Deprecated public static final ClassTypeInformation<Map> MAP;
47-
@Deprecated public static final ClassTypeInformation<Object> OBJECT;
43+
public static final ClassTypeInformation<Collection> COLLECTION;
44+
public static final ClassTypeInformation<List> LIST;
45+
public static final ClassTypeInformation<Set> SET;
46+
public static final ClassTypeInformation<Map> MAP;
47+
public static final ClassTypeInformation<Object> OBJECT;
4848

4949
static {
5050

@@ -62,11 +62,6 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
6262
this.type = (Class<S>) type.resolve(Object.class);
6363
}
6464

65-
private ClassTypeInformation(Class<S> type) {
66-
super(ResolvableType.forClass(type));
67-
this.type = type;
68-
}
69-
7065
/**
7166
* @param <S>
7267
* @param type
@@ -75,10 +70,10 @@ private ClassTypeInformation(Class<S> type) {
7570
*/
7671
@Deprecated
7772
public static <S> ClassTypeInformation<S> from(Class<S> type) {
78-
return cti(ResolvableType.forClass(type));
73+
return from(ResolvableType.forClass(type));
7974
}
8075

81-
static <S> ClassTypeInformation<S> cti(ResolvableType type) {
76+
static <S> ClassTypeInformation<S> from(ResolvableType type) {
8277

8378
Assert.notNull(type, "Type must not be null");
8479

@@ -104,8 +99,7 @@ public static <S> TypeInformation<S> fromReturnTypeOf(Method method) {
10499
*/
105100
static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> actualType) {
106101

107-
var type = actualType == null
108-
? ResolvableType.forMethodReturnType(method)
102+
var type = actualType == null ? ResolvableType.forMethodReturnType(method)
109103
: ResolvableType.forMethodReturnType(method, actualType);
110104

111105
return TypeInformation.of(type);

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
* @author Jürgen Diez
4848
* @author Alessandro Nistico
4949
* @author Johannes Englmeier
50-
* @deprecated since 3.0 to go package protected at some point. Prefer to refer to {@link TypeInformation} instead.
5150
*/
52-
@Deprecated
5351
class TypeDiscoverer<S> implements TypeInformation<S> {
5452

5553
private static final ConcurrentLruCache<ResolvableType, TypeInformation<?>> CACHE = new ConcurrentLruCache<>(64,
@@ -124,8 +122,7 @@ public boolean isCollectionLike() {
124122
return type.isArray() //
125123
|| Iterable.class.equals(type) //
126124
|| Collection.class.isAssignableFrom(type) //
127-
|| Streamable.class.isAssignableFrom(type)
128-
|| CustomCollections.isCollection(type);
125+
|| Streamable.class.isAssignableFrom(type) || CustomCollections.isCollection(type);
129126
}
130127

131128
@Nullable
@@ -195,7 +192,7 @@ public TypeDescriptor toTypeDescriptor() {
195192
}
196193

197194
@Override
198-
public ClassTypeInformation<?> getRawTypeInformation() {
195+
public TypeInformation<?> getRawTypeInformation() {
199196
return new ClassTypeInformation<>(ResolvableType.forRawClass(resolvableType.toClass()));
200197
}
201198

@@ -257,13 +254,10 @@ public TypeInformation<?> getSuperTypeInformation(Class<?> superType) {
257254
return TypeInformation.of(resolvableSuperType);
258255
}
259256

260-
var noGenericsResolvable = !Arrays.stream(resolvableSuperType.resolveGenerics())
261-
.filter(it -> it != null)
262-
.findAny()
257+
var noGenericsResolvable = !Arrays.stream(resolvableSuperType.resolveGenerics()).filter(it -> it != null).findAny()
263258
.isPresent();
264259

265-
return noGenericsResolvable
266-
? new ClassTypeInformation<>(ResolvableType.forRawClass(superType))
260+
return noGenericsResolvable ? new ClassTypeInformation<>(ResolvableType.forRawClass(superType))
267261
: TypeInformation.of(resolvableSuperType);
268262
}
269263

@@ -299,17 +293,16 @@ private List<TypeInformation<?>> doGetTypeArguments() {
299293
}
300294

301295
return Arrays.stream(resolvableType.getGenerics())
302-
.<TypeInformation<?>> map(it -> it.resolve(Object.class) == null ? null : TypeInformation.of(it))
303-
.toList();
296+
.<TypeInformation<?>> map(it -> it.resolve(Object.class) == null ? null : TypeInformation.of(it)).toList();
304297
}
305298

306299
@Override
307300
@SuppressWarnings("unchecked")
308301
public TypeInformation<? extends S> specialize(TypeInformation<?> type) {
309302

310303
if (this.getTypeArguments().size() == type.getTypeArguments().size()) {
311-
return (TypeInformation<? extends S>) TypeInformation.of(
312-
ResolvableType.forClassWithGenerics(type.getType(), this.resolvableType.getGenerics()));
304+
return (TypeInformation<? extends S>) TypeInformation
305+
.of(ResolvableType.forClassWithGenerics(type.getType(), this.resolvableType.getGenerics()));
313306
}
314307

315308
return TypeInformation.of((Class<S>) type.getType());
@@ -380,10 +373,8 @@ private Optional<TypeInformation<?>> getPropertyInformation(String fieldname) {
380373
var rawType = getType();
381374
var field = ReflectionUtils.findField(rawType, fieldname);
382375

383-
return field != null
384-
? Optional.of(TypeInformation.of(ResolvableType.forField(field, resolvableType)))
385-
: Optional.ofNullable(BeanUtils.getPropertyDescriptor(rawType, fieldname))
386-
.map(it -> from(it, rawType))
376+
return field != null ? Optional.of(TypeInformation.of(ResolvableType.forField(field, resolvableType)))
377+
: Optional.ofNullable(BeanUtils.getPropertyDescriptor(rawType, fieldname)).map(it -> from(it, rawType))
387378
.map(TypeInformation::of);
388379
}
389380

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

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@
4242
@SuppressWarnings({ "deprecation", "rawtypes" })
4343
public interface TypeInformation<S> {
4444

45-
public static final TypeInformation<Collection> COLLECTION = ClassTypeInformation.COLLECTION;
46-
public static final TypeInformation<List> LIST = ClassTypeInformation.LIST;
47-
public static final TypeInformation<Set> SET = ClassTypeInformation.SET;
48-
public static final TypeInformation<Map> MAP = ClassTypeInformation.MAP;
49-
public static final TypeInformation<Object> OBJECT = ClassTypeInformation.OBJECT;
50-
51-
static TypeInformation<?> orObject(@Nullable ResolvableType type) {
52-
return type == null ? ClassTypeInformation.OBJECT : of(type);
53-
}
45+
TypeInformation<Collection> COLLECTION = ClassTypeInformation.COLLECTION;
46+
TypeInformation<List> LIST = ClassTypeInformation.LIST;
47+
TypeInformation<Set> SET = ClassTypeInformation.SET;
48+
TypeInformation<Map> MAP = ClassTypeInformation.MAP;
49+
TypeInformation<Object> OBJECT = ClassTypeInformation.OBJECT;
5450

5551
/**
5652
* Creates a new {@link TypeInformation} from the given {@link ResolvableType}.
@@ -63,11 +59,8 @@ public static TypeInformation<?> of(ResolvableType type) {
6359

6460
Assert.notNull(type, "Type must not be null");
6561

66-
return type.hasGenerics()
67-
|| (type.isArray() && type.getComponentType().hasGenerics()) //
68-
|| (type.getType() instanceof TypeVariable)
69-
? TypeDiscoverer.td(type)
70-
: ClassTypeInformation.cti(type);
62+
return type.hasGenerics() || (type.isArray() && type.getComponentType().hasGenerics()) //
63+
|| (type.getType() instanceof TypeVariable) ? TypeDiscoverer.td(type) : ClassTypeInformation.from(type);
7164
}
7265

7366
/**
@@ -108,8 +101,7 @@ public static TypeInformation<?> fromReturnTypeOf(Method method) {
108101
*/
109102
public static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> type) {
110103

111-
ResolvableType intermediate = type == null
112-
? ResolvableType.forMethodReturnType(method)
104+
ResolvableType intermediate = type == null ? ResolvableType.forMethodReturnType(method)
113105
: ResolvableType.forMethodReturnType(method, type);
114106

115107
return TypeInformation.of(intermediate);
@@ -161,8 +153,7 @@ default TypeInformation<?> getRequiredProperty(String property) {
161153
return typeInformation;
162154
}
163155

164-
throw new IllegalArgumentException(
165-
String.format("Could not find required property %s on %s", property, getType()));
156+
throw new IllegalArgumentException(String.format("Could not find required property %s on %s", property, getType()));
166157
}
167158

168159
/**
@@ -259,12 +250,11 @@ default TypeInformation<?> getUserTypeInformation() {
259250
}
260251

261252
/**
262-
* Returns a {@link ClassTypeInformation} to represent the {@link TypeInformation} of the raw type of the current
263-
* instance.
253+
* Returns a {@link TypeInformation} to represent the {@link TypeInformation} of the raw type of the current instance.
264254
*
265255
* @return
266256
*/
267-
ClassTypeInformation<?> getRawTypeInformation();
257+
TypeInformation<?> getRawTypeInformation();
268258

269259
/**
270260
* Transparently returns the {@link java.util.Map} value type if the type is a {@link java.util.Map}, returns the
@@ -338,8 +328,7 @@ default TypeInformation<?> getRequiredSuperTypeInformation(Class<?> superType) {
338328

339329
if (result == null) {
340330
throw new IllegalArgumentException(String.format(
341-
"Can't retrieve super type information for %s; Does current type really implement the given one",
342-
superType));
331+
"Can't retrieve super type information for %s; Does current type really implement the given one", superType));
343332
}
344333

345334
return result;
@@ -362,21 +351,6 @@ default TypeInformation<?> getRequiredSuperTypeInformation(Class<?> superType) {
362351
*/
363352
List<TypeInformation<?>> getTypeArguments();
364353

365-
/**
366-
* Specializes the given (raw) {@link ClassTypeInformation} using the context of the current potentially parameterized
367-
* type, basically turning the given raw type into a parameterized one. Will return the given type as is if no
368-
* generics are involved.
369-
*
370-
* @param type must not be {@literal null}.
371-
* @return will never be {@literal null}.
372-
* @deprecated since 3.0. Use {@link #specialize(TypeInformation)} instead, i.e. switch the given parameter's type to
373-
* {@link TypeInformation} in the first place.
374-
*/
375-
@Deprecated
376-
default TypeInformation<? extends S> specialize(ClassTypeInformation<?> type) {
377-
return specialize((TypeInformation<?>) type);
378-
}
379-
380354
/**
381355
* Specializes the given (raw) {@link TypeInformation} using the context of the current potentially parameterized
382356
* type, basically turning the given raw type into a parameterized one. Will return the given type as is if no
@@ -391,7 +365,7 @@ default TypeInformation<? extends S> specialize(TypeInformation<?> type) {
391365
}
392366

393367
/**
394-
* Returns whether the current type is a sub type of the given one, i.e. whether it's assignable but not the same one.
368+
* Returns whether the current type is a subtype of the given one, i.e. whether it's assignable but not the same one.
395369
*
396370
* @param type must not be {@literal null}.
397371
* @return

src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import org.junit.jupiter.api.BeforeEach;
4040
import org.junit.jupiter.api.Test;
41+
4142
import org.springframework.aop.SpringProxy;
4243
import org.springframework.aop.framework.Advised;
4344
import org.springframework.context.ApplicationContext;
@@ -52,7 +53,6 @@
5253
import org.springframework.data.mapping.ShadowingPropertyTypeWithCtor;
5354
import org.springframework.data.mapping.model.BasicPersistentEntity;
5455
import org.springframework.data.mapping.model.SimpleTypeHolder;
55-
import org.springframework.data.util.ClassTypeInformation;
5656
import org.springframework.data.util.StreamUtils;
5757
import org.springframework.data.util.TypeInformation;
5858

@@ -154,13 +154,13 @@ void returnsEntityForComponentType() {
154154
void exposesCopyOfPersistentEntitiesToAvoidConcurrentModificationException() {
155155

156156
var context = new SampleMappingContext();
157-
context.getPersistentEntity(ClassTypeInformation.MAP);
157+
context.getPersistentEntity(TypeInformation.MAP);
158158

159159
var iterator = context.getPersistentEntities()
160160
.iterator();
161161

162162
while (iterator.hasNext()) {
163-
context.getPersistentEntity(ClassTypeInformation.SET);
163+
context.getPersistentEntity(TypeInformation.SET);
164164
iterator.next();
165165
}
166166
}

src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.mockito.junit.jupiter.MockitoExtension;
2929
import org.mockito.junit.jupiter.MockitoSettings;
3030
import org.mockito.quality.Strictness;
31+
3132
import org.springframework.aop.framework.ProxyFactory;
3233
import org.springframework.beans.factory.support.AbstractBeanDefinition;
3334
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -47,7 +48,6 @@
4748
import org.springframework.data.repository.core.support.DummyRepositoryInformation;
4849
import org.springframework.data.repository.core.support.RepositoryFactoryInformation;
4950
import org.springframework.data.repository.query.QueryMethod;
50-
import org.springframework.data.util.ClassTypeInformation;
5151
import org.springframework.data.util.TypeInformation;
5252
import org.springframework.util.ClassUtils;
5353

@@ -139,8 +139,7 @@ void discoversRepositoryForAlternativeDomainType() {
139139
@Test // DATACMNS-794
140140
void exposesRepositoryFactoryInformationForRepository() {
141141

142-
var information = new Repositories(context)
143-
.getRepositoryInformation(PersonRepository.class);
142+
var information = new Repositories(context).getRepositoryInformation(PersonRepository.class);
144143

145144
assertThat(information)
146145
.hasValueSatisfying(it -> assertThat(it.getRepositoryInterface()).isEqualTo(PersonRepository.class));
@@ -304,8 +303,8 @@ static class CustomRepositoryMetadata extends DefaultRepositoryMetadata {
304303
var domainType = super.getDomainType().getName().concat("Entity");
305304

306305
try {
307-
this.domainType = ClassTypeInformation
308-
.from(ClassUtils.forName(domainType, CustomRepositoryMetadata.class.getClassLoader()));
306+
this.domainType = TypeInformation
307+
.of(ClassUtils.forName(domainType, CustomRepositoryMetadata.class.getClassLoader()));
309308
} catch (Exception e) {
310309
throw new RuntimeException(e);
311310
}

0 commit comments

Comments
 (0)