diff --git a/src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java b/src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java index 5709fa5f8..1dfc81c30 100644 --- a/src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java +++ b/src/main/java/org/springframework/data/convert/ConfigurableTypeInformationMapper.java @@ -22,7 +22,6 @@ import java.util.Map.Entry; import org.springframework.data.mapping.Alias; import org.springframework.data.mapping.PersistentEntity; 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; @@ -37,8 +36,8 @@ import org.springframework.util.Assert; */ public class ConfigurableTypeInformationMapper implements TypeInformationMapper { - private final Map, Alias> typeToAlias; - private final Map> aliasToType; + private final Map, Alias> typeToAlias; + private final Map> aliasToType; /** * Creates a new {@link ConfigurableTypeInformationMapper} for the given type map. @@ -54,7 +53,7 @@ public class ConfigurableTypeInformationMapper implements TypeInformationMapper for (Entry, String> entry : sourceTypeMap.entrySet()) { - ClassTypeInformation type = ClassTypeInformation.from(entry.getKey()); + TypeInformation type = TypeInformation.of(entry.getKey()); Alias alias = Alias.of(entry.getValue()); if (typeToAlias.containsValue(alias)) { diff --git a/src/main/java/org/springframework/data/convert/DefaultTypeMapper.java b/src/main/java/org/springframework/data/convert/DefaultTypeMapper.java index ada432ec2..a154279b9 100644 --- a/src/main/java/org/springframework/data/convert/DefaultTypeMapper.java +++ b/src/main/java/org/springframework/data/convert/DefaultTypeMapper.java @@ -27,7 +27,6 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.data.mapping.Alias; import org.springframework.data.mapping.PersistentEntity; 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; @@ -149,16 +148,16 @@ public class DefaultTypeMapper implements TypeMapper, BeanClassLoaderAware Class rawType = basicType.getType(); - boolean isMoreConcreteCustomType = rawType == null - || rawType.isAssignableFrom(documentsTargetType) && !rawType.equals(documentsTargetType); + boolean isMoreConcreteCustomType = (rawType == null) + || (rawType.isAssignableFrom(documentsTargetType) && !rawType.equals(documentsTargetType)); if (!isMoreConcreteCustomType) { return basicType; } - ClassTypeInformation targetType = ClassTypeInformation.from(documentsTargetType); + TypeInformation targetType = TypeInformation.of(documentsTargetType); - return (TypeInformation) basicType.specialize(targetType); + return basicType.specialize(targetType); } /** @@ -190,7 +189,7 @@ public class DefaultTypeMapper implements TypeMapper, BeanClassLoaderAware @Override public void writeType(Class type, S dbObject) { - writeType(ClassTypeInformation.from(type), dbObject); + writeType(TypeInformation.of(type), dbObject); } @Override diff --git a/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java b/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java index 32fdc9c91..d453df8b2 100644 --- a/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java +++ b/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java @@ -21,7 +21,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.data.mapping.Alias; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; @@ -36,7 +35,7 @@ import org.springframework.util.ClassUtils; */ public class SimpleTypeInformationMapper implements TypeInformationMapper, BeanClassLoaderAware { - private final Map>> cache = new ConcurrentHashMap<>(); + private final Map>> cache = new ConcurrentHashMap<>(); private @Nullable ClassLoader classLoader; @@ -79,10 +78,10 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper, BeanC this.classLoader = classLoader; } - private Optional> loadClass(String typeName) { + private Optional> loadClass(String typeName) { try { - return Optional.of(ClassTypeInformation.from(ClassUtils.forName(typeName, this.classLoader))); + return Optional.of(TypeInformation.of(ClassUtils.forName(typeName, this.classLoader))); } catch (ClassNotFoundException e) { return Optional.empty(); } diff --git a/src/main/java/org/springframework/data/convert/ValueConversionContext.java b/src/main/java/org/springframework/data/convert/ValueConversionContext.java index 8a3880024..f073f1074 100644 --- a/src/main/java/org/springframework/data/convert/ValueConversionContext.java +++ b/src/main/java/org/springframework/data/convert/ValueConversionContext.java @@ -69,7 +69,7 @@ public interface ValueConversionContext

> { */ @Nullable default T write(@Nullable Object value, @NonNull Class target) { - return write(value, ClassTypeInformation.from(target)); + return write(value, TypeInformation.of(target)); } /** @@ -119,7 +119,7 @@ public interface ValueConversionContext

> { */ @Nullable default T read(@Nullable Object value, @NonNull Class target) { - return read(value, ClassTypeInformation.from(target)); + return read(value, TypeInformation.of(target)); } /** diff --git a/src/main/java/org/springframework/data/mapping/PropertyPath.java b/src/main/java/org/springframework/data/mapping/PropertyPath.java index daae7ddc8..51185d114 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -68,7 +68,7 @@ public class PropertyPath implements Streamable { * @param owningType must not be {@literal null}. */ PropertyPath(String name, Class owningType) { - this(name, ClassTypeInformation.from(owningType), Collections.emptyList()); + this(name, TypeInformation.of(owningType), Collections.emptyList()); } /** @@ -315,7 +315,7 @@ public class PropertyPath implements Streamable { * @return */ public static PropertyPath from(String source, Class type) { - return from(source, ClassTypeInformation.from(type)); + return from(source, TypeInformation.of(type)); } /** diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 6b3d9bffe..7570a8f03 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -189,7 +189,7 @@ public abstract class AbstractMappingContext type) { - return getPersistentEntity(ClassTypeInformation.from(type)); + return getPersistentEntity(TypeInformation.of(type)); } @Override @@ -197,7 +197,7 @@ public abstract class AbstractMappingContext typeInformation = ClassTypeInformation.from(type); + TypeInformation typeInformation = TypeInformation.of(type); try { @@ -312,7 +312,7 @@ public abstract class AbstractMappingContext PersistentPropertyPaths doFindPersistentPropertyPaths(Class type, Predicate predicate, Predicate

traversalGuard) { - return persistentPropertyPathFactory.from(ClassTypeInformation.from(type), predicate, traversalGuard); + return persistentPropertyPathFactory.from(TypeInformation.of(type), predicate, traversalGuard); } /** @@ -322,7 +322,7 @@ public abstract class AbstractMappingContext addPersistentEntity(Class type) { - return addPersistentEntity(ClassTypeInformation.from(type)); + return addPersistentEntity(TypeInformation.of(type)); } /** @@ -728,7 +728,7 @@ public abstract class AbstractMappingContext, P extends Assert.notNull(type, "Type must not be null"); Assert.notNull(propertyPath, "Property path must not be null"); - return getPersistentPropertyPath(ClassTypeInformation.from(type), propertyPath); + return getPersistentPropertyPath(TypeInformation.of(type), propertyPath); } /** @@ -112,7 +112,7 @@ class PersistentPropertyPathFactory, P extends Assert.notNull(type, "Type must not be null"); Assert.notNull(propertyFilter, "Property filter must not be null"); - return from(ClassTypeInformation.from(type), propertyFilter); + return from(TypeInformation.of(type), propertyFilter); } /** @@ -131,7 +131,7 @@ class PersistentPropertyPathFactory, P extends Assert.notNull(propertyFilter, "Property filter must not be null"); Assert.notNull(traversalGuard, "Traversal guard must not be null"); - return from(ClassTypeInformation.from(type), propertyFilter, traversalGuard); + return from(TypeInformation.of(type), propertyFilter, traversalGuard); } /** diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index 78bbd8565..c908b7c97 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -88,7 +88,7 @@ public abstract class AnnotationBasedPersistentProperty

!Class.class.equals(it) ? ClassTypeInformation.from(it) : getActualTypeInformation()) // + .map(it -> !Class.class.equals(it) ? TypeInformation.of(it) : getActualTypeInformation()) // .orElseGet(() -> super.getAssociationTargetTypeInformation()); }); diff --git a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java index 02d1a9fce..be04f5a51 100644 --- a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java +++ b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java @@ -63,7 +63,7 @@ public interface PreferredConstructorDiscoverer the domain type. * @author Mark Paluch * @author Christoph Strobl + * @author Oliver Drotbohm * @since 2.7 */ public class EntityProjection implements Streamable> { @@ -90,7 +90,9 @@ public class EntityProjection implements Streamable EntityProjection nonProjecting(Class type) { - ClassTypeInformation typeInformation = ClassTypeInformation.from(type); + + TypeInformation typeInformation = TypeInformation.of(type); + return new EntityProjection<>(typeInformation, typeInformation, Collections.emptyList(), false, ProjectionType.CLOSED); } diff --git a/src/main/java/org/springframework/data/projection/EntityProjectionIntrospector.java b/src/main/java/org/springframework/data/projection/EntityProjectionIntrospector.java index c939e1012..42750542e 100644 --- a/src/main/java/org/springframework/data/projection/EntityProjectionIntrospector.java +++ b/src/main/java/org/springframework/data/projection/EntityProjectionIntrospector.java @@ -25,9 +25,8 @@ import java.util.Set; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PropertyPath; -import org.springframework.data.projection.EntityProjection.ProjectionType; import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.projection.EntityProjection.ProjectionType; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -39,6 +38,7 @@ import org.springframework.util.Assert; * @author Gerrit Meier * @author Mark Paluch * @author Christoph Strobl + * @author Oliver Drotbohm * @since 2.7 */ public class EntityProjectionIntrospector { @@ -91,8 +91,8 @@ public class EntityProjectionIntrospector { */ public EntityProjection introspect(Class mappedType, Class domainType) { - ClassTypeInformation returnedTypeInformation = ClassTypeInformation.from(mappedType); - ClassTypeInformation domainTypeInformation = ClassTypeInformation.from(domainType); + TypeInformation returnedTypeInformation = TypeInformation.of(mappedType); + TypeInformation domainTypeInformation = TypeInformation.of(domainType); boolean isProjection = projectionPredicate.test(mappedType, domainType); @@ -111,7 +111,8 @@ public class EntityProjectionIntrospector { List> propertyDescriptors = getProperties(null, projectionInformation, returnedTypeInformation, persistentEntity, null); - return EntityProjection.projecting(returnedTypeInformation, domainTypeInformation, propertyDescriptors, ProjectionType.CLOSED); + return EntityProjection.projecting(returnedTypeInformation, domainTypeInformation, propertyDescriptors, + ProjectionType.CLOSED); } private List> getProperties(@Nullable PropertyPath propertyPath, @@ -157,10 +158,12 @@ public class EntityProjectionIntrospector { if (container) { propertyDescriptors.add(EntityProjection.ContainerPropertyProjection.projecting(nestedPropertyPath, property, - persistentProperty.getTypeInformation(), nestedPropertyDescriptors, ProjectionType.from(projectionInformation))); + persistentProperty.getTypeInformation(), nestedPropertyDescriptors, + ProjectionType.from(projectionInformation))); } else { propertyDescriptors.add(EntityProjection.PropertyProjection.projecting(nestedPropertyPath, property, - persistentProperty.getTypeInformation(), nestedPropertyDescriptors, ProjectionType.from(projectionInformation))); + persistentProperty.getTypeInformation(), nestedPropertyDescriptors, + ProjectionType.from(projectionInformation))); } } else { diff --git a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java index 0d6e6c313..901796e0c 100644 --- a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java +++ b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java @@ -25,10 +25,8 @@ import java.util.Map.Entry; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.NullableWrapper; import org.springframework.data.util.NullableWrapperConverters; import org.springframework.data.util.TypeInformation; @@ -66,7 +64,7 @@ class ProjectingMethodInterceptor implements MethodInterceptor { @Override public Object invoke(@SuppressWarnings("null") @NonNull MethodInvocation invocation) throws Throwable { - TypeInformation type = ClassTypeInformation.fromReturnTypeOf(invocation.getMethod()); + TypeInformation type = TypeInformation.fromReturnTypeOf(invocation.getMethod()); TypeInformation resultType = type; TypeInformation typeToReturn = type; @@ -74,7 +72,7 @@ class ProjectingMethodInterceptor implements MethodInterceptor { boolean applyWrapper = false; if (NullableWrapperConverters.supports(type.getType()) - && (result == null || !NullableWrapperConverters.supports(result.getClass()))) { + && ((result == null) || !NullableWrapperConverters.supports(result.getClass()))) { resultType = NullableWrapperConverters.unwrapActualType(typeToReturn); applyWrapper = true; } @@ -161,7 +159,7 @@ class ProjectingMethodInterceptor implements MethodInterceptor { @Nullable private Object getProjection(@Nullable Object result, Class returnType) { - return result == null || ClassUtils.isAssignable(returnType, result.getClass()) ? result + return (result == null) || ClassUtils.isAssignable(returnType, result.getClass()) ? result : factory.createProjection(returnType, result); } diff --git a/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindings.java b/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindings.java index 770426ef1..64d4b1038 100644 --- a/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindings.java +++ b/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindings.java @@ -25,7 +25,6 @@ import java.util.Set; import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyReferenceException; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.Optionals; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; @@ -175,7 +174,7 @@ public class QuerydslBindings { Assert.notNull(path, "Path must not be null"); Assert.notNull(type, "Type must not be null"); - return isPathAvailable(path, ClassTypeInformation.from(type)); + return isPathAvailable(path, TypeInformation.of(type)); } /** @@ -573,7 +572,7 @@ public class QuerydslBindings { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } @@ -589,7 +588,7 @@ public class QuerydslBindings { @Override public int hashCode() { int result = ObjectUtils.nullSafeHashCode(path); - result = 31 * result + ObjectUtils.nullSafeHashCode(binding); + result = (31 * result) + ObjectUtils.nullSafeHashCode(binding); return result; } diff --git a/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java index 735e7e95e..44230bbc2 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java @@ -29,7 +29,6 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.util.QueryExecutionConverters; import org.springframework.data.repository.util.ReactiveWrapperConverters; import org.springframework.data.repository.util.ReactiveWrappers; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.KotlinReflectionUtils; import org.springframework.data.util.Lazy; import org.springframework.data.util.TypeInformation; @@ -60,7 +59,7 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata { Assert.isTrue(repositoryInterface.isInterface(), "Given type must be an interface"); this.repositoryInterface = repositoryInterface; - this.typeInformation = ClassTypeInformation.from(repositoryInterface); + this.typeInformation = TypeInformation.of(repositoryInterface); this.crudMethods = Lazy.of(() -> new DefaultCrudMethods(this)); } diff --git a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java index ceb243f2b..946a6a460 100644 --- a/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java @@ -20,7 +20,6 @@ import java.util.function.Function; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.repository.RepositoryDefinition; import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; @@ -78,6 +77,6 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { throw new IllegalArgumentException(String.format("Could not resolve domain type of %s", repositoryInterface)); } - return ClassTypeInformation.from(extractor.apply(annotation)); + return TypeInformation.of(extractor.apply(annotation)); } } diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java index 733540af3..3f0ab9d9e 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java @@ -20,7 +20,6 @@ import java.util.function.Supplier; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; @@ -50,7 +49,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { super(repositoryInterface); Assert.isTrue(Repository.class.isAssignableFrom(repositoryInterface), MUST_BE_A_REPOSITORY); - List> arguments = ClassTypeInformation.from(repositoryInterface)// + List> arguments = TypeInformation.of(repositoryInterface)// .getRequiredSuperTypeInformation(Repository.class)// .getTypeArguments(); diff --git a/src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java b/src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java index 08cd53013..be65d0cdc 100644 --- a/src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java +++ b/src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java @@ -21,7 +21,6 @@ import java.util.Map; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; @@ -85,7 +84,7 @@ public class MethodInvocationValidator implements MethodInterceptor { continue; } - if (arguments.length < i || arguments[i] == null) { + if ((arguments.length < i) || (arguments[i] == null)) { throw new IllegalArgumentException( String.format("Parameter %s in %s.%s must not be null", nullability.getMethodParameterName(i), ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); @@ -94,7 +93,7 @@ public class MethodInvocationValidator implements MethodInterceptor { Object result = invocation.proceed(); - if (result == null && !nullability.isNullableReturn()) { + if ((result == null) && !nullability.isNullableReturn()) { throw new EmptyResultDataAccessException("Result must not be null", 1); } @@ -170,7 +169,7 @@ public class MethodInvocationValidator implements MethodInterceptor { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; @@ -194,8 +193,8 @@ public class MethodInvocationValidator implements MethodInterceptor { @Override public int hashCode() { int result = (nullableReturn ? 1 : 0); - result = 31 * result + ObjectUtils.nullSafeHashCode(nullableParameters); - result = 31 * result + ObjectUtils.nullSafeHashCode(methodParameters); + result = (31 * result) + ObjectUtils.nullSafeHashCode(nullableParameters); + result = (31 * result) + ObjectUtils.nullSafeHashCode(methodParameters); return result; } diff --git a/src/main/java/org/springframework/data/repository/core/support/MethodLookup.java b/src/main/java/org/springframework/data/repository/core/support/MethodLookup.java index a7a8aefd9..35a779226 100644 --- a/src/main/java/org/springframework/data/repository/core/support/MethodLookup.java +++ b/src/main/java/org/springframework/data/repository/core/support/MethodLookup.java @@ -21,6 +21,7 @@ import java.util.function.BiPredicate; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -75,8 +76,7 @@ public interface MethodLookup { /** * Value object representing an invoked {@link Method}. */ - final - class InvokedMethod { + final class InvokedMethod { private final Method method; @@ -109,7 +109,7 @@ public interface MethodLookup { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; diff --git a/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java b/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java index dee439136..3e4c28864 100644 --- a/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java +++ b/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java @@ -37,6 +37,7 @@ import org.springframework.data.repository.core.support.MethodLookup.MethodPredi import org.springframework.data.repository.util.QueryExecutionConverters; import org.springframework.data.repository.util.ReactiveWrapperConverters; import org.springframework.data.repository.util.ReactiveWrappers; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -58,7 +59,7 @@ interface MethodLookups { static MethodLookup direct() { MethodPredicate direct = (MethodPredicate) (invoked, candidate) -> candidate.getName().equals(invoked.getName()) - && candidate.getParameterCount() == invoked.getParameterCount() + && (candidate.getParameterCount() == invoked.getParameterCount()) && Arrays.equals(candidate.getParameterTypes(), invoked.getParameterTypes()); return () -> Collections.singletonList(direct); @@ -248,8 +249,8 @@ interface MethodLookups { MethodPredicate detailedComparison = (MethodPredicate) (invokedMethod, candidate) -> getMethodCandidate(invokedMethod, - candidate, - matchParameterOrComponentType(repositoryMetadata.getRepositoryInterface())).isPresent(); + candidate, + matchParameterOrComponentType(repositoryMetadata.getRepositoryInterface())).isPresent(); return Arrays.asList(convertibleComparison, detailedComparison); } @@ -434,7 +435,7 @@ interface MethodLookups { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; @@ -454,7 +455,7 @@ interface MethodLookups { @Override public int hashCode() { int result = ObjectUtils.nullSafeHashCode(declared); - result = 31 * result + ObjectUtils.nullSafeHashCode(base); + result = (31 * result) + ObjectUtils.nullSafeHashCode(base); return result; } diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryComposition.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryComposition.java index 890df3c86..69d81a5bd 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryComposition.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryComposition.java @@ -81,7 +81,7 @@ public class RepositoryComposition { Class parameterType = parameterTypes.length > i ? parameterTypes[i] : null; - if (value != null && parameterType != null) { + if ((value != null) && (parameterType != null)) { if (!parameterType.isAssignableFrom(value.getClass()) && ReactiveWrapperConverters.canConvert(value.getClass(), parameterType)) { @@ -558,7 +558,7 @@ public class RepositoryComposition { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; @@ -582,8 +582,8 @@ public class RepositoryComposition { @Override public int hashCode() { int result = ObjectUtils.nullSafeHashCode(fragmentCache); - result = 31 * result + ObjectUtils.nullSafeHashCode(invocationMetadataCache); - result = 31 * result + ObjectUtils.nullSafeHashCode(fragments); + result = (31 * result) + ObjectUtils.nullSafeHashCode(invocationMetadataCache); + result = (31 * result) + ObjectUtils.nullSafeHashCode(fragments); return result; } } diff --git a/src/main/java/org/springframework/data/repository/query/Parameter.java b/src/main/java/org/springframework/data/repository/query/Parameter.java index f8c14c83c..5fbf81ba8 100644 --- a/src/main/java/org/springframework/data/repository/query/Parameter.java +++ b/src/main/java/org/springframework/data/repository/query/Parameter.java @@ -17,7 +17,6 @@ package org.springframework.data.repository.query; import static java.lang.String.*; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -32,10 +31,8 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.util.ClassUtils; import org.springframework.data.repository.util.QueryExecutionConverters; import org.springframework.data.repository.util.ReactiveWrapperConverters; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.Lazy; import org.springframework.data.util.TypeInformation; -import org.springframework.data.util.TypeDiscoverer; import org.springframework.util.Assert; /** @@ -218,7 +215,9 @@ public class Parameter { } ResolvableType returnType = ResolvableType.forMethodReturnType(parameter.getMethod()); - if(new TypeDiscoverer(returnType).isCollectionLike() || org.springframework.util.ClassUtils.isAssignable(Stream.class, returnType.toClass())) { + + if (TypeInformation.of(returnType).isCollectionLike() + || org.springframework.util.ClassUtils.isAssignable(Stream.class, returnType.toClass())) { returnType = returnType.getGeneric(0); } diff --git a/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/src/main/java/org/springframework/data/repository/query/QueryMethod.java index 3fa0f7d38..d9d9f1026 100644 --- a/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -30,7 +30,6 @@ import org.springframework.data.repository.core.EntityMetadata; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.util.QueryExecutionConverters; import org.springframework.data.repository.util.ReactiveWrapperConverters; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.Lazy; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; @@ -108,7 +107,7 @@ public class QueryMethod { Class repositoryDomainClass = metadata.getDomainType(); Class methodDomainClass = metadata.getReturnedDomainClass(method); - return repositoryDomainClass == null || repositoryDomainClass.isAssignableFrom(methodDomainClass) + return (repositoryDomainClass == null) || repositoryDomainClass.isAssignableFrom(methodDomainClass) ? methodDomainClass : repositoryDomainClass; }); @@ -271,7 +270,7 @@ public class QueryMethod { return !QueryExecutionConverters.isSingleValue(unwrappedReturnType); } - return ClassTypeInformation.from(unwrappedReturnType).isCollectionLike(); + return TypeInformation.of(unwrappedReturnType).isCollectionLike(); } private static Class potentiallyUnwrapReturnTypeFor(RepositoryMetadata metadata, Method method) { @@ -301,7 +300,7 @@ public class QueryMethod { Assert.notEmpty(types, "Types must not be null or empty"); // TODO: to resolve generics fully we'd need the actual repository interface here - TypeInformation returnType = ClassTypeInformation.fromReturnTypeOf(method); + TypeInformation returnType = TypeInformation.fromReturnTypeOf(method); returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) // ? returnType.getRequiredComponentType() // diff --git a/src/main/java/org/springframework/data/repository/util/ClassUtils.java b/src/main/java/org/springframework/data/repository/util/ClassUtils.java index 287f0bd46..98d7c5ce2 100644 --- a/src/main/java/org/springframework/data/repository/util/ClassUtils.java +++ b/src/main/java/org/springframework/data/repository/util/ClassUtils.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.function.Consumer; import org.springframework.data.repository.Repository; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; @@ -114,13 +113,13 @@ public abstract class ClassUtils { } /** - * Returns the number of occurrences for the given {@link Method#getParameterTypes() parameter type} - * in the given {@link Method}. + * Returns the number of occurrences for the given {@link Method#getParameterTypes() parameter type} in the given + * {@link Method}. * * @param method {@link Method} to evaluate. * @param parameterType {@link Class} of the {@link Method} parameter type to count. - * @return the number of occurrences for the given {@link Method#getParameterTypes() parameter type} - * in the given {@link Method}. + * @return the number of occurrences for the given {@link Method#getParameterTypes() parameter type} in the given + * {@link Method}. * @see java.lang.reflect.Method#getParameterTypes() */ public static int getNumberOfOccurrences(@NonNull Method method, @NonNull Class parameterType) { @@ -195,9 +194,11 @@ public abstract class ClassUtils { // TODO: we should also consider having the owning type here so we can resolve generics better. private static TypeInformation getEffectivelyReturnedTypeFrom(Method method) { - TypeInformation returnType = ClassTypeInformation.fromReturnTypeOf(method); - return QueryExecutionConverters.supports(returnType.getType()) - || ReactiveWrapperConverters.supports(returnType.getType()) ? returnType.getRequiredComponentType() + TypeInformation returnType = TypeInformation.fromReturnTypeOf(method); + + return QueryExecutionConverters.supports(returnType.getType()) // + || ReactiveWrapperConverters.supports(returnType.getType()) // + ? returnType.getRequiredComponentType() // : returnType; } } diff --git a/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/src/main/java/org/springframework/data/util/ClassTypeInformation.java index 8b52d741a..2dd5902f1 100644 --- a/src/main/java/org/springframework/data/util/ClassTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ClassTypeInformation.java @@ -16,45 +16,85 @@ package org.springframework.data.util; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.ResolvableType; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import org.springframework.util.ConcurrentReferenceHashMap; -import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType; +import org.springframework.util.ConcurrentLruCache; /** * {@link TypeInformation} for a plain {@link Class}. * * @author Oliver Gierke * @author Christoph Strobl + * @deprecated since 3.0 to go package protected at some point. Refer to {@link TypeInformation} only. */ +@Deprecated +@SuppressWarnings({ "rawtypes", "unchecked" }) public class ClassTypeInformation extends TypeDiscoverer { - public static final ClassTypeInformation COLLECTION = new ClassTypeInformation(Collection.class); - public static final ClassTypeInformation LIST = new ClassTypeInformation(List.class); - public static final ClassTypeInformation SET = new ClassTypeInformation(Set.class); - public static final ClassTypeInformation MAP = new ClassTypeInformation(Map.class); - public static final ClassTypeInformation OBJECT = new ClassTypeInformation(Object.class); + private static final ConcurrentLruCache> cache = new ConcurrentLruCache<>(64, + ClassTypeInformation::new); - private static final Map, ClassTypeInformation> cache = new ConcurrentReferenceHashMap<>(64, - ReferenceType.WEAK); + @Deprecated public static final ClassTypeInformation COLLECTION; + @Deprecated public static final ClassTypeInformation LIST; + @Deprecated public static final ClassTypeInformation SET; + @Deprecated public static final ClassTypeInformation MAP; + @Deprecated public static final ClassTypeInformation OBJECT; + + static { + + OBJECT = (ClassTypeInformation) cache.get(ResolvableType.forClass(Object.class)); + COLLECTION = (ClassTypeInformation) cache.get(ResolvableType.forClass(Collection.class)); + LIST = (ClassTypeInformation) cache.get(ResolvableType.forClass(List.class)); + SET = (ClassTypeInformation) cache.get(ResolvableType.forClass(Set.class)); + MAP = (ClassTypeInformation) cache.get(ResolvableType.forClass(Map.class)); + } + + private final Class type; + + ClassTypeInformation(ResolvableType type) { + super(type); + this.type = (Class) type.resolve(Object.class); + } + + private ClassTypeInformation(Class type) { + super(ResolvableType.forClass(type)); + this.type = type; + } + + /** + * @param + * @param type + * @return + * @deprecated since 3.0. Use {@link TypeInformation#of} instead. + */ + @Deprecated + public static ClassTypeInformation from(Class type) { + return cti(ResolvableType.forClass(type)); + } + + static ClassTypeInformation cti(ResolvableType type) { + + Assert.notNull(type, "Type must not be null"); + + return (ClassTypeInformation) cache.get(type); + } /** * Warning: Does not fully resolve generic arguments. + * * @param method * @return - * @deprecated since 3.0 Use {@link #fromReturnTypeOf(Method, Class)} instead. + * @deprecated since 3.0. Use {@link TypeInformation#fromReturnTypeOf(Method)} instead. */ @Deprecated - public static TypeInformation fromReturnTypeOf(Method method) { - return new TypeDiscoverer<>(ResolvableType.forMethodReturnType(method)); + public static TypeInformation fromReturnTypeOf(Method method) { + return (TypeInformation) TypeInformation.of(ResolvableType.forMethodReturnType(method)); } /** @@ -62,35 +102,18 @@ public class ClassTypeInformation extends TypeDiscoverer { * @param actualType can be {@literal null}. * @return */ - public static TypeInformation fromReturnTypeOf(Method method, @Nullable Class actualType) { - - if(actualType == null) { - return new TypeDiscoverer<>(ResolvableType.forMethodReturnType(method)); - } - return new TypeDiscoverer<>(ResolvableType.forMethodReturnType(method, actualType)); - } + static TypeInformation fromReturnTypeOf(Method method, @Nullable Class actualType) { - Class type; + var type = actualType == null + ? ResolvableType.forMethodReturnType(method) + : ResolvableType.forMethodReturnType(method, actualType); - static { - Arrays.asList(COLLECTION, LIST, SET, MAP, OBJECT).forEach(it -> cache.put(it.getType(), it)); - } - - public static ClassTypeInformation from(Class type) { - - Assert.notNull(type, "Type must not be null"); - - return (ClassTypeInformation) cache.computeIfAbsent(type, ClassTypeInformation::new); - } - - ClassTypeInformation(Class type) { - super(ResolvableType.forClass(type)); - this.type = type; + return TypeInformation.of(type); } @Override public Class getType() { - return (Class) type; + return type; } @Override @@ -104,7 +127,7 @@ public class ClassTypeInformation extends TypeDiscoverer { } @Override - public TypeInformation specialize(ClassTypeInformation type) { + public TypeInformation specialize(TypeInformation type) { return (TypeInformation) type; } @@ -112,9 +135,4 @@ public class ClassTypeInformation extends TypeDiscoverer { public String toString() { return type.getName(); } - - @Override - public boolean equals(Object o) { - return super.equals(o); - } } diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index ef1cd56bd..85c4f2076 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -22,11 +22,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -37,6 +35,7 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.ConcurrentLruCache; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -49,55 +48,36 @@ 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. */ -public class TypeDiscoverer implements TypeInformation { +@Deprecated +class TypeDiscoverer implements TypeInformation { - protected static final Class[] MAP_TYPES; - private static final Class[] COLLECTION_TYPES; - - static { - - var classLoader = TypeDiscoverer.class.getClassLoader(); - - Set> mapTypes = new HashSet<>(); - mapTypes.add(Map.class); - - try { - mapTypes.add(ClassUtils.forName("io.vavr.collection.Map", classLoader)); - } catch (ClassNotFoundException o_O) {} - - MAP_TYPES = mapTypes.toArray(new Class[0]); - - Set> collectionTypes = new HashSet<>(); - collectionTypes.add(Collection.class); - - try { - collectionTypes.add(ClassUtils.forName("io.vavr.collection.Seq", classLoader)); - } catch (ClassNotFoundException o_O) {} - - try { - collectionTypes.add(ClassUtils.forName("io.vavr.collection.Set", classLoader)); - } catch (ClassNotFoundException o_O) {} - - COLLECTION_TYPES = collectionTypes.toArray(new Class[0]); - } - - ResolvableType resolvableType; - private Map>> fields = new ConcurrentHashMap<>(); + private static final ConcurrentLruCache> CACHE = new ConcurrentLruCache<>(64, + TypeDiscoverer::new); + private final ResolvableType resolvableType; + private final Map>> fields = new ConcurrentHashMap<>(); private final Lazy> componentType; private final Lazy> valueType; + private final Map, List>> constructorParameters = new ConcurrentHashMap<>(); + private final Lazy>> typeArguments; - public TypeDiscoverer(Class type) { - this(ResolvableType.forClass(type)); - } - - public TypeDiscoverer(ResolvableType type) { + protected TypeDiscoverer(ResolvableType type) { Assert.notNull(type, "Type must not be null"); + this.resolvableType = type; this.componentType = Lazy.of(this::doGetComponentType); this.valueType = Lazy.of(this::doGetMapValueType); + this.typeArguments = Lazy.of(this::doGetTypeArguments); + } + + static TypeDiscoverer td(ResolvableType type) { + + Assert.notNull(type, "Type must not be null"); + + return (TypeDiscoverer) CACHE.get(type); } @Override @@ -105,16 +85,16 @@ public class TypeDiscoverer implements TypeInformation { Assert.notNull(constructor, "Constructor must not be null"); - List> target = new ArrayList<>(); - for (int i = 0; i < constructor.getParameterCount(); i++) { - target.add(new TypeDiscoverer<>(ResolvableType.forConstructorParameter(constructor, i))); - } - return target; - } + return constructorParameters.computeIfAbsent(constructor, it -> { - @Override - public TypeDescriptor toTypeDescriptor() { - return new TypeDescriptor(resolvableType, null, null); + List> target = new ArrayList<>(); + + for (int i = 0; i < it.getParameterCount(); i++) { + target.add(TypeInformation.of(ResolvableType.forConstructorParameter(it, i))); + } + + return target; + }); } @Nullable @@ -137,56 +117,11 @@ public class TypeDiscoverer implements TypeInformation { return info.getProperty(name.substring(separatorIndex + 1)); } - private Optional> getPropertyInformation(String fieldname) { - - Class rawType = resolvableType.toClass(); - var field = ReflectionUtils.findField(rawType, fieldname); - - if (field != null) { - return Optional.of(new TypeDiscoverer(ResolvableType.forField(field, resolvableType))); - } - - return findPropertyDescriptor(rawType, fieldname).map(it -> { - - if (it.getReadMethod() != null) { - return new TypeDiscoverer(ResolvableType.forMethodReturnType(it.getReadMethod(), rawType)); - } - if (it.getWriteMethod() != null) { - return new TypeDiscoverer(ResolvableType.forMethodParameter(it.getWriteMethod(), 0, rawType)); - } - - return new TypeDiscoverer(ResolvableType.forType(it.getPropertyType(), resolvableType)); - }); - } - - private Optional findPropertyDescriptor(Class type, String fieldname) { - - PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(type, fieldname); - - if (descriptor != null) { - return Optional.of(descriptor); - } - - List> superTypes = new ArrayList<>(); - superTypes.addAll(Arrays.asList(type.getInterfaces())); - superTypes.add(type.getSuperclass()); - - return Streamable.of(type.getInterfaces()).stream()// - .flatMap(it -> Optionals.toStream(findPropertyDescriptor(it, fieldname)))// - .findFirst(); - } - @Override public boolean isCollectionLike() { Class type = getType(); - for (Class collectionType : COLLECTION_TYPES) { - if (collectionType.isAssignableFrom(type)) { - return true; - } - } - return type.isArray() // || Iterable.class.equals(type) // || Collection.class.isAssignableFrom(type) // @@ -203,66 +138,27 @@ public class TypeDiscoverer implements TypeInformation { @Nullable protected TypeInformation doGetComponentType() { - var rawType = getType(); - - if (rawType.isArray()) { - return new TypeDiscoverer<>(resolvableType.getComponentType()); + if (resolvableType.isArray()) { + return TypeInformation.of(resolvableType.getComponentType()); } - if (isMap()) { - if (ClassUtils.isAssignable(Map.class, rawType)) { - ResolvableType mapValueType = resolvableType.asMap().getGeneric(0); - if (ResolvableType.NONE.equals(mapValueType)) { - return null; - } + Class rawType = getType(); - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - if (resolvableType.hasGenerics()) { - ResolvableType mapValueType = resolvableType.getGeneric(0); - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - return Arrays.stream(resolvableType.getInterfaces()).filter(ResolvableType::hasGenerics) - .findFirst() - .map(it -> it.getGeneric(0)) - .map(TypeDiscoverer::new) - .orElse(null); + if (isMap()) { + return getTypeArgument(CustomCollections.getMapBaseType(rawType), 0); } if (Iterable.class.isAssignableFrom(rawType)) { - - ResolvableType iterableType = resolvableType.as(Iterable.class); - ResolvableType mapValueType = iterableType.getGeneric(0); - if (ResolvableType.NONE.equals(mapValueType)) { - return null; - } - - if (resolvableType.hasGenerics()) { - mapValueType = resolvableType.getGeneric(0); - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - - return mapValueType.resolve() != null ? new TypeDiscoverer<>(mapValueType) : null; + return getTypeArgument(Iterable.class, 0); } if (isNullableWrapper()) { - ResolvableType mapValueType = resolvableType.getGeneric(0); - if (ResolvableType.NONE.equals(mapValueType)) { - return null; - } - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - - if (resolvableType.hasGenerics()) { - ResolvableType mapValueType = resolvableType.getGeneric(0); - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); + return getTypeArgument(rawType, 0); } - return null; - } + List> arguments = getTypeArguments(); - private boolean isNullableWrapper() { - return NullableWrapperConverters.supports(getType()); + return arguments.size() > 0 ? arguments.get(0) : null; } @Override @@ -279,50 +175,31 @@ public class TypeDiscoverer implements TypeInformation { @Nullable protected TypeInformation doGetMapValueType() { - if (isMap()) { - if (ClassUtils.isAssignable(Map.class, getType())) { - ResolvableType mapValueType = resolvableType.asMap().getGeneric(1); - if (ResolvableType.NONE.equals(mapValueType)) { - return null; - } - - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - if (resolvableType.hasGenerics()) { - ResolvableType mapValueType = resolvableType.getGeneric(1); - return mapValueType != null ? new TypeDiscoverer(mapValueType) : new ClassTypeInformation<>(Object.class); - } - return Arrays.stream(resolvableType.getInterfaces()).filter(ResolvableType::hasGenerics) - .findFirst() - .map(it -> it.getGeneric(1)) - .map(TypeDiscoverer::new) - .orElse(null); - } - - if (!resolvableType.hasGenerics()) { - return null; - } - ResolvableType x = Arrays.stream(resolvableType.getGenerics()).skip(1).findFirst().orElse(null); - if ((x == null) || ResolvableType.NONE.equals(x)) { - return null; - } - - return new TypeDiscoverer<>(x); + return isMap() // + ? getTypeArgument(CustomCollections.getMapBaseType(getType()), 1) + : getTypeArguments().stream().skip(1).findFirst().orElse(null); } @Override + @SuppressWarnings("unchecked") public Class getType() { return (Class) resolvableType.toClass(); } + @Override + public TypeDescriptor toTypeDescriptor() { + return new TypeDescriptor(resolvableType, getType(), null); + } + @Override public ClassTypeInformation getRawTypeInformation() { - return new ClassTypeInformation<>(this.resolvableType.getRawClass()); + return new ClassTypeInformation<>(ResolvableType.forRawClass(resolvableType.getRawClass())); } @Nullable @Override public TypeInformation getActualType() { + if (isMap()) { return getMapValueType(); } @@ -331,8 +208,6 @@ public class TypeDiscoverer implements TypeInformation { return getComponentType(); } - // TODO: Consider that we will support value types beyond Optional, such as Json, Foo that should remain - // configurable. if (isNullableWrapper()) { return getComponentType(); } @@ -342,10 +217,7 @@ public class TypeDiscoverer implements TypeInformation { @Override public TypeInformation getReturnType(Method method) { - - Assert.notNull(method, "Method must not be null"); - - return new TypeDiscoverer(ResolvableType.forMethodReturnType(method, getType())); + return TypeInformation.of(ResolvableType.forMethodReturnType(method, getType())); } @Override @@ -353,9 +225,11 @@ public class TypeDiscoverer implements TypeInformation { Assert.notNull(method, "Method most not be null"); - return Streamable.of(method.getParameters()).stream().map(MethodParameter::forParameter) - .map(it -> ResolvableType.forMethodParameter(it, resolvableType)).map(TypeDiscoverer::new) - .collect(Collectors.toList()); + return Arrays.stream(method.getParameters()) // + .map(MethodParameter::forParameter) // + .map(it -> ResolvableType.forMethodParameter(it, resolvableType)) // + .> map(TypeInformation::of) // + .toList(); } @@ -373,46 +247,24 @@ public class TypeDiscoverer implements TypeInformation { return this; } - List candidates = new ArrayList<>(); + var resolvableSuperType = resolvableType.as(superType); + var type = resolvableType.getType(); - ResolvableType genericSuperclass = resolvableType.getSuperType(); - if ((genericSuperclass != null) && !genericSuperclass.equals(ResolvableType.NONE)) { - candidates.add(genericSuperclass); + if (!(type instanceof Class) || !ObjectUtils.isEmpty(((Class) type).getTypeParameters())) { + return TypeInformation.of(resolvableSuperType); } - candidates.addAll(Arrays.asList(resolvableType.getInterfaces())); - - for (var candidate : candidates) { - if (ObjectUtils.nullSafeEquals(superType, candidate.toClass())) { - - if (resolvableType.getType() instanceof Class) { - - if (ObjectUtils.isEmpty(((Class) resolvableType.getType()).getTypeParameters())) { - Class[] classes = candidate.resolveGenerics(null); - - if (!Arrays.stream(classes).filter(it -> it != null).findAny().isPresent()) { - return new TypeDiscoverer<>(ResolvableType.forRawClass(superType)); - } - } - } - return new TypeDiscoverer(ResolvableType.forClass(superType, getType())); - } else { - var sup = candidate.getSuperType(); - if ((sup != null) && !ResolvableType.NONE.equals(sup)) { - if (sup.equals(resolvableType)) { - return this; - } - return new TypeDiscoverer(sup); - } - } - } + var noGenericsResolvable = !Arrays.stream(resolvableSuperType.resolveGenerics()) + .filter(it -> it != null) + .findAny() + .isPresent(); - return new TypeDiscoverer(resolvableType.as(superType)); + return noGenericsResolvable + ? new ClassTypeInformation<>(ResolvableType.forRawClass(superType)) + : TypeInformation.of(resolvableSuperType); } - /* (non-Javadoc) - * @see org.springframework.data.util.TypeInformation#isAssignableFrom(org.springframework.data.util.TypeInformation) - */ + @Override public boolean isAssignableFrom(TypeInformation target) { TypeInformation superTypeInformation = target.getSuperTypeInformation(getType()); @@ -420,6 +272,7 @@ public class TypeDiscoverer implements TypeInformation { if (superTypeInformation == null) { return false; } + if (superTypeInformation.equals(this)) { return true; } @@ -433,62 +286,58 @@ public class TypeDiscoverer implements TypeInformation { @Override public List> getTypeArguments() { + return typeArguments.get(); + } + + private List> doGetTypeArguments() { if (!resolvableType.hasGenerics()) { return Collections.emptyList(); } - return Arrays.stream(resolvableType.getGenerics()).map(it -> { - if ((it == null) || ResolvableType.NONE.equals(it)) { - return null; - } - return new TypeDiscoverer<>(it); - - }).collect(Collectors.toList()); + return Arrays.stream(resolvableType.getGenerics()) + .> map(it -> it.resolve(Object.class) == null ? null : TypeInformation.of(it)) + .toList(); } @Override - public TypeInformation specialize(ClassTypeInformation type) { - // if(isAssignableFrom(type)) { - // return new ClassTypeInformation(type.getType()); - // } - // return new NewTypeDiscoverer(type.resolvableType.as(getType())); - // if(type.resolvableType.isAssignableFrom(type.resolvableType)) { - // return (TypeInformation) type; - // } - - if (this.resolvableType.getGenerics().length == type.resolvableType.getGenerics().length) { - return new TypeDiscoverer<>( + @SuppressWarnings("unchecked") + public TypeInformation specialize(TypeInformation type) { + + if (this.getTypeArguments().size() == type.getTypeArguments().size()) { + return (TypeInformation) TypeInformation.of( ResolvableType.forClassWithGenerics(type.getType(), this.resolvableType.getGenerics())); } - return new ClassTypeInformation(type.getType()); + return TypeInformation.of((Class) type.getType()); } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { + if (this == o) { return true; } + if ((o == null) || !ClassUtils.isAssignable(getClass(), o.getClass())) { return false; } - TypeDiscoverer that = (TypeDiscoverer) o; + var that = (TypeDiscoverer) o; if (!ObjectUtils.nullSafeEquals(getType(), that.getType())) { return false; } - List> collect1 = Arrays.stream(resolvableType.getGenerics()).map(ResolvableType::toClass) + var collect1 = Arrays.stream(resolvableType.getGenerics()) // + .map(ResolvableType::toClass) // .collect(Collectors.toList()); - List> collect2 = Arrays.stream(that.resolvableType.getGenerics()).map(ResolvableType::toClass) + + var collect2 = Arrays.stream(that.resolvableType.getGenerics()) // + .map(ResolvableType::toClass) // .collect(Collectors.toList()); - if (!ObjectUtils.nullSafeEquals(collect1, collect2)) { - return false; - } - return true; + return ObjectUtils.nullSafeEquals(collect1, collect2); } @Override @@ -498,6 +347,57 @@ public class TypeDiscoverer implements TypeInformation { @Override public String toString() { - return getType().getName(); + return resolvableType.toString(); + } + + @Nullable + private TypeInformation getTypeArgument(Class bound, int index) { + + var superTypeInformation = getSuperTypeInformation(bound); + + if (superTypeInformation == null) { + return null; + } + + var arguments = superTypeInformation.getTypeArguments(); + + if (arguments.isEmpty() || (index > (arguments.size() - 1))) { + return null; + } + + return arguments.get(index); + } + + private Optional> getPropertyInformation(String fieldname) { + + 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)) + .map(TypeInformation::of); + } + + private ResolvableType from(PropertyDescriptor descriptor, Class rawType) { + + var method = descriptor.getReadMethod(); + + if (method != null) { + return ResolvableType.forMethodReturnType(method, rawType); + } + + method = descriptor.getWriteMethod(); + + if (method != null) { + return ResolvableType.forMethodParameter(method, 0, rawType); + } + + return ResolvableType.forType(descriptor.getPropertyType(), resolvableType); + } + + private boolean isNullableWrapper() { + return NullableWrapperConverters.supports(getType()); } } diff --git a/src/main/java/org/springframework/data/util/TypeInformation.java b/src/main/java/org/springframework/data/util/TypeInformation.java index 6ee8788c6..4423d267a 100644 --- a/src/main/java/org/springframework/data/util/TypeInformation.java +++ b/src/main/java/org/springframework/data/util/TypeInformation.java @@ -17,10 +17,15 @@ package org.springframework.data.util; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.Set; +import org.springframework.core.ResolvableType; import org.springframework.core.convert.TypeDescriptor; import org.springframework.lang.Nullable; +import org.springframework.util.Assert; /** * Interface to access property types and resolving generics on the way. Starting with a {@link ClassTypeInformation} @@ -30,9 +35,77 @@ import org.springframework.lang.Nullable; * @author Mark Paluch * @author Alessandro Nistico * @author Johannes Englmeier + * @author Christoph Strobl */ +@SuppressWarnings({ "deprecation", "rawtypes" }) public interface TypeInformation { + public static final TypeInformation COLLECTION = ClassTypeInformation.COLLECTION; + public static final TypeInformation LIST = ClassTypeInformation.LIST; + public static final TypeInformation SET = ClassTypeInformation.SET; + public static final TypeInformation MAP = ClassTypeInformation.MAP; + public static final TypeInformation OBJECT = ClassTypeInformation.OBJECT; + + static TypeInformation orObject(@Nullable ResolvableType type) { + return type == null ? ClassTypeInformation.OBJECT : of(type); + } + + /** + * Creates a new {@link TypeInformation} from the given {@link ResolvableType}. + * + * @param type must not be {@literal null}. + * @return will never be {@literal null}. + * @since 3.0 + */ + public static TypeInformation of(ResolvableType type) { + + Assert.notNull(type, "Type must not be null"); + + return type.hasGenerics() || (type.isArray() && type.getComponentType().hasGenerics()) // + ? TypeDiscoverer.td(type) + : ClassTypeInformation.cti(type); + } + + /** + * Creates a new {@link TypeInformation} for the given {@link Class}. + * + * @param type must not be {@literal null}. + * @return will never be {@literal null}. + * @since 3.0 + */ + public static TypeInformation of(Class type) { + + Assert.notNull(type, "Type must not be null"); + + return ClassTypeInformation.from(type); + } + + /** + * Returns a {@link TypeInformation} for the given {@link Method}. + * + * @param method must not be {@literal null}. + * @return will never be {@literal null}. + * @since 3.0 + */ + public static TypeInformation fromReturnTypeOf(Method method) { + + Assert.notNull(method, "Method must not be null"); + + return fromReturnTypeOf(method, null); + } + + /** + * Returns a {@link TypeInformation} for the given method as declared on the given type. + * + * @param method must not be {@literal null}. + * @param type can be {@literal null}. + * @return will never be {@literal null}. + * @since 3.0 + */ + public static TypeInformation fromReturnTypeOf(Method method, @Nullable Class type) { + return ClassTypeInformation.fromReturnTypeOf(method, type); + } + /** * Returns the {@link TypeInformation}s for the parameters of the given {@link Constructor}. * @@ -162,7 +235,7 @@ public interface TypeInformation { default TypeInformation getUserTypeInformation() { Class userType = ProxyUtils.getUserClass(getType()); - return userType.equals(getType()) ? this : ClassTypeInformation.from(userType); + return userType.equals(getType()) ? this : TypeInformation.of(userType); } /** @@ -276,12 +349,27 @@ public interface TypeInformation { * * @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. */ - TypeInformation specialize(ClassTypeInformation type); + @Deprecated + default TypeInformation 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 + * generics are involved. + * + * @param type must not be {@literal null}. + * @return will never be {@literal null}. + */ + @SuppressWarnings("unchecked") default TypeInformation specialize(TypeInformation type) { - return specialize(ClassTypeInformation.from(type.getType())); + return (TypeInformation) type; } + /** * Returns whether the current type is a sub type of the given one, i.e. whether it's assignable but not the same one. * diff --git a/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java b/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java index 604b9ce16..480540711 100644 --- a/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java +++ b/src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java @@ -29,12 +29,10 @@ import java.util.Map; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.projection.Accessor; import org.springframework.data.projection.MethodInterceptorFactory; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -146,7 +144,7 @@ public class JsonProjectingMethodInterceptorFactory implements MethodInterceptor public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); - TypeInformation returnType = ClassTypeInformation.fromReturnTypeOf(method); + TypeInformation returnType = TypeInformation.fromReturnTypeOf(method); ResolvableType type = ResolvableType.forMethodReturnType(method); boolean isCollectionResult = Collection.class.isAssignableFrom(type.getRawClass()); type = isCollectionResult ? type : ResolvableType.forClassWithGenerics(List.class, type); diff --git a/src/main/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverSupport.java b/src/main/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverSupport.java index 852faee0e..0a1c27ef4 100644 --- a/src/main/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverSupport.java +++ b/src/main/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverSupport.java @@ -29,7 +29,6 @@ import org.springframework.data.querydsl.binding.QuerydslBindingsFactory; import org.springframework.data.querydsl.binding.QuerydslPredicate; import org.springframework.data.querydsl.binding.QuerydslPredicateBuilder; import org.springframework.data.util.CastUtils; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -135,7 +134,7 @@ public abstract class QuerydslPredicateArgumentResolverSupport { Optional annotation = predicateAnnotation.synthesize(MergedAnnotation::isPresent); return annotation.filter(it -> !Object.class.equals(it.root()))// - .> map(it -> ClassTypeInformation.from(it.root()))// + .> map(it -> TypeInformation.of(it.root()))// .orElseGet(() -> detectDomainType(parameter)); } @@ -147,7 +146,7 @@ public abstract class QuerydslPredicateArgumentResolverSupport { throw new IllegalArgumentException("Method parameter is not backed by a method"); } - return detectDomainType(ClassTypeInformation.fromReturnTypeOf(method)); + return detectDomainType(TypeInformation.fromReturnTypeOf(method)); } private static TypeInformation detectDomainType(TypeInformation source) { diff --git a/src/test/java/org/springframework/data/convert/ConfigurableTypeInformationMapperUnitTests.java b/src/test/java/org/springframework/data/convert/ConfigurableTypeInformationMapperUnitTests.java index 214745a1a..c94acafc8 100755 --- a/src/test/java/org/springframework/data/convert/ConfigurableTypeInformationMapperUnitTests.java +++ b/src/test/java/org/springframework/data/convert/ConfigurableTypeInformationMapperUnitTests.java @@ -25,10 +25,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; - import org.springframework.data.mapping.Alias; import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link ConfigurableTypeInformationMapper}. @@ -64,14 +63,14 @@ class ConfigurableTypeInformationMapperUnitTests @Test void writesMapKeyForType() { - assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class))).isEqualTo(Alias.of("1")); - assertThat(mapper.createAliasFor(ClassTypeInformation.from(Object.class))).isEqualTo(Alias.NONE); + assertThat(mapper.createAliasFor(TypeInformation.of(String.class))).isEqualTo(Alias.of("1")); + assertThat(mapper.createAliasFor(TypeInformation.of(Object.class))).isEqualTo(Alias.NONE); } @Test void readsTypeForMapKey() { - assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(ClassTypeInformation.from(String.class)); + assertThat(mapper.resolveTypeFrom(Alias.of("1"))).isEqualTo(TypeInformation.of(String.class)); assertThat(mapper.resolveTypeFrom(Alias.of("unmapped"))).isNull(); } } diff --git a/src/test/java/org/springframework/data/convert/DefaultTypeMapperUnitTests.java b/src/test/java/org/springframework/data/convert/DefaultTypeMapperUnitTests.java index 1ab7cee62..3f7a01f06 100755 --- a/src/test/java/org/springframework/data/convert/DefaultTypeMapperUnitTests.java +++ b/src/test/java/org/springframework/data/convert/DefaultTypeMapperUnitTests.java @@ -46,7 +46,7 @@ import org.springframework.data.util.TypeInformation; @MockitoSettings(strictness = Strictness.LENIENT) class DefaultTypeMapperUnitTests { - static final TypeInformation STRING_TYPE_INFO = ClassTypeInformation.from(String.class); + static final TypeInformation STRING_TYPE_INFO = TypeInformation.of(String.class); static final Alias ALIAS = Alias.of(String.class.getName()); @Mock TypeAliasAccessor> accessor; @@ -88,9 +88,9 @@ class DefaultTypeMapperUnitTests { @Test // DATACMNS-783 void specializesRawSourceTypeUsingGenericContext() { - var root = ClassTypeInformation.from(Foo.class); + var root = TypeInformation.of(Foo.class); var propertyType = root.getProperty("abstractBar"); - TypeInformation barType = ClassTypeInformation.from(Bar.class); + TypeInformation barType = TypeInformation.of(Bar.class); doReturn(Alias.of(barType)).when(accessor).readAliasFrom(source); doReturn(barType).when(mapper).resolveTypeFrom(Alias.of(barType)); diff --git a/src/test/java/org/springframework/data/convert/MappingContextTypeInformationMapperUnitTests.java b/src/test/java/org/springframework/data/convert/MappingContextTypeInformationMapperUnitTests.java index 2c278af9d..b35e08c69 100755 --- a/src/test/java/org/springframework/data/convert/MappingContextTypeInformationMapperUnitTests.java +++ b/src/test/java/org/springframework/data/convert/MappingContextTypeInformationMapperUnitTests.java @@ -16,7 +16,6 @@ package org.springframework.data.convert; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.util.ClassTypeInformation.from; import java.util.Collections; @@ -28,7 +27,7 @@ import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.SampleMappingContext; import org.springframework.data.mapping.context.SamplePersistentProperty; import org.springframework.data.util.AnnotatedTypeScanner; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link MappingContextTypeInformationMapper}. @@ -58,7 +57,7 @@ class MappingContextTypeInformationMapperUnitTests { mapper = new MappingContextTypeInformationMapper(mappingContext); - assertThat(mapper.createAliasFor(ClassTypeInformation.from(Entity.class)).hasValue("foo")).isTrue(); + assertThat(mapper.createAliasFor(TypeInformation.of(Entity.class)).hasValue("foo")).isTrue(); } @Test @@ -69,7 +68,7 @@ class MappingContextTypeInformationMapperUnitTests { mapper = new MappingContextTypeInformationMapper(mappingContext); - assertThat(mapper.createAliasFor(from(Entity.class)).hasValue("foo")).isTrue(); + assertThat(mapper.createAliasFor(TypeInformation.of(Entity.class)).hasValue("foo")).isTrue(); } @Test @@ -79,7 +78,7 @@ class MappingContextTypeInformationMapperUnitTests { mappingContext.initialize(); mapper = new MappingContextTypeInformationMapper(mappingContext); - assertThat(mapper.createAliasFor(from(String.class)).isPresent()).isFalse(); + assertThat(mapper.createAliasFor(TypeInformation.of(String.class)).isPresent()).isFalse(); } @Test @@ -94,7 +93,7 @@ class MappingContextTypeInformationMapperUnitTests { PersistentEntity entity = mappingContext.getRequiredPersistentEntity(Entity.class); assertThat(entity).isNotNull(); - assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(from(Entity.class)); + assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(TypeInformation.of(Entity.class)); } @Test // DATACMNS-485 diff --git a/src/test/java/org/springframework/data/convert/SimpleTypeInformationMapperUnitTests.java b/src/test/java/org/springframework/data/convert/SimpleTypeInformationMapperUnitTests.java index 93b589da0..8de558a7b 100755 --- a/src/test/java/org/springframework/data/convert/SimpleTypeInformationMapperUnitTests.java +++ b/src/test/java/org/springframework/data/convert/SimpleTypeInformationMapperUnitTests.java @@ -39,7 +39,7 @@ class SimpleTypeInformationMapperUnitTests { var type = mapper.resolveTypeFrom(Alias.of("java.lang.String")); - TypeInformation expected = ClassTypeInformation.from(String.class); + TypeInformation expected = TypeInformation.of(String.class); assertThat(type).isEqualTo(expected); } @@ -73,7 +73,7 @@ class SimpleTypeInformationMapperUnitTests { @Test void usesFullyQualifiedClassNameAsTypeKey() { - assertThat(mapper.createAliasFor(ClassTypeInformation.from(String.class))) + assertThat(mapper.createAliasFor(TypeInformation.of(String.class))) .isEqualTo(Alias.of(String.class.getName())); } diff --git a/src/test/java/org/springframework/data/mapping/ParameterUnitTests.java b/src/test/java/org/springframework/data/mapping/ParameterUnitTests.java index ef1dae92a..85f88757a 100755 --- a/src/test/java/org/springframework/data/mapping/ParameterUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/ParameterUnitTests.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -38,7 +36,7 @@ class ParameterUnitTests

> { @Mock PersistentEntity entity; @Mock PersistentEntity stringEntity; - private TypeInformation type = ClassTypeInformation.from(Object.class); + private TypeInformation type = TypeInformation.of(Object.class); private Annotation[] annotations = new Annotation[0]; @Test @@ -84,7 +82,7 @@ class ParameterUnitTests

> { void twoParametersWithDifferenTypeAreNotEqual() { var left = new Parameter("name", type, annotations, entity); - var right = new Parameter("name", ClassTypeInformation.from(String.class), annotations, + var right = new Parameter("name", TypeInformation.of(String.class), annotations, stringEntity); assertThat(left).isNotEqualTo(right); diff --git a/src/test/java/org/springframework/data/mapping/PreferredConstructorDiscovererUnitTests.java b/src/test/java/org/springframework/data/mapping/PreferredConstructorDiscovererUnitTests.java index a979d22b6..7443da754 100755 --- a/src/test/java/org/springframework/data/mapping/PreferredConstructorDiscovererUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PreferredConstructorDiscovererUnitTests.java @@ -24,13 +24,12 @@ import java.lang.annotation.Target; import java.util.Iterator; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.annotation.Value; import org.springframework.data.annotation.PersistenceConstructor; import org.springframework.data.mapping.PreferredConstructorDiscovererUnitTests.Outer.Inner; import org.springframework.data.mapping.model.BasicPersistentEntity; import org.springframework.data.mapping.model.PreferredConstructorDiscoverer; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link PreferredConstructorDiscoverer}. @@ -94,7 +93,7 @@ class PreferredConstructorDiscovererUnitTests

> { @Test // DATACMNS-134, DATACMNS-1126 void discoversInnerClassConstructorCorrectly() { - PersistentEntity entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class)); + PersistentEntity entity = new BasicPersistentEntity<>(TypeInformation.of(Inner.class)); assertThat(PreferredConstructorDiscoverer.discover(entity)).satisfies(constructor -> { @@ -107,7 +106,7 @@ class PreferredConstructorDiscovererUnitTests

> { void skipsSyntheticConstructor() { PersistentEntity entity = new BasicPersistentEntity<>( - ClassTypeInformation.from(SyntheticConstructor.class)); + TypeInformation.of(SyntheticConstructor.class)); assertThat(PreferredConstructorDiscoverer.discover(entity)).satisfies(constructor -> { @@ -222,11 +221,11 @@ class PreferredConstructorDiscovererUnitTests

> { static class ClassWithMetaAnnotatedParameter { - ClassWithMetaAnnotatedParameter(@MyValue String value) { } + ClassWithMetaAnnotatedParameter(@MyValue String value) {} } @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Value("${hello-world}") - @interface MyValue { } + @interface MyValue {} } diff --git a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java index 4276ee05d..b2cb298ab 100755 --- a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java @@ -23,8 +23,6 @@ import java.util.Set; import java.util.regex.Pattern; import org.junit.jupiter.api.Test; - -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -44,7 +42,7 @@ class PropertyPathUnitTests { assertThat(reference.hasNext()).isFalse(); assertThat(reference.toDotPath()).isEqualTo("userName"); - assertThat(reference.getOwningType()).isEqualTo(ClassTypeInformation.from(Foo.class)); + assertThat(reference.getOwningType()).isEqualTo(TypeInformation.of(Foo.class)); } @Test diff --git a/src/test/java/org/springframework/data/mapping/PropertyReferenceExceptionUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyReferenceExceptionUnitTests.java index 152a0b985..49f722c6e 100755 --- a/src/test/java/org/springframework/data/mapping/PropertyReferenceExceptionUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyReferenceExceptionUnitTests.java @@ -21,8 +21,6 @@ import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; - -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -33,7 +31,7 @@ import org.springframework.data.util.TypeInformation; */ public class PropertyReferenceExceptionUnitTests { - static final TypeInformation TYPE_INFO = ClassTypeInformation.from(Sample.class); + static final TypeInformation TYPE_INFO = TypeInformation.of(Sample.class); static final List NO_PATHS = Collections.emptyList(); @Test diff --git a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java index c64540367..f50174067 100755 --- a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java +++ b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java @@ -28,7 +28,6 @@ import org.springframework.data.mapping.PropertyHandler; import org.springframework.data.mapping.model.BasicPersistentEntity; import org.springframework.data.mapping.model.Property; import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -45,7 +44,7 @@ class AbstractMappingContextIntegrationTests> { context.setInitialEntitySet(Collections.singleton(Person.class)); context.initialize(); - assertThat(context.getManagedTypes()).contains(ClassTypeInformation.from(Person.class)); + assertThat(context.getManagedTypes()).contains(TypeInformation.of(Person.class)); } @Test // DATACMNS-457 diff --git a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java index f584649d7..b7bb21258 100755 --- a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java @@ -232,7 +232,7 @@ class AbstractMappingContextUnitTests { void shouldIgnoreKotlinOverrideCtorPropertyInSuperClass() { var entity = context - .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyTypeWithCtor.class)); + .getPersistentEntity(TypeInformation.of(ShadowingPropertyTypeWithCtor.class)); entity.doWithProperties((PropertyHandler) property -> { assertThat(property.getField().getDeclaringClass()).isIn(ShadowingPropertyTypeWithCtor.class, ShadowedPropertyTypeWithCtor.class); @@ -243,7 +243,7 @@ class AbstractMappingContextUnitTests { void shouldIncludeAssignableKotlinOverridePropertyInSuperClass() { var entity = context - .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyType.class)); + .getPersistentEntity(TypeInformation.of(ShadowingPropertyType.class)); entity.doWithProperties((PropertyHandler) property -> { assertThat(property.getField().getDeclaringClass()).isIn(ShadowedPropertyType.class, ShadowingPropertyType.class); }); @@ -253,7 +253,7 @@ class AbstractMappingContextUnitTests { void shouldIncludeAssignableShadowedPropertyInSuperClass() { var entity = context - .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyAssignable.class)); + .getPersistentEntity(TypeInformation.of(ShadowingPropertyAssignable.class)); assertThat(StreamUtils.createStreamFromIterator(entity.iterator()) .filter(it -> it.getField().getDeclaringClass().equals(ShadowedPropertyAssignable.class)).findFirst() // @@ -271,7 +271,7 @@ class AbstractMappingContextUnitTests { void shouldIgnoreNonAssignableOverridePropertyInSuperClass() { var entity = context - .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyNotAssignable.class)); + .getPersistentEntity(TypeInformation.of(ShadowingPropertyNotAssignable.class)); entity.doWithProperties((PropertyHandler) property -> { assertThat(property.getField().getDeclaringClass()).isEqualTo(ShadowingPropertyNotAssignable.class); }); diff --git a/src/test/java/org/springframework/data/mapping/context/PersistentEntitiesUnitTests.java b/src/test/java/org/springframework/data/mapping/context/PersistentEntitiesUnitTests.java index 465784206..fa11882e3 100755 --- a/src/test/java/org/springframework/data/mapping/context/PersistentEntitiesUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/context/PersistentEntitiesUnitTests.java @@ -24,12 +24,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Reference; import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.model.BasicPersistentEntity; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link PersistentEntities}. @@ -76,7 +75,7 @@ class PersistentEntitiesUnitTests { assertThat(entities.getPersistentEntity(Sample.class)).isPresent(); assertThat(entities.getPersistentEntity(Object.class)).isNotPresent(); - assertThat(entities.getManagedTypes()).contains(ClassTypeInformation.from(Sample.class)); + assertThat(entities.getManagedTypes()).contains(TypeInformation.of(Sample.class)); assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> assertThat(entities).contains(it)); } diff --git a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java index 7e7c037da..6ce8b9731 100755 --- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java @@ -35,13 +35,10 @@ import org.jmolecules.ddd.types.AggregateRoot; import org.jmolecules.ddd.types.Identifier; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - -import org.springframework.data.convert.PropertyValueConverter; import org.springframework.data.mapping.Association; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.Person; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.Optionals; import org.springframework.data.util.TypeInformation; import org.springframework.util.ReflectionUtils; @@ -62,7 +59,7 @@ public class AbstractPersistentPropertyUnitTests { @BeforeEach void setUp() { - typeInfo = ClassTypeInformation.from(TestClassComplex.class); + typeInfo = TypeInformation.of(TestClassComplex.class); entity = new BasicPersistentEntity<>(typeInfo); typeHolder = new SimpleTypeHolder(); } @@ -142,7 +139,7 @@ public class AbstractPersistentPropertyUnitTests { void doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven() { var field = ReflectionUtils.findField(AccessorTestClass.class, "id"); - var property = Property.of(ClassTypeInformation.from(AccessorTestClass.class), field); + var property = Property.of(TypeInformation.of(AccessorTestClass.class), field); PersistentProperty persistentProperty = new SamplePersistentProperty(property, getEntity(AccessorTestClass.class), typeHolder); @@ -247,12 +244,12 @@ public class AbstractPersistentPropertyUnitTests { } private BasicPersistentEntity getEntity(Class type) { - return new BasicPersistentEntity<>(ClassTypeInformation.from(type)); + return new BasicPersistentEntity<>(TypeInformation.of(type)); } private SamplePersistentProperty getProperty(Class type, String name) { - TypeInformation typeInformation = ClassTypeInformation.from(type); + TypeInformation typeInformation = TypeInformation.of(type); var field = Optional.ofNullable(ReflectionUtils.findField(type, name)); var descriptor = getPropertyDescriptor(type, name); diff --git a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java index 34f40487a..9d71468e2 100755 --- a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java @@ -36,7 +36,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; - import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.annotation.AccessType; @@ -49,7 +48,7 @@ import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.context.SampleMappingContext; import org.springframework.data.mapping.context.SamplePersistentProperty; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.test.util.ReflectionTestUtils; @@ -328,7 +327,7 @@ public class AnnotationBasedPersistentPropertyUnitTests

it.equals(ClassTypeInformation.from(Sample.class))); + .allMatch(it -> it.equals(TypeInformation.of(Sample.class))); } @Test // #2438 @@ -461,8 +460,7 @@ public class AnnotationBasedPersistentPropertyUnitTests

> { var failed = new AtomicBoolean(false); PersistentEntity entity = new BasicPersistentEntity( - ClassTypeInformation.from(EntityWithAnnotation.class), null) { + TypeInformation.of(EntityWithAnnotation.class), null) { @Nullable @Override @@ -378,7 +377,7 @@ class BasicPersistentEntityUnitTests> { } private BasicPersistentEntity createEntity(Class type, Comparator comparator) { - return new BasicPersistentEntity<>(ClassTypeInformation.from(type), comparator); + return new BasicPersistentEntity<>(TypeInformation.of(type), comparator); } private static PersistentEntity createPopulatedPersistentEntity(Class type) { diff --git a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiatorUnitTests.java b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiatorUnitTests.java index 3e201e689..4e5078f58 100755 --- a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiatorUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiatorUnitTests.java @@ -18,7 +18,6 @@ package org.springframework.data.mapping.model; import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.springframework.data.util.ClassTypeInformation.from; import java.lang.reflect.Constructor; import java.util.Arrays; @@ -40,7 +39,6 @@ import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PreferredConstructor; import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.ObjectInstantiator; import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiatorUnitTests.Outer.Inner; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.ReflectionUtils; @@ -104,7 +102,7 @@ class ClassGeneratingEntityInstantiatorUnitTests

@Test // DATACMNS-134, DATACMNS-578 void createsInnerClassInstanceCorrectly() { - var entity = new BasicPersistentEntity(from(Inner.class)); + var entity = new BasicPersistentEntity(TypeInformation.of(Inner.class)); assertThat(entity.getInstanceCreatorMetadata()).satisfies(constructor -> { var parameter = constructor.getParameters().iterator().next(); @@ -130,7 +128,7 @@ class ClassGeneratingEntityInstantiatorUnitTests

@SuppressWarnings({ "unchecked", "rawtypes" }) void capturesContextOnInstantiationException() throws Exception { - PersistentEntity entity = new BasicPersistentEntity<>(from(Sample.class)); + PersistentEntity entity = new BasicPersistentEntity<>(TypeInformation.of(Sample.class)); doReturn("FOO").when(provider).getParameterValue(any(Parameter.class)); @@ -159,8 +157,9 @@ class ClassGeneratingEntityInstantiatorUnitTests

@SuppressWarnings({ "unchecked", "rawtypes" }) void createsInstancesWithRecursionAndSameCtorArgCountCorrectly() { - PersistentEntity outer = new BasicPersistentEntity<>(from(SampleWithReference.class)); - PersistentEntity inner = new BasicPersistentEntity<>(from(Sample.class)); + PersistentEntity outer = new BasicPersistentEntity<>( + TypeInformation.of(SampleWithReference.class)); + PersistentEntity inner = new BasicPersistentEntity<>(TypeInformation.of(Sample.class)); doReturn(2L, "FOO").when(provider).getParameterValue(any(Parameter.class)); @@ -193,7 +192,8 @@ class ClassGeneratingEntityInstantiatorUnitTests

@SuppressWarnings({ "unchecked", "rawtypes" }) void createsInstancesWithFactoryMethodCorrectly() { - PersistentEntity entity = new BasicPersistentEntity<>(from(WithFactoryMethod.class)); + PersistentEntity entity = new BasicPersistentEntity<>( + TypeInformation.of(WithFactoryMethod.class)); doReturn(2L, "FOO").when(provider).getParameterValue(any(Parameter.class)); @@ -436,7 +436,7 @@ class ClassGeneratingEntityInstantiatorUnitTests

void entityInstantiatorShouldFailForAbstractClass() { assertThatExceptionOfType(MappingInstantiationException.class).isThrownBy(() -> this.instance - .createInstance(new BasicPersistentEntity<>(ClassTypeInformation.from(AbstractDto.class)), provider)); + .createInstance(new BasicPersistentEntity<>(TypeInformation.of(AbstractDto.class)), provider)); } private void prepareMocks(Class type) { diff --git a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java index 8c9b8b31e..ad239abee 100755 --- a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java +++ b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryEntityTypeTests.java @@ -21,7 +21,6 @@ import java.io.Serializable; import java.time.LocalDateTime; import org.junit.jupiter.api.Test; - import org.springframework.data.annotation.Id; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.SampleMappingContext; diff --git a/src/test/java/org/springframework/data/mapping/model/EntityCreatorMetadataDiscovererUnitTests.java b/src/test/java/org/springframework/data/mapping/model/EntityCreatorMetadataDiscovererUnitTests.java index 49e893cd8..bdd41105e 100644 --- a/src/test/java/org/springframework/data/mapping/model/EntityCreatorMetadataDiscovererUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/EntityCreatorMetadataDiscovererUnitTests.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.data.annotation.PersistenceCreator; import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.PreferredConstructor; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link InstanceCreatorMetadataDiscoverer}. @@ -33,7 +33,7 @@ class EntityCreatorMetadataDiscovererUnitTests { @Test void shouldDiscoverAnnotatedFactoryMethod() { - var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(FactoryMethodsPerson.class)); + var entity = new BasicPersistentEntity<>(TypeInformation.of(FactoryMethodsPerson.class)); var creator = InstanceCreatorMetadataDiscoverer.discover(entity); assertThat(creator).isInstanceOf(org.springframework.data.mapping.FactoryMethod.class); @@ -44,7 +44,7 @@ class EntityCreatorMetadataDiscovererUnitTests { @Test void shouldDiscoverAnnotatedConstructor() { - var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(ConstructorPerson.class)); + var entity = new BasicPersistentEntity<>(TypeInformation.of(ConstructorPerson.class)); var creator = InstanceCreatorMetadataDiscoverer.discover(entity); assertThat(creator).isInstanceOf(PreferredConstructor.class); @@ -53,7 +53,7 @@ class EntityCreatorMetadataDiscovererUnitTests { @Test void shouldDiscoverDefaultConstructor() { - var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Person.class)); + var entity = new BasicPersistentEntity<>(TypeInformation.of(Person.class)); var creator = InstanceCreatorMetadataDiscoverer.discover(entity); assertThat(creator).isInstanceOf(PreferredConstructor.class); @@ -62,7 +62,7 @@ class EntityCreatorMetadataDiscovererUnitTests { @Test void shouldRejectNonStaticFactoryMethod() { assertThatExceptionOfType(MappingException.class) - .isThrownBy(() -> new BasicPersistentEntity<>(ClassTypeInformation.from(NonStaticFactoryMethod.class))); + .isThrownBy(() -> new BasicPersistentEntity<>(TypeInformation.of(NonStaticFactoryMethod.class))); } static class Person { diff --git a/src/test/java/org/springframework/data/mapping/model/FactoryMethodUnitTests.java b/src/test/java/org/springframework/data/mapping/model/FactoryMethodUnitTests.java index 5575f57e8..19e82be2a 100644 --- a/src/test/java/org/springframework/data/mapping/model/FactoryMethodUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/FactoryMethodUnitTests.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.Test; import org.springframework.data.annotation.PersistenceCreator; import org.springframework.data.mapping.Parameter; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link org.springframework.data.mapping.FactoryMethod}. @@ -34,7 +34,7 @@ class FactoryMethodUnitTests { @Test void shouldCreateInstanceThroughFactoryMethod() { - var entity = new BasicPersistentEntity<>(ClassTypeInformation.from(FactoryPerson.class)); + var entity = new BasicPersistentEntity<>(TypeInformation.of(FactoryPerson.class)); var result = instantiators.getInstantiatorFor(entity).createInstance(entity, new ParameterValueProvider() { diff --git a/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java b/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java index 11dbd4670..34bd4c128 100755 --- a/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java @@ -27,7 +27,7 @@ import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.model.PersistentEntityParameterValueProviderUnitTests.Outer.Inner; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Unit tests for {@link PersistentEntityParameterValueProvider}. @@ -46,7 +46,7 @@ class PersistentEntityParameterValueProviderUnitTests

entity = new BasicPersistentEntity(ClassTypeInformation.from(Inner.class)) { + PersistentEntity entity = new BasicPersistentEntity(TypeInformation.of(Inner.class)) { @Override public P getPersistentProperty(String name) { @@ -69,7 +69,7 @@ class PersistentEntityParameterValueProviderUnitTests

entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Entity.class)); + PersistentEntity entity = new BasicPersistentEntity<>(TypeInformation.of(Entity.class)); ParameterValueProvider

provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider, Optional.of(property)); diff --git a/src/test/java/org/springframework/data/mapping/model/PropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/PropertyUnitTests.java index 4f68a69e1..60a63d64e 100644 --- a/src/test/java/org/springframework/data/mapping/model/PropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/PropertyUnitTests.java @@ -21,7 +21,7 @@ import lombok.Value; import lombok.With; import org.junit.jupiter.api.Test; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; import org.springframework.util.ReflectionUtils; /** @@ -35,17 +35,17 @@ class PropertyUnitTests { void shouldNotFindWitherMethod() { assertThat(Property - .of(ClassTypeInformation.from(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "id")) + .of(TypeInformation.of(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "id")) .getWither()).isEmpty(); assertThat(Property - .of(ClassTypeInformation.from(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "name")) + .of(TypeInformation.of(ImmutableType.class), ReflectionUtils.findField(ImmutableType.class, "name")) .getWither()).isEmpty(); } @Test // DATACMNS-1322 void shouldDiscoverWitherMethod() { - var property = Property.of(ClassTypeInformation.from(WitherType.class), + var property = Property.of(TypeInformation.of(WitherType.class), ReflectionUtils.findField(WitherType.class, "id")); assertThat(property.getWither()).isPresent().hasValueSatisfying(actual -> { @@ -57,7 +57,7 @@ class PropertyUnitTests { @Test // DATACMNS-1421 void shouldDiscoverDerivedWitherMethod() { - var property = Property.of(ClassTypeInformation.from(DerivedWitherClass.class), + var property = Property.of(TypeInformation.of(DerivedWitherClass.class), ReflectionUtils.findField(DerivedWitherClass.class, "id")); assertThat(property.getWither()).isPresent().hasValueSatisfying(actual -> { @@ -70,7 +70,7 @@ class PropertyUnitTests { @Test // DATACMNS-1421 void shouldNotDiscoverWitherMethodWithIncompatibleReturnType() { - var property = Property.of(ClassTypeInformation.from(AnotherLevel.class), + var property = Property.of(TypeInformation.of(AnotherLevel.class), ReflectionUtils.findField(AnotherLevel.class, "id")); assertThat(property.getWither()).isEmpty(); @@ -110,6 +110,7 @@ class PropertyUnitTests { static abstract class WitherIntermediateClass extends WitherBaseClass { + @Override abstract WitherIntermediateClass withId(String id); } @@ -121,6 +122,7 @@ class PropertyUnitTests { this.id = id; } + @Override DerivedWitherClass withId(String id) { return new DerivedWitherClass(id); } @@ -132,6 +134,7 @@ class PropertyUnitTests { super(id); } + @Override DerivedWitherClass withId(String id) { return new AnotherLevel(id); } diff --git a/src/test/java/org/springframework/data/mapping/model/ReflectionEntityInstantiatorUnitTests.java b/src/test/java/org/springframework/data/mapping/model/ReflectionEntityInstantiatorUnitTests.java index fb0d3a547..4b21ea537 100755 --- a/src/test/java/org/springframework/data/mapping/model/ReflectionEntityInstantiatorUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/ReflectionEntityInstantiatorUnitTests.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static org.springframework.data.mapping.model.ReflectionEntityInstantiator.*; -import static org.springframework.data.util.ClassTypeInformation.from; import java.lang.reflect.Constructor; import java.util.Arrays; @@ -34,6 +33,7 @@ import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PreferredConstructor; import org.springframework.data.mapping.model.ReflectionEntityInstantiatorUnitTests.Outer.Inner; +import org.springframework.data.util.TypeInformation; import org.springframework.util.ReflectionUtils; /** @@ -90,7 +90,7 @@ class ReflectionEntityInstantiatorUnitTests

> { @Test // DATACMNS-134 void createsInnerClassInstanceCorrectly() { - var entity = new BasicPersistentEntity(from(Inner.class)); + var entity = new BasicPersistentEntity(TypeInformation.of(Inner.class)); assertThat(entity.getInstanceCreatorMetadata()).satisfies(it -> { var parameter = it.getParameters().iterator().next(); @@ -116,7 +116,7 @@ class ReflectionEntityInstantiatorUnitTests

> { @SuppressWarnings({ "unchecked", "rawtypes" }) void capturesContextOnInstantiationException() throws Exception { - PersistentEntity entity = new BasicPersistentEntity<>(from(Sample.class)); + PersistentEntity entity = new BasicPersistentEntity<>(TypeInformation.of(Sample.class)); doReturn("FOO").when(provider).getParameterValue(any(Parameter.class)); diff --git a/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java b/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java index d53fc16fd..c177c9423 100755 --- a/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java @@ -23,14 +23,12 @@ import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.querydsl.QUser; import org.springframework.data.querydsl.SimpleEntityPathResolver; import org.springframework.data.querydsl.User; import org.springframework.data.repository.support.Repositories; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.servlet.ModelAndView; @@ -47,7 +45,7 @@ import com.querydsl.core.types.Predicate; */ class QuerydslBindingsFactoryUnitTests { - static final TypeInformation USER_TYPE = ClassTypeInformation.from(User.class); + static final TypeInformation USER_TYPE = TypeInformation.of(User.class); QuerydslBindingsFactory factory; @@ -123,7 +121,7 @@ class QuerydslBindingsFactoryUnitTests { void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() { assertThatIllegalStateException()// - .isThrownBy(() -> factory.createBindingsFor(ClassTypeInformation.from(ModelAndView.class)))// + .isThrownBy(() -> factory.createBindingsFor(TypeInformation.of(ModelAndView.class)))// .withMessageContaining(QuerydslPredicate.class.getSimpleName())// .withMessageContaining("root"); diff --git a/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java b/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java index 5d08b5fb7..1c7de1e6b 100755 --- a/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java +++ b/src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java @@ -21,7 +21,6 @@ import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.data.querydsl.Address; import org.springframework.data.querydsl.QAddress; @@ -29,7 +28,7 @@ import org.springframework.data.querydsl.QSpecialUser; import org.springframework.data.querydsl.QUser; import org.springframework.data.querydsl.SimpleEntityPathResolver; import org.springframework.data.querydsl.User; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; import com.querydsl.core.types.Path; import com.querydsl.core.types.Predicate; @@ -230,7 +229,7 @@ class QuerydslBindingsUnitTests { bindings.bind(QUser.user.address.city).as("city").first(CONTAINS_BINDING); - var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class)); + var path = bindings.getPropertyPath("city", TypeInformation.of(User.class)); assertThat(path).isNotNull(); assertThat(bindings.isPathAvailable("city", User.class)).isTrue(); @@ -245,14 +244,14 @@ class QuerydslBindingsUnitTests { bindings.including(QUser.user.address.city); bindings.bind(QUser.user.address.city).as("city").first(CONTAINS_BINDING); - var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class)); + var path = bindings.getPropertyPath("city", TypeInformation.of(User.class)); assertThat(path).isNotNull(); assertThat(bindings.isPathAvailable("city", User.class)).isTrue(); assertThat(bindings.isPathAvailable("address.city", User.class)).isTrue(); - var propertyPath = bindings.getPropertyPath("address.city", ClassTypeInformation.from(User.class)); + var propertyPath = bindings.getPropertyPath("address.city", TypeInformation.of(User.class)); assertThat(propertyPath).isNotNull(); assertAdapterWithTargetBinding(bindings.getBindingForPath(propertyPath), CONTAINS_BINDING); @@ -263,7 +262,7 @@ class QuerydslBindingsUnitTests { bindings.bind(QUser.user.address.city).as("city").withDefaultBinding(); - var path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class)); + var path = bindings.getPropertyPath("city", TypeInformation.of(User.class)); assertThat(path).isNotNull(); assertThat(bindings.getBindingForPath(path)).isNotPresent(); diff --git a/src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java b/src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java index 22bec3679..be48982f0 100755 --- a/src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java +++ b/src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java @@ -23,7 +23,6 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.data.querydsl.Address; import org.springframework.data.querydsl.QSpecialUser; import org.springframework.data.querydsl.QUser; @@ -32,7 +31,8 @@ import org.springframework.data.querydsl.SimpleEntityPathResolver; import org.springframework.data.querydsl.User; import org.springframework.data.querydsl.UserWrapper; import org.springframework.data.querydsl.Users; -import org.springframework.data.util.ClassTypeInformation; +// import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; import org.springframework.data.util.Version; import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.util.LinkedMultiValueMap; @@ -51,7 +51,7 @@ import com.querydsl.core.types.dsl.StringPath; */ class QuerydslPredicateBuilderUnitTests { - static final ClassTypeInformation USER_TYPE = ClassTypeInformation.from(User.class); + static final TypeInformation USER_TYPE = TypeInformation.of(User.class); static final QuerydslBindings DEFAULT_BINDINGS = new QuerydslBindings(); static final SingleValueBinding CONTAINS_BINDING = (path, value) -> path.contains(value); @@ -79,8 +79,9 @@ class QuerydslPredicateBuilderUnitTests { @Test // DATACMNS-669, DATACMNS-1168 void getPredicateShouldReturnEmptyWhenPropertiesAreEmpty() { assertThat( - QuerydslPredicateBuilder.isEmpty(builder.getPredicate(ClassTypeInformation.OBJECT, values, DEFAULT_BINDINGS))) - .isTrue(); + QuerydslPredicateBuilder + .isEmpty(builder.getPredicate(TypeInformation.of(Object.class), values, DEFAULT_BINDINGS))) + .isTrue(); } @Test // GH-2418 @@ -89,11 +90,11 @@ class QuerydslPredicateBuilderUnitTests { DEFAULT_BINDINGS.bind(QUser.user.description).first(CONTAINS_BINDING); values.add("description", "Linz"); - var predicate = this.builder.getPredicate(ClassTypeInformation.from(User.class), values, DEFAULT_BINDINGS); + var predicate = this.builder.getPredicate(TypeInformation.of(User.class), values, DEFAULT_BINDINGS); assertThat(predicate).hasToString("contains(user.description,Linz)"); - predicate = this.builder.getPredicate(ClassTypeInformation.from(Address.class), values, DEFAULT_BINDINGS); + predicate = this.builder.getPredicate(TypeInformation.of(Address.class), values, DEFAULT_BINDINGS); assertThat(predicate).hasToString("address.description = Linz"); } @@ -214,7 +215,7 @@ class QuerydslPredicateBuilderUnitTests { bindings.bind(wrapper.user.as(QSpecialUser.class).specialProperty)// .first(QuerydslBindingsUnitTests.ContainsBinding.INSTANCE); - assertThat(builder.getPredicate(ClassTypeInformation.from(UserWrapper.class), values, bindings))// + assertThat(builder.getPredicate(TypeInformation.of(UserWrapper.class), values, bindings))// .isEqualTo(wrapper.user.as(QSpecialUser.class).specialProperty.contains("VALUE")); } diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java index e23b7c089..1948e6e57 100755 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java @@ -22,14 +22,12 @@ import java.util.Collection; import java.util.Optional; import org.junit.jupiter.api.Test; - import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.util.ClassUtils; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -84,7 +82,7 @@ class DefaultRepositoryMetadataUnitTests { RepositoryMetadata metadata = new DefaultRepositoryMetadata(GenericEntityRepository.class); TypeInformation domainType = metadata.getDomainTypeInformation(); assertThat(domainType.getType()).isEqualTo(GenericEntity.class); - assertThat(domainType.getTypeArguments()).containsExactly(ClassTypeInformation.from(String.class)); + assertThat(domainType.getTypeArguments()).containsExactly(TypeInformation.of(String.class)); } @Test diff --git a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java index 371e3ab75..fd82e3e2b 100755 --- a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java @@ -19,7 +19,6 @@ import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.springframework.data.repository.core.support.DummyRepositoryFactory.*; import java.io.Serializable; import java.lang.reflect.Method; @@ -40,25 +39,23 @@ import org.mockito.Mockito; 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.DefaultListableBeanFactory; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.Repository; import org.springframework.data.repository.RepositoryDefinition; import org.springframework.data.repository.core.EntityInformation; import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryMetadata; +import org.springframework.data.repository.core.support.DummyRepositoryFactory.MyRepositoryQuery; import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments; import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener.RepositoryMethodInvocation; import org.springframework.data.repository.core.support.RepositoryMethodInvocationListener.RepositoryMethodInvocationResult.State; diff --git a/src/test/java/org/springframework/data/repository/support/DomainClassConverterIntegrationTests.java b/src/test/java/org/springframework/data/repository/support/DomainClassConverterIntegrationTests.java index b7bb2dcca..60457b5c5 100755 --- a/src/test/java/org/springframework/data/repository/support/DomainClassConverterIntegrationTests.java +++ b/src/test/java/org/springframework/data/repository/support/DomainClassConverterIntegrationTests.java @@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; @@ -37,7 +36,7 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; import org.springframework.data.repository.core.support.RepositoryFactoryInformation; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; /** * Integration test for {@link DomainClassConverter}. @@ -66,8 +65,8 @@ class DomainClassConverterIntegrationTests { beanFactory.registerBeanDefinition("postProcessor", new RootBeanDefinition(PredictingProcessor.class)); beanFactory.registerBeanDefinition("repoFactory", new RootBeanDefinition(RepositoryFactoryBeanSupport.class)); - doReturn(ClassTypeInformation.from(Person.class)).when(information).getDomainTypeInformation(); - doReturn(ClassTypeInformation.from(Serializable.class)).when(information).getIdTypeInformation(); + doReturn(TypeInformation.of(Person.class)).when(information).getDomainTypeInformation(); + doReturn(TypeInformation.of(Serializable.class)).when(information).getIdTypeInformation(); doCallRealMethod().when(information).getDomainType(); doReturn(PersonRepository.class).when(factory).getObjectType(); doReturn(information).when(factory).getRepositoryInformation(); diff --git a/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java b/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java index abbd01472..bd8080e18 100755 --- a/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java +++ b/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java @@ -33,20 +33,18 @@ import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; - import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Slice; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.NullableWrapper; import org.springframework.data.util.Streamable; +import org.springframework.data.util.TypeInformation; import org.springframework.util.concurrent.ListenableFuture; import com.google.common.base.Optional; @@ -185,7 +183,7 @@ class QueryExecutionConvertersUnitTests { void unwrapsPages() throws Exception { var method = Sample.class.getMethod("pages"); - var returnType = ClassTypeInformation.fromReturnTypeOf(method); + var returnType = TypeInformation.fromReturnTypeOf(method); assertThat(QueryExecutionConverters.unwrapWrapperTypes(returnType).getType()) .isEqualTo(String.class); @@ -207,9 +205,7 @@ class QueryExecutionConvertersUnitTests { for (var methodName : Arrays.asList("tryMethod", "tryForSeqMethod")) { var method = Sample.class.getMethod(methodName); - - var type = QueryExecutionConverters - .unwrapWrapperTypes(ClassTypeInformation.fromReturnTypeOf(method)); + var type = QueryExecutionConverters.unwrapWrapperTypes(TypeInformation.fromReturnTypeOf(method)); assertThat(type.getType()).isEqualTo(Sample.class); } @@ -231,9 +227,7 @@ class QueryExecutionConvertersUnitTests { for (var methodName : Arrays.asList("tryMethod", "tryForSeqMethod")) { var method = Sample.class.getMethod(methodName); - - var type = QueryExecutionConverters - .unwrapWrapperTypes(ClassTypeInformation.fromReturnTypeOf(method)); + var type = QueryExecutionConverters.unwrapWrapperTypes(TypeInformation.fromReturnTypeOf(method)); assertThat(type.getType()).isEqualTo(Sample.class); } diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index 6cdd05c84..d12a5ff21 100755 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -16,7 +16,8 @@ package org.springframework.data.util; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.util.ClassTypeInformation.from; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertThat; import io.vavr.collection.Traversable; @@ -34,7 +35,7 @@ import org.springframework.aop.SpringProxy; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.AopConfigException; - +import org.springframework.core.ResolvableType; import org.springframework.data.mapping.Person; import org.springframework.lang.Nullable; @@ -49,7 +50,7 @@ public class ClassTypeInformationUnitTests { @Test public void discoversTypeForSimpleGenericField() { - TypeInformation discoverer = from(ConcreteType.class); + TypeInformation discoverer = TypeInformation.of(ConcreteType.class); assertThat(discoverer.getType()).isEqualTo(ConcreteType.class); @@ -63,7 +64,7 @@ public class ClassTypeInformationUnitTests { @Test public void discoversTypeForNestedGenericField() { - TypeInformation discoverer = from(ConcreteWrapper.class); + TypeInformation discoverer = TypeInformation.of(ConcreteWrapper.class); assertThat(discoverer.getType()).isEqualTo(ConcreteWrapper.class); assertThat(discoverer.getProperty("wrapped")).satisfies(it -> { @@ -79,14 +80,14 @@ public class ClassTypeInformationUnitTests { @SuppressWarnings("rawtypes") public void discoversBoundType() { - TypeInformation information = from(GenericTypeWithBound.class); + TypeInformation information = TypeInformation.of(GenericTypeWithBound.class); assertThat(information.getProperty("person")).satisfies(it -> assertThat(it.getType()).isEqualTo(Person.class)); } @Test public void discoversBoundTypeForSpecialization() { - TypeInformation information = from(SpecialGenericTypeWithBound.class); + TypeInformation information = TypeInformation.of(SpecialGenericTypeWithBound.class); assertThat(information.getProperty("person")) .satisfies(it -> assertThat(it.getType()).isEqualTo(SpecialPerson.class)); } @@ -95,7 +96,7 @@ public class ClassTypeInformationUnitTests { @SuppressWarnings("rawtypes") public void discoversBoundTypeForNested() { - TypeInformation information = from(AnotherGenericType.class); + TypeInformation information = TypeInformation.of(AnotherGenericType.class); assertThat(information.getProperty("nested")) .satisfies(it -> assertThat(it.getType()).isEqualTo(GenericTypeWithBound.class)); @@ -106,7 +107,7 @@ public class ClassTypeInformationUnitTests { @Test public void discoversArraysAndCollections() { - TypeInformation information = from(StringCollectionContainer.class); + TypeInformation information = TypeInformation.of(StringCollectionContainer.class); var array = information.getProperty("array"); @@ -132,7 +133,7 @@ public class ClassTypeInformationUnitTests { @Test public void discoversMapValueType() { - TypeInformation information = from(StringMapContainer.class); + TypeInformation information = TypeInformation.of(StringMapContainer.class); var genericMap = information.getProperty("genericMap"); @@ -148,8 +149,8 @@ public class ClassTypeInformationUnitTests { @Test public void typeInfoDoesNotEqualForGenericTypesWithDifferentParent() { - TypeInformation first = from(ConcreteWrapper.class); - TypeInformation second = from(AnotherConcreteWrapper.class); + TypeInformation first = TypeInformation.of(ConcreteWrapper.class); + TypeInformation second = TypeInformation.of(AnotherConcreteWrapper.class); assertThat(first.getProperty("wrapped").equals(second.getProperty("wrapped"))).isFalse(); } @@ -157,7 +158,7 @@ public class ClassTypeInformationUnitTests { @Test public void handlesPropertyFieldMismatchCorrectly() { - TypeInformation from = from(PropertyGetter.class); + TypeInformation from = TypeInformation.of(PropertyGetter.class); assertThat(from.getProperty("_name")).satisfies(it -> assertThat(it.getType()).isEqualTo(String.class)); assertThat(from.getProperty("name")).satisfies(it -> assertThat(it.getType()).isEqualTo(byte[].class)); @@ -166,14 +167,14 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-77 public void returnsSameInstanceForCachedClass() { - TypeInformation info = from(PropertyGetter.class); - assertThat(from(PropertyGetter.class)).isSameAs(info); + TypeInformation info = TypeInformation.of(PropertyGetter.class); + assertThat(TypeInformation.of(PropertyGetter.class)).isSameAs(info); } @Test // DATACMNS-39 public void resolvesWildCardTypeCorrectly() { - TypeInformation information = from(ClassWithWildCardBound.class); + TypeInformation information = TypeInformation.of(ClassWithWildCardBound.class); var wildcard = information.getProperty("wildcard"); @@ -192,7 +193,7 @@ public class ClassTypeInformationUnitTests { @Test public void resolvesTypeParametersCorrectly() { - TypeInformation information = from(ConcreteType.class); + TypeInformation information = TypeInformation.of(ConcreteType.class); var superTypeInformation = information.getSuperTypeInformation(GenericType.class); var parameters = superTypeInformation.getTypeArguments(); @@ -204,7 +205,7 @@ public class ClassTypeInformationUnitTests { @Test public void resolvesNestedInheritedTypeParameters() { - TypeInformation information = from(SecondExtension.class); + TypeInformation information = TypeInformation.of(SecondExtension.class); var superTypeInformation = information.getSuperTypeInformation(Base.class); var parameters = superTypeInformation.getTypeArguments(); @@ -215,7 +216,7 @@ public class ClassTypeInformationUnitTests { @Test public void discoveresMethodParameterTypesCorrectly() throws Exception { - TypeInformation information = from(SecondExtension.class); + TypeInformation information = TypeInformation.of(SecondExtension.class); var method = SecondExtension.class.getMethod("foo", Base.class); var informations = information.getParameterTypes(method); var returnTypeInformation = information.getReturnType(method); @@ -228,51 +229,54 @@ public class ClassTypeInformationUnitTests { @Test public void discoversImplementationBindingCorrectlyForString() throws Exception { - TypeInformation information = from(TypedClient.class); + TypeInformation information = TypeInformation.of(TypedClient.class); var method = TypedClient.class.getMethod("stringMethod", GenericInterface.class); var parameterType = information.getParameterTypes(method).get(0); - TypeInformation stringInfo = from(StringImplementation.class); + TypeInformation stringInfo = TypeInformation.of(StringImplementation.class); assertThat(parameterType.isAssignableFrom(stringInfo)).isTrue(); assertThat(stringInfo.getSuperTypeInformation(GenericInterface.class)).isEqualTo(parameterType); - assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isFalse(); + assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isFalse(); assertThat(parameterType - .isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isTrue(); + .isAssignableFrom( + TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isTrue(); } @Test public void discoversImplementationBindingCorrectlyForLong() throws Exception { - TypeInformation information = from(TypedClient.class); + TypeInformation information = TypeInformation.of(TypedClient.class); var method = TypedClient.class.getMethod("longMethod", GenericInterface.class); var parameterType = information.getParameterTypes(method).get(0); - assertThat(parameterType.isAssignableFrom(from(StringImplementation.class))).isFalse(); - assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isTrue(); + assertThat(parameterType.isAssignableFrom(TypeInformation.of(StringImplementation.class))).isFalse(); + assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isTrue(); assertThat(parameterType - .isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse(); + .isAssignableFrom( + TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse(); } @Test public void discoversImplementationBindingCorrectlyForNumber() throws Exception { - TypeInformation information = from(TypedClient.class); + TypeInformation information = TypeInformation.of(TypedClient.class); var method = TypedClient.class.getMethod("boundToNumberMethod", GenericInterface.class); var parameterType = information.getParameterTypes(method).get(0); - assertThat(parameterType.isAssignableFrom(from(StringImplementation.class))).isFalse(); - assertThat(parameterType.isAssignableFrom(from(LongImplementation.class))).isTrue(); + assertThat(parameterType.isAssignableFrom(TypeInformation.of(StringImplementation.class))).isFalse(); + assertThat(parameterType.isAssignableFrom(TypeInformation.of(LongImplementation.class))).isTrue(); assertThat(parameterType - .isAssignableFrom(from(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse(); + .isAssignableFrom( + TypeInformation.of(StringImplementation.class).getSuperTypeInformation(GenericInterface.class))).isFalse(); } @Test public void returnsComponentTypeForMultiDimensionalArrayCorrectly() { - TypeInformation information = from(String[][].class); + TypeInformation information = TypeInformation.of(String[][].class); assertThat(information.getType()).isEqualTo(String[][].class); assertThat(information.getComponentType()).satisfies(it -> assertThat(it.getType()).isEqualTo(String[].class)); @@ -282,27 +286,32 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-309 public void findsGetterOnInterface() { - TypeInformation information = from(Product.class); + TypeInformation information = TypeInformation.of(Product.class); - assertThat(information.getProperty("category.id")).isEqualTo(from(Long.class)); + assertThat(information.getProperty("category.id")).isEqualTo(TypeInformation.of(Long.class)); } @Test // DATACMNS-387 public void rejectsNullClass() { - assertThatIllegalArgumentException().isThrownBy(() -> ClassTypeInformation.from(null)); + assertThatIllegalArgumentException().isThrownBy(() -> TypeInformation.of((Class) null)); + } + + @Test // DATACMNS-387 + public void rejectsNullResolvableType() { + assertThatIllegalArgumentException().isThrownBy(() -> TypeInformation.of((ResolvableType) null)); } @Test // DATACMNS-422 public void returnsEmptyOptionalForRawTypesOnly() { - assertThat(from(MyRawIterable.class).getComponentType()).isNull(); - assertThat(from(MyIterable.class).getComponentType()).isNotNull(); + assertThat(TypeInformation.of(MyRawIterable.class).getComponentType()).isNull(); + assertThat(TypeInformation.of(MyIterable.class).getComponentType()).isNotNull(); } @Test // DATACMNS-440 public void detectsSpecialMapAsMapValueType() { - var seriously = from(SuperGenerics.class).getProperty("seriously"); + var seriously = TypeInformation.of(SuperGenerics.class).getProperty("seriously"); // Type assertThat(seriously.getType()).isEqualTo(SortedMap.class); @@ -321,14 +330,14 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-446 public void createsToStringRepresentation() { - assertThat(from(SpecialPerson.class).toString()) + assertThat(TypeInformation.of(SpecialPerson.class).toString()) .isEqualTo("org.springframework.data.util.ClassTypeInformationUnitTests$SpecialPerson"); } @Test // DATACMNS-590 public void resolvesNestedGenericsToConcreteType() { - var rootType = from(ConcreteRoot.class); + var rootType = TypeInformation.of(ConcreteRoot.class); assertThat(rootType.getProperty("subs").getActualType().getProperty("subSub").getType())// .isEqualTo(ConcreteSubSub.class); @@ -337,7 +346,7 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-594 public void considersGenericsOfTypeBounds() { - assertThat(from(ConcreteRootIntermediate.class) + assertThat(TypeInformation.of(ConcreteRootIntermediate.class) .getProperty("intermediate.content.intermediate.content").getType())// .isEqualTo(Leaf.class); } @@ -345,21 +354,21 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-783, DATACMNS-853 public void specializesTypeUsingTypeVariableContext() { - var root = from(Foo.class); + var root = TypeInformation.of(Foo.class); - assertThat(root.getProperty("abstractBar").specialize(from(Bar.class)))// + assertThat(root.getProperty("abstractBar").specialize(TypeInformation.of(Bar.class)))// .satisfies(it -> { assertThat(it.getType()).isEqualTo(Bar.class); - assertThat(it.getProperty("field").getType()).isEqualTo(Character.class); - assertThat(it.getProperty("anotherField").getType()).isEqualTo(Integer.class); + assertThat(it.getProperty("field").getType()).isEqualTo(Character.class); + assertThat(it.getProperty("anotherField").getType()).isEqualTo(Integer.class); }); } @Test // DATACMNS-783 public void usesTargetTypeDirectlyIfNoGenericsAreInvolved() { - var root = ClassTypeInformation.from(Foo.class); - ClassTypeInformation from = ClassTypeInformation.from(Bar.class); + var root = TypeInformation.of(Foo.class); + TypeInformation from = TypeInformation.of(Bar.class); assertThat(root.getProperty("object").specialize(from)).isEqualTo(from); } @@ -367,12 +376,12 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-855 public void specializedTypeEqualsAndHashCode() { - var root = ClassTypeInformation.from(Foo.class); + var root = TypeInformation.of(Foo.class); var abstractBar = root.getProperty("abstractBar"); - assertThat(Pair.of(abstractBar.specialize(ClassTypeInformation.from(Bar.class)), - abstractBar.specialize(ClassTypeInformation.from(Bar.class)))).satisfies(pair -> { + assertThat(Pair.of(abstractBar.specialize(TypeInformation.of(Bar.class)), + abstractBar.specialize(TypeInformation.of(Bar.class)))).satisfies(pair -> { assertThat(pair.getFirst()).isEqualTo(pair.getSecond()); assertThat(pair.getSecond()).isEqualTo(pair.getFirst()); assertThat(pair.getFirst().hashCode()).isEqualTo(pair.getSecond().hashCode()); @@ -382,7 +391,7 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-896 public void prefersLocalTypeMappingOverNestedWithSameGenericType() { - var information = from(Concrete.class); + var information = TypeInformation.of(Concrete.class); assertThat(information.getProperty("field").getType()).isEqualTo(Nested.class); } @@ -390,7 +399,7 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-940 public void detectsVavrTraversableComponentType() { - var information = from(SampleTraversable.class); + var information = TypeInformation.of(SampleTraversable.class); assertThat(information.getComponentType().getType()).isAssignableFrom(Integer.class); } @@ -398,7 +407,7 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-940 public void detectsVavrMapComponentAndValueType() { - var information = from(SampleMap.class); + var information = TypeInformation.of(SampleMap.class); assertThat(information.getComponentType().getType()).isAssignableFrom(String.class); @@ -408,8 +417,8 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-1138 public void usesTargetTypeForWildcardedBaseOnSpecialization() { - var wrapper = from(WildcardedWrapper.class); - var concrete = from(SomeConcrete.class); + var wrapper = TypeInformation.of(WildcardedWrapper.class); + var concrete = TypeInformation.of(SomeConcrete.class); var property = wrapper.getRequiredProperty("wildcarded"); @@ -419,14 +428,14 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-1571 public void considersGenericsOfTypeToSpecializeToIfFullyResolved() { - TypeInformation storeEvent = ClassTypeInformation.from(StoredEvent.class); + TypeInformation storeEvent = TypeInformation.of(StoredEvent.class); assertThat(storeEvent.getType()).isEqualTo(StoredEvent.class); var domainEvent = (TypeInformation) storeEvent.getProperty("event"); assertThat(domainEvent.getType()).isEqualTo(DomainEvent.class); var specialized = domainEvent - .specialize(ClassTypeInformation.from(OfferCreated.class)); + .specialize(TypeInformation.of(OfferCreated.class)); assertThat(specialized.getType()).isEqualTo(OfferCreated.class); assertThat(specialized.getProperty("aggregateId").getType()).isEqualTo(Long.class); @@ -436,14 +445,14 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-1571 public void mergesGenericsFromContextAndProvidedDefaultOnSpecialization() { - TypeInformation storeEvent = ClassTypeInformation.from(StoredEvent.class); + TypeInformation storeEvent = TypeInformation.of(StoredEvent.class); assertThat(storeEvent.getType()).isEqualTo(StoredEvent.class); var domainEvent = (TypeInformation) storeEvent.getProperty("event"); assertThat(domainEvent.getType()).isEqualTo(DomainEvent.class); var specialized = domainEvent - .specialize(ClassTypeInformation.from(GenericEvent.class)); + .specialize(TypeInformation.of(GenericEvent.class)); assertThat(specialized.getType()).isEqualTo(GenericEvent.class); assertThat(specialized.getProperty("aggregateId").getType()).isEqualTo(Long.class); @@ -453,7 +462,7 @@ public class ClassTypeInformationUnitTests { @Test // DATACMNS-1828 void discoversMapKeyAndValueTypeFromTypedMap() { - TypeInformation information = from(TypeWithTypedMap.class); + TypeInformation information = TypeInformation.of(TypeWithTypedMap.class); var typedMap = information.getProperty("typedMap"); @@ -477,20 +486,21 @@ public class ClassTypeInformationUnitTests { } @Test // GH-2485 - public void proxyTypeInformationShouldNotEqualUserClassTypeInfo () { + public void proxyTypeInformationShouldNotEqualUserClassTypeInfo() { - ClassTypeInformation typeInfoLeaf = from(Leaf.class); - ClassTypeInformation typeInformationLeafProxy = from(Leaf$$SpringProxy$873fa2e.class); + var typeInfoLeaf = TypeInformation.of(Leaf.class); + var typeInformationLeafProxy = TypeInformation + .of(Leaf$$SpringProxy$873fa2e.class); assertThat(typeInfoLeaf).isNotEqualTo(typeInformationLeafProxy); } - @Test // GH-2312 + @Test // GH-2312 void typeInfoShouldPreserveGenericParameter() { - TypeInformation wrapperTypeInfo = ClassTypeInformation.from(Wrapper.class); - TypeInformation fieldTypeInfo = wrapperTypeInfo.getProperty("field"); - TypeInformation valueTypeInfo = fieldTypeInfo.getProperty("value"); + var wrapperTypeInfo = TypeInformation.of(Wrapper.class); + var fieldTypeInfo = wrapperTypeInfo.getProperty("field"); + var valueTypeInfo = fieldTypeInfo.getProperty("value"); assertThat(valueTypeInfo.getType()).isEqualTo(Leaf.class); } @@ -706,7 +716,7 @@ public class ClassTypeInformationUnitTests { static class SomeConcrete extends SomeGeneric {} - static class GenericExtendingSomeGeneric extends SomeGeneric { } + static class GenericExtendingSomeGeneric extends SomeGeneric {} static class Wrapper { GenericExtendingSomeGeneric field; diff --git a/src/test/java/org/springframework/data/util/DataCmns511Tests.java b/src/test/java/org/springframework/data/util/DataCmns511Tests.java index 961673469..5a73fd1cf 100755 --- a/src/test/java/org/springframework/data/util/DataCmns511Tests.java +++ b/src/test/java/org/springframework/data/util/DataCmns511Tests.java @@ -33,7 +33,7 @@ public class DataCmns511Tests { @Test // DATACMNS-511 public void detectsEqualTypeVariableTypeInformationInstances() { - var createdBy = ClassTypeInformation.from(AbstractRole.class).getProperty("createdBy"); + var createdBy = TypeInformation.of(AbstractRole.class).getProperty("createdBy"); assertThat(createdBy.getProperty("roles").getActualType().getProperty("createdBy"))// .satisfies(second -> { diff --git a/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java b/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java index da2008fe0..052bfc6c8 100755 --- a/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java +++ b/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java @@ -16,13 +16,10 @@ package org.springframework.data.util; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.util.ClassTypeInformation.from; -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -31,8 +28,8 @@ import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowire; import org.springframework.core.ResolvableType; import org.springframework.util.ReflectionUtils; @@ -45,11 +42,6 @@ import org.springframework.util.ReflectionUtils; @ExtendWith(MockitoExtension.class) public class TypeDiscovererUnitTests { - private static final Map, Type> EMPTY_MAP = Collections.emptyMap(); - - @Mock Map, Type> firstMap; - @Mock Map, Type> secondMap; - @Test void rejectsNullType() { assertThatIllegalArgumentException().isThrownBy(() -> new TypeDiscoverer<>((ResolvableType) null)); @@ -58,27 +50,17 @@ public class TypeDiscovererUnitTests { @Test void isNotEqualIfTypesDiffer() { - var objectTypeInfo = new TypeDiscoverer(Object.class); - var stringTypeInfo = new TypeDiscoverer(String.class); + var objectTypeInfo = TypeInformation.of(Object.class); + var stringTypeInfo = TypeInformation.of(String.class); assertThat(objectTypeInfo.equals(stringTypeInfo)).isFalse(); } -// @Test -// void isNotEqualIfTypeVariableMapsDiffer() { -// -// assertThat(firstMap.equals(secondMap)).isFalse(); -// -// var first = new TypeDiscoverer(Object.class); -// var second = new TypeDiscoverer(Object.class); -// -// assertThat(first.equals(second)).isFalse(); -// } - @Test void dealsWithTypesReferencingThemselves() { - TypeInformation information = from(SelfReferencing.class); + var information = TypeInformation.of(SelfReferencing.class); + var first = information.getProperty("parent").getMapValueType(); var second = first.getProperty("map").getMapValueType(); @@ -88,7 +70,7 @@ public class TypeDiscovererUnitTests { @Test void dealsWithTypesReferencingThemselvesInAMap() { - TypeInformation information = from(SelfReferencingMap.class); + var information = TypeInformation.of(SelfReferencingMap.class); var property = information.getProperty("map"); assertThat(property.getMapValueType()).isEqualTo(information); @@ -97,7 +79,7 @@ public class TypeDiscovererUnitTests { @Test void returnsComponentAndValueTypesForMapExtensions() { - TypeInformation discoverer = new TypeDiscoverer<>(CustomMap.class); + TypeInformation discoverer = TypeInformation.of(CustomMap.class); assertThat(discoverer.getMapValueType().getType()).isEqualTo(Locale.class); assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class); @@ -106,7 +88,7 @@ public class TypeDiscovererUnitTests { @Test void returnsComponentTypeForCollectionExtension() { - var discoverer = new TypeDiscoverer(CustomCollection.class); + var discoverer = TypeInformation.of(CustomCollection.class); assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class); } @@ -114,7 +96,7 @@ public class TypeDiscovererUnitTests { @Test void returnsComponentTypeForArrays() { - var discoverer = new TypeDiscoverer(String[].class); + var discoverer = TypeInformation.of(String[].class); assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class); } @@ -122,7 +104,7 @@ public class TypeDiscovererUnitTests { @Test // DATACMNS-57 void discoveresConstructorParameterTypesCorrectly() throws NoSuchMethodException, SecurityException { - var discoverer = new TypeDiscoverer(GenericConstructors.class); + var discoverer = TypeInformation.of(GenericConstructors.class); var constructor = GenericConstructors.class.getConstructor(List.class, Locale.class); var types = discoverer.getParameterTypes(constructor); @@ -135,7 +117,7 @@ public class TypeDiscovererUnitTests { @SuppressWarnings("rawtypes") void returnsNullForComponentAndValueTypesForRawMaps() { - var discoverer = new TypeDiscoverer(Map.class); + var discoverer = TypeInformation.of(Map.class); assertThat(discoverer.getComponentType()).isNotNull(); assertThat(discoverer.getMapValueType()).isNotNull(); @@ -145,8 +127,8 @@ public class TypeDiscovererUnitTests { @SuppressWarnings("rawtypes") void doesNotConsiderTypeImplementingIterableACollection() { - var discoverer = new TypeDiscoverer(Person.class); - TypeInformation reference = from(Address.class); + var discoverer = TypeInformation.of(Person.class); + TypeInformation reference = TypeInformation.of(Address.class); var addresses = discoverer.getProperty("addresses"); @@ -166,7 +148,7 @@ public class TypeDiscovererUnitTests { @Test // DATACMNS-1342, DATACMNS-1430 void considersStreamableToBeCollectionLike() { - TypeInformation type = from(SomeStreamable.class); + TypeInformation type = TypeInformation.of(SomeStreamable.class); assertThat(type.isCollectionLike()).isTrue(); assertThat(type.getRequiredProperty("streamable").isCollectionLike()).isTrue(); @@ -175,7 +157,7 @@ public class TypeDiscovererUnitTests { @Test // DATACMNS-1419 void detectsSubTypes() { - var type = from(Set.class); + var type = TypeInformation.of(Set.class); assertThat(type.isSubTypeOf(Collection.class)).isTrue(); assertThat(type.isSubTypeOf(Set.class)).isFalse(); @@ -196,124 +178,115 @@ public class TypeDiscovererUnitTests { } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldNoGenericsInfoShouldBeEqual() { - Field addresses = ReflectionUtils.findField(Person.class, "addresses"); + var addresses = ReflectionUtils.findField(Person.class, "addresses"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class)); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class)); + var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses, Person.class)); + var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses, Person.class)); assertThat(discoverer1).isEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldNoGenericsWhenInherited() { - Field addresses = ReflectionUtils.findField(Person.class, "addresses"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses, Person.class)); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses, TypeExtendingPerson.class)); + var addresses = ReflectionUtils.findField(Person.class, "addresses"); + + var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses, Person.class)); + var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses, TypeExtendingPerson.class)); assertThat(discoverer1).isEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldNoGenericsOnDifferentTypes() { - Field addresses1 = ReflectionUtils.findField(Person.class, "addresses"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(addresses1, Person.class)); + var addresses1 = ReflectionUtils.findField(Person.class, "addresses"); + var discoverer1 = TypeInformation.of(ResolvableType.forField(addresses1, Person.class)); - Field addresses2 = ReflectionUtils.findField(OtherPerson.class, "addresses"); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(addresses2, OtherPerson.class)); + var addresses2 = ReflectionUtils.findField(OtherPerson.class, "addresses"); + var discoverer2 = TypeInformation.of(ResolvableType.forField(addresses2, OtherPerson.class)); assertThat(discoverer1).isEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldWithGenerics() { - Field field1 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, GenericPerson.class)); + var field1 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, GenericPerson.class)); - Field field2 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, GenericPerson.class)); + var field2 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, GenericPerson.class)); assertThat(discoverer1).isEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldWithGenericsSet() { - Field field1 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class)); + var field1 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class)); - Field field2 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class)); + var field2 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class)); assertThat(discoverer1).isEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldWithDifferentGenericsSet() { - Field field1 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class)); + var field1 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, TypeExtendingGenericPersonWithObject.class)); - Field field2 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithAddress.class)); + var field2 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithAddress.class)); assertThat(discoverer1).isNotEqualTo(discoverer2); assertThat(discoverer1.hashCode()).isNotEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void sameFieldWithDifferentNoGenericsAndObjectOneSet() { - Field field1 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer1 = new TypeDiscoverer<>(ResolvableType.forField(field1, GenericPerson.class)); + var field1 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer1 = TypeInformation.of(ResolvableType.forField(field1, GenericPerson.class)); - Field field2 = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer2 = new TypeDiscoverer<>(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class)); + var field2 = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer2 = TypeInformation.of(ResolvableType.forField(field2, TypeExtendingGenericPersonWithObject.class)); assertThat(discoverer1).isEqualTo(discoverer2); // TODO: notEquals assertThat(discoverer1.hashCode()).isEqualTo(discoverer2.hashCode()); } - @Test - // GH-2312 + @Test // GH-2312 void genericFieldOfType() { - Field field = ReflectionUtils.findField(GenericPerson.class, "value"); - TypeDiscoverer discoverer = new TypeDiscoverer<>(ResolvableType.forField(field, TypeExtendingGenericPersonWithAddress.class)); + var field = ReflectionUtils.findField(GenericPerson.class, "value"); + var discoverer = TypeInformation.of(ResolvableType.forField(field, TypeExtendingGenericPersonWithAddress.class)); - assertThat(discoverer).isEqualTo(ClassTypeInformation.from(Address.class)); - assertThat(discoverer.hashCode()).isEqualTo(ClassTypeInformation.from(Address.class).hashCode()); + assertThat(discoverer).isEqualTo(TypeInformation.of(Address.class)); + assertThat(discoverer.hashCode()).isEqualTo(TypeInformation.of(Address.class).hashCode()); } @Test // #2511 void considerVavrMapToBeAMap() { - var type = from(io.vavr.collection.Map.class); - - assertThat(type.isMap()).isTrue(); + assertThat(TypeInformation.of(io.vavr.collection.Map.class).isMap()).isTrue(); } @Test // #2517 void returnsComponentAndValueTypesForVavrMapExtensions() { - var discoverer = new TypeDiscoverer<>(CustomVavrMap.class); + var discoverer = TypeInformation.of(CustomVavrMap.class); assertThat(discoverer.getMapValueType().getType()).isEqualTo(Locale.class); assertThat(discoverer.getComponentType().getType()).isEqualTo(String.class); @@ -321,26 +294,36 @@ public class TypeDiscovererUnitTests { @Test // #2511 void considerVavrSetToBeCollectionLike() { - - var type = from(io.vavr.collection.Set.class); - - assertThat(type.isCollectionLike()).isTrue(); + assertThat(TypeInformation.of(io.vavr.collection.Set.class).isCollectionLike()).isTrue(); } @Test // #2511 void considerVavrSeqToBeCollectionLike() { - - var type = from(io.vavr.collection.Seq.class); - - assertThat(type.isCollectionLike()).isTrue(); + assertThat(TypeInformation.of(io.vavr.collection.Seq.class).isCollectionLike()).isTrue(); } @Test // #2511 void considerVavrListToBeCollectionLike() { + assertThat(TypeInformation.of(io.vavr.collection.List.class).isCollectionLike()).isTrue(); + } - var type = from(io.vavr.collection.List.class); + @Test + void typeInfoShouldPreserveGenericParameter() { - assertThat(type.isCollectionLike()).isTrue(); + TypeInformation wrapperTypeInfo = TypeInformation.of(Wrapper.class); + TypeInformation fieldTypeInfo = wrapperTypeInfo.getProperty("field"); + TypeInformation valueTypeInfo = fieldTypeInfo.getProperty("value"); + + assertThat(valueTypeInfo.getType()).isEqualTo(Leaf.class); + } + + @Test + void detectsMapKeyAndValueOnEnumMaps() { + + TypeInformation map = TypeInformation.of(EnumMapWrapper.class).getProperty("map"); + + assertThat(map.getComponentType().getType()).isEqualTo(Autowire.class); + assertThat(map.getMapValueType().getType()).isEqualTo(String.class); } class Person { @@ -369,7 +352,6 @@ public class TypeDiscovererUnitTests { } - abstract class Addresses implements Iterable
{ } @@ -415,4 +397,22 @@ public class TypeDiscovererUnitTests { } interface CustomVavrMap extends io.vavr.collection.Map {} + + // #2312 + + class SomeGeneric { + T value; + } + + class GenericExtendingSomeGeneric extends SomeGeneric {} + + class Wrapper { + GenericExtendingSomeGeneric field; + } + + class Leaf {} + + class EnumMapWrapper { + EnumMap map; + } } diff --git a/src/test/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverUnitTests.java b/src/test/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverUnitTests.java index 95b6480e2..8a7fc4971 100755 --- a/src/test/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverUnitTests.java +++ b/src/test/java/org/springframework/data/web/querydsl/QuerydslPredicateArgumentResolverUnitTests.java @@ -16,7 +16,7 @@ package org.springframework.data.web.querydsl; import static org.assertj.core.api.Assertions.*; -import static org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver.*; +import static org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolverSupport.*; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -26,7 +26,6 @@ import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.MergedAnnotation; @@ -39,7 +38,6 @@ import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; import org.springframework.data.querydsl.binding.QuerydslBindings; import org.springframework.data.querydsl.binding.QuerydslBindingsFactory; import org.springframework.data.querydsl.binding.QuerydslPredicate; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.hateoas.EntityModel; import org.springframework.http.HttpEntity; @@ -210,15 +208,15 @@ class QuerydslPredicateArgumentResolverUnitTests { TypeInformation type = ReflectionTestUtils.invokeMethod(resolver, "extractTypeInfo", getMethodParameterFor("predicateWithoutAnnotation", Predicate.class), MergedAnnotation.missing()); - assertThat(type).isEqualTo(ClassTypeInformation.from(User.class)); + assertThat(type).isEqualTo(TypeInformation.of(User.class)); } @Test // DATACMNS-669 @SuppressWarnings("rawtypes") void detectsDomainTypesCorrectly() { - TypeInformation USER_TYPE = ClassTypeInformation.from(User.class); - TypeInformation MODELA_AND_VIEW_TYPE = ClassTypeInformation.from(ModelAndView.class); + TypeInformation USER_TYPE = TypeInformation.of(User.class); + TypeInformation MODELA_AND_VIEW_TYPE = TypeInformation.of(ModelAndView.class); assertThat(extractTypeInfo(getMethodParameterFor("forEntity"), MergedAnnotation.missing())).isEqualTo(USER_TYPE); assertThat(extractTypeInfo(getMethodParameterFor("forResourceOfUser"), MergedAnnotation.missing()))