Browse Source

Remove references to `ClassTypeInformation` from `TypeInformation`.

Closes #2703
pull/2705/head
Mark Paluch 3 years ago
parent
commit
b55f098b43
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 7
      src/main/java/org/springframework/data/convert/MappingContextTypeInformationMapper.java
  2. 5
      src/main/java/org/springframework/data/convert/ValueConversionContext.java
  3. 1
      src/main/java/org/springframework/data/mapping/PropertyPath.java
  4. 1
      src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java
  5. 24
      src/main/java/org/springframework/data/util/ClassTypeInformation.java
  6. 27
      src/main/java/org/springframework/data/util/TypeDiscoverer.java
  7. 52
      src/main/java/org/springframework/data/util/TypeInformation.java
  8. 6
      src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java
  9. 9
      src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

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

@ -22,7 +22,6 @@ import org.springframework.data.mapping.Alias; @@ -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; @@ -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 @@ -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 @@ -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();
}

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

@ -16,7 +16,6 @@ @@ -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>> { @@ -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>> { @@ -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) {

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

@ -25,7 +25,6 @@ import java.util.Stack; @@ -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;

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

@ -28,7 +28,6 @@ import org.springframework.data.mapping.PersistentPropertyPath; @@ -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;

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

@ -33,18 +33,18 @@ import org.springframework.util.ConcurrentLruCache; @@ -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> { @@ -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> { @@ -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> { @@ -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);

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

@ -47,9 +47,7 @@ import org.springframework.util.ReflectionUtils; @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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);
}

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

@ -42,15 +42,11 @@ import org.springframework.util.Assert; @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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> { @@ -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

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

@ -38,6 +38,7 @@ import java.util.function.Supplier; @@ -38,6 +38,7 @@ import java.util.function.Supplier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.SpringProxy;
import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
@ -52,7 +53,6 @@ import org.springframework.data.mapping.ShadowingPropertyType; @@ -52,7 +53,6 @@ import org.springframework.data.mapping.ShadowingPropertyType;
import org.springframework.data.mapping.ShadowingPropertyTypeWithCtor;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.StreamUtils;
import org.springframework.data.util.TypeInformation;
@ -154,13 +154,13 @@ class AbstractMappingContextUnitTests { @@ -154,13 +154,13 @@ class AbstractMappingContextUnitTests {
void exposesCopyOfPersistentEntitiesToAvoidConcurrentModificationException() {
var context = new SampleMappingContext();
context.getPersistentEntity(ClassTypeInformation.MAP);
context.getPersistentEntity(TypeInformation.MAP);
var iterator = context.getPersistentEntities()
.iterator();
while (iterator.hasNext()) {
context.getPersistentEntity(ClassTypeInformation.SET);
context.getPersistentEntity(TypeInformation.SET);
iterator.next();
}
}

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

@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@ -47,7 +48,6 @@ import org.springframework.data.repository.core.support.DummyRepositoryFactoryBe @@ -47,7 +48,6 @@ import org.springframework.data.repository.core.support.DummyRepositoryFactoryBe
import org.springframework.data.repository.core.support.DummyRepositoryInformation;
import org.springframework.data.repository.core.support.RepositoryFactoryInformation;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ClassUtils;
@ -139,8 +139,7 @@ class RepositoriesUnitTests { @@ -139,8 +139,7 @@ class RepositoriesUnitTests {
@Test // DATACMNS-794
void exposesRepositoryFactoryInformationForRepository() {
var information = new Repositories(context)
.getRepositoryInformation(PersonRepository.class);
var information = new Repositories(context).getRepositoryInformation(PersonRepository.class);
assertThat(information)
.hasValueSatisfying(it -> assertThat(it.getRepositoryInterface()).isEqualTo(PersonRepository.class));
@ -304,8 +303,8 @@ class RepositoriesUnitTests { @@ -304,8 +303,8 @@ class RepositoriesUnitTests {
var domainType = super.getDomainType().getName().concat("Entity");
try {
this.domainType = ClassTypeInformation
.from(ClassUtils.forName(domainType, CustomRepositoryMetadata.class.getClassLoader()));
this.domainType = TypeInformation
.of(ClassUtils.forName(domainType, CustomRepositoryMetadata.class.getClassLoader()));
} catch (Exception e) {
throw new RuntimeException(e);
}

Loading…
Cancel
Save