Use full type information for identifier and domain types exposed byRepositoryMetadata.

See #2518.
This commit is contained in:
Alex Nistico
2021-12-31 05:43:17 +01:00
committed by Oliver Drotbohm
parent 21e4fd5ffb
commit 58ed9ce211
17 changed files with 161 additions and 92 deletions

View File

@@ -53,6 +53,7 @@ import org.springframework.util.ReflectionUtils;
* @author Christoph Strobl
* @author Mark Paluch
* @author Jürgen Diez
* @author Alessandro Nistico
*/
class TypeDiscoverer<S> implements TypeInformation<S> {
@@ -293,6 +294,16 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
public Class<S> getType() {
return resolvedType.get();
}
@Override
public Type getGenericType() {
return type;
}
@Override
public TypeInformation<?> getGenericTypeInformation() {
return createInfo(type);
}
@Override
public ClassTypeInformation<?> getRawTypeInformation() {

View File

@@ -17,6 +17,7 @@ package org.springframework.data.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import org.springframework.lang.Nullable;
@@ -27,6 +28,7 @@ import org.springframework.lang.Nullable;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Alessandro Nistico
*/
public interface TypeInformation<S> {
@@ -148,6 +150,15 @@ public interface TypeInformation<S> {
* @return
*/
Class<S> getType();
/**
* Returns the type of the property with all resolvable generics applied
*
* @return
*/
default Type getGenericType() {
return getType();
}
/**
* Returns the user type of the property if proxied.
@@ -170,6 +181,13 @@ public interface TypeInformation<S> {
*/
ClassTypeInformation<?> getRawTypeInformation();
/**
* Returns a {@link TypeInformation} to represent the {@link TypeInformation} of the type of the current instance with all the generics parameters resolved.
*
* @return
*/
TypeInformation<?> getGenericTypeInformation();
/**
* Transparently returns the {@link java.util.Map} value type if the type is a {@link java.util.Map}, returns the
* component type if the type {@link #isCollectionLike()} or the simple type if none of this applies.

View File

@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* {@link TypeVariable} is being used in.
*
* @author Oliver Gierke
* @author Alessandro Nistico
*/
class TypeVariableTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
@@ -49,6 +50,11 @@ class TypeVariableTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
this.variable = variable;
}
@Override
public TypeInformation<?> getGenericTypeInformation() {
return createInfo(getTypeVariableMap().getOrDefault(variable, Object.class));
}
@Override
public boolean equals(@Nullable Object obj) {