Remove references to ClassTypeInformation from TypeInformation.

Closes #2703
This commit is contained in:
Mark Paluch
2022-10-06 16:20:22 +02:00
parent 1ff6e39ec2
commit b55f098b43
9 changed files with 43 additions and 89 deletions

View File

@@ -22,7 +22,6 @@ import org.springframework.data.mapping.Alias;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -38,7 +37,7 @@ import org.springframework.util.Assert;
*/
public class MappingContextTypeInformationMapper implements TypeInformationMapper {
private final Map<ClassTypeInformation<?>, Alias> typeMap;
private final Map<TypeInformation<?>, Alias> typeMap;
private final MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext;
/**
@@ -79,7 +78,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
* @param key must not be {@literal null}.
* @param alias can be {@literal null}.
*/
private Alias verify(ClassTypeInformation<?> key, Alias alias) {
private Alias verify(TypeInformation<?> key, Alias alias) {
// Reject second alias for same type
@@ -113,7 +112,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
@Override
public TypeInformation<?> resolveTypeFrom(Alias alias) {
for (Map.Entry<ClassTypeInformation<?>, Alias> entry : typeMap.entrySet()) {
for (Map.Entry<TypeInformation<?>, Alias> entry : typeMap.entrySet()) {
if (entry.getValue().hasSamePresentValueAs(alias)) {
return entry.getKey();
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.convert;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
@@ -65,7 +64,7 @@ public interface ValueConversionContext<P extends PersistentProperty<P>> {
* @return can be {@literal null}.
* @throws IllegalStateException if value cannot be written as an instance of {@link Class type}.
* @see #write(Object, TypeInformation)
* @see ClassTypeInformation
* @see TypeInformation
*/
@Nullable
default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
@@ -115,7 +114,7 @@ public interface ValueConversionContext<P extends PersistentProperty<P>> {
* @return can be {@literal null}.
* @throws IllegalStateException if value cannot be read as an instance of {@link Class type}.
* @see #read(Object, TypeInformation)
* @see ClassTypeInformation
* @see TypeInformation
*/
@Nullable
default <T> T read(@Nullable Object value, @NonNull Class<T> target) {

View File

@@ -25,7 +25,6 @@ import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Streamable;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;

View File

@@ -28,7 +28,6 @@ import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Pair;
import org.springframework.data.util.StreamUtils;
import org.springframework.data.util.TypeInformation;

View File

@@ -33,18 +33,18 @@ import org.springframework.util.ConcurrentLruCache;
* @author Christoph Strobl
* @deprecated since 3.0 to go package protected at some point. Refer to {@link TypeInformation} only.
*/
@Deprecated
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
private static final ConcurrentLruCache<ResolvableType, ClassTypeInformation<?>> cache = new ConcurrentLruCache<>(64,
ClassTypeInformation::new);
@Deprecated public static final ClassTypeInformation<Collection> COLLECTION;
@Deprecated public static final ClassTypeInformation<List> LIST;
@Deprecated public static final ClassTypeInformation<Set> SET;
@Deprecated public static final ClassTypeInformation<Map> MAP;
@Deprecated public static final ClassTypeInformation<Object> OBJECT;
public static final ClassTypeInformation<Collection> COLLECTION;
public static final ClassTypeInformation<List> LIST;
public static final ClassTypeInformation<Set> SET;
public static final ClassTypeInformation<Map> MAP;
public static final ClassTypeInformation<Object> OBJECT;
static {
@@ -62,11 +62,6 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
this.type = (Class<S>) type.resolve(Object.class);
}
private ClassTypeInformation(Class<S> type) {
super(ResolvableType.forClass(type));
this.type = type;
}
/**
* @param <S>
* @param type
@@ -75,10 +70,10 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
*/
@Deprecated
public static <S> ClassTypeInformation<S> from(Class<S> type) {
return cti(ResolvableType.forClass(type));
return from(ResolvableType.forClass(type));
}
static <S> ClassTypeInformation<S> cti(ResolvableType type) {
static <S> ClassTypeInformation<S> from(ResolvableType type) {
Assert.notNull(type, "Type must not be null");
@@ -104,8 +99,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
*/
static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> actualType) {
var type = actualType == null
? ResolvableType.forMethodReturnType(method)
var type = actualType == null ? ResolvableType.forMethodReturnType(method)
: ResolvableType.forMethodReturnType(method, actualType);
return TypeInformation.of(type);

View File

@@ -47,9 +47,7 @@ import org.springframework.util.ReflectionUtils;
* @author Jürgen Diez
* @author Alessandro Nistico
* @author Johannes Englmeier
* @deprecated since 3.0 to go package protected at some point. Prefer to refer to {@link TypeInformation} instead.
*/
@Deprecated
class TypeDiscoverer<S> implements TypeInformation<S> {
private static final ConcurrentLruCache<ResolvableType, TypeInformation<?>> CACHE = new ConcurrentLruCache<>(64,
@@ -124,8 +122,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
return type.isArray() //
|| Iterable.class.equals(type) //
|| Collection.class.isAssignableFrom(type) //
|| Streamable.class.isAssignableFrom(type)
|| CustomCollections.isCollection(type);
|| Streamable.class.isAssignableFrom(type) || CustomCollections.isCollection(type);
}
@Nullable
@@ -195,7 +192,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
}
@Override
public ClassTypeInformation<?> getRawTypeInformation() {
public TypeInformation<?> getRawTypeInformation() {
return new ClassTypeInformation<>(ResolvableType.forRawClass(resolvableType.toClass()));
}
@@ -257,13 +254,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
return TypeInformation.of(resolvableSuperType);
}
var noGenericsResolvable = !Arrays.stream(resolvableSuperType.resolveGenerics())
.filter(it -> it != null)
.findAny()
var noGenericsResolvable = !Arrays.stream(resolvableSuperType.resolveGenerics()).filter(it -> it != null).findAny()
.isPresent();
return noGenericsResolvable
? new ClassTypeInformation<>(ResolvableType.forRawClass(superType))
return noGenericsResolvable ? new ClassTypeInformation<>(ResolvableType.forRawClass(superType))
: TypeInformation.of(resolvableSuperType);
}
@@ -299,8 +293,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
}
return Arrays.stream(resolvableType.getGenerics())
.<TypeInformation<?>> map(it -> it.resolve(Object.class) == null ? null : TypeInformation.of(it))
.toList();
.<TypeInformation<?>> map(it -> it.resolve(Object.class) == null ? null : TypeInformation.of(it)).toList();
}
@Override
@@ -308,8 +301,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
public TypeInformation<? extends S> specialize(TypeInformation<?> type) {
if (this.getTypeArguments().size() == type.getTypeArguments().size()) {
return (TypeInformation<? extends S>) TypeInformation.of(
ResolvableType.forClassWithGenerics(type.getType(), this.resolvableType.getGenerics()));
return (TypeInformation<? extends S>) TypeInformation
.of(ResolvableType.forClassWithGenerics(type.getType(), this.resolvableType.getGenerics()));
}
return TypeInformation.of((Class<S>) type.getType());
@@ -380,10 +373,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
var rawType = getType();
var field = ReflectionUtils.findField(rawType, fieldname);
return field != null
? Optional.of(TypeInformation.of(ResolvableType.forField(field, resolvableType)))
: Optional.ofNullable(BeanUtils.getPropertyDescriptor(rawType, fieldname))
.map(it -> from(it, rawType))
return field != null ? Optional.of(TypeInformation.of(ResolvableType.forField(field, resolvableType)))
: Optional.ofNullable(BeanUtils.getPropertyDescriptor(rawType, fieldname)).map(it -> from(it, rawType))
.map(TypeInformation::of);
}

View File

@@ -42,15 +42,11 @@ import org.springframework.util.Assert;
@SuppressWarnings({ "deprecation", "rawtypes" })
public interface TypeInformation<S> {
public static final TypeInformation<Collection> COLLECTION = ClassTypeInformation.COLLECTION;
public static final TypeInformation<List> LIST = ClassTypeInformation.LIST;
public static final TypeInformation<Set> SET = ClassTypeInformation.SET;
public static final TypeInformation<Map> MAP = ClassTypeInformation.MAP;
public static final TypeInformation<Object> OBJECT = ClassTypeInformation.OBJECT;
static TypeInformation<?> orObject(@Nullable ResolvableType type) {
return type == null ? ClassTypeInformation.OBJECT : of(type);
}
TypeInformation<Collection> COLLECTION = ClassTypeInformation.COLLECTION;
TypeInformation<List> LIST = ClassTypeInformation.LIST;
TypeInformation<Set> SET = ClassTypeInformation.SET;
TypeInformation<Map> MAP = ClassTypeInformation.MAP;
TypeInformation<Object> OBJECT = ClassTypeInformation.OBJECT;
/**
* Creates a new {@link TypeInformation} from the given {@link ResolvableType}.
@@ -63,11 +59,8 @@ public interface TypeInformation<S> {
Assert.notNull(type, "Type must not be null");
return type.hasGenerics()
|| (type.isArray() && type.getComponentType().hasGenerics()) //
|| (type.getType() instanceof TypeVariable)
? TypeDiscoverer.td(type)
: ClassTypeInformation.cti(type);
return type.hasGenerics() || (type.isArray() && type.getComponentType().hasGenerics()) //
|| (type.getType() instanceof TypeVariable) ? TypeDiscoverer.td(type) : ClassTypeInformation.from(type);
}
/**
@@ -108,8 +101,7 @@ public interface TypeInformation<S> {
*/
public static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> type) {
ResolvableType intermediate = type == null
? ResolvableType.forMethodReturnType(method)
ResolvableType intermediate = type == null ? ResolvableType.forMethodReturnType(method)
: ResolvableType.forMethodReturnType(method, type);
return TypeInformation.of(intermediate);
@@ -161,8 +153,7 @@ public interface TypeInformation<S> {
return typeInformation;
}
throw new IllegalArgumentException(
String.format("Could not find required property %s on %s", property, getType()));
throw new IllegalArgumentException(String.format("Could not find required property %s on %s", property, getType()));
}
/**
@@ -259,12 +250,11 @@ public interface TypeInformation<S> {
}
/**
* Returns a {@link ClassTypeInformation} to represent the {@link TypeInformation} of the raw type of the current
* instance.
* Returns a {@link TypeInformation} to represent the {@link TypeInformation} of the raw type of the current instance.
*
* @return
*/
ClassTypeInformation<?> getRawTypeInformation();
TypeInformation<?> getRawTypeInformation();
/**
* Transparently returns the {@link java.util.Map} value type if the type is a {@link java.util.Map}, returns the
@@ -338,8 +328,7 @@ public interface TypeInformation<S> {
if (result == null) {
throw new IllegalArgumentException(String.format(
"Can't retrieve super type information for %s; Does current type really implement the given one",
superType));
"Can't retrieve super type information for %s; Does current type really implement the given one", superType));
}
return result;
@@ -362,21 +351,6 @@ public interface TypeInformation<S> {
*/
List<TypeInformation<?>> getTypeArguments();
/**
* Specializes the given (raw) {@link ClassTypeInformation} using the context of the current potentially parameterized
* type, basically turning the given raw type into a parameterized one. Will return the given type as is if no
* generics are involved.
*
* @param type must not be {@literal null}.
* @return will never be {@literal null}.
* @deprecated since 3.0. Use {@link #specialize(TypeInformation)} instead, i.e. switch the given parameter's type to
* {@link TypeInformation} in the first place.
*/
@Deprecated
default TypeInformation<? extends S> specialize(ClassTypeInformation<?> type) {
return specialize((TypeInformation<?>) type);
}
/**
* Specializes the given (raw) {@link TypeInformation} using the context of the current potentially parameterized
* type, basically turning the given raw type into a parameterized one. Will return the given type as is if no
@@ -391,7 +365,7 @@ public interface TypeInformation<S> {
}
/**
* Returns whether the current type is a sub type of the given one, i.e. whether it's assignable but not the same one.
* Returns whether the current type is a subtype of the given one, i.e. whether it's assignable but not the same one.
*
* @param type must not be {@literal null}.
* @return