Class GenericContextAwarePojoGenericTypeModel<T>
java.lang.Object
org.hibernate.search.mapper.pojo.model.spi.AbstractPojoGenericTypeModel<T>
org.hibernate.search.mapper.pojo.model.spi.GenericContextAwarePojoGenericTypeModel<T>
- All Implemented Interfaces:
PojoTypeModel<T>
public final class GenericContextAwarePojoGenericTypeModel<T>
extends AbstractPojoGenericTypeModel<T>
implements PojoTypeModel<T>
An implementation of
PojoTypeModel
that takes advantage of the context
in which a given property appears to derive more precise type information.
Instances wrap a PojoRawTypeModel
, and propagate generics information to properties
and their type by wrapping the property models as well.
For instance, given the following model:
class A<T extends C> {
GenericType<T> propertyOfA;
}
class B extends A<D> {
}
class C {
}
class D extends C {
}
class GenericType<T> {
T propertyOfGenericType;
}
... if an instance of this implementation was used to model the type of B.propertyOfA
,
then the property B.propertyOfA
would appear to have type List<D>
as one would expect,
instead of type T extends C
if we inferred the type solely based on generics information from type A
.
This will also be true for more deeply nested references to a type variable,
for instance the type of property B.propertyOfA.propertyOfGenericType
will correctly be inferred as D.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
-
Method Summary
Modifier and TypeMethodDescription<U> Optional<PojoTypeModel<? extends U>>
boolean
int
hashCode()
name()
typeArgument
(Class<?> rawSuperType, int typeParameterIndex) Methods inherited from class org.hibernate.search.mapper.pojo.model.spi.AbstractPojoGenericTypeModel
rawType, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.hibernate.search.mapper.pojo.model.spi.PojoTypeModel
rawType, toString
-
Method Details
-
name
- Specified by:
name
in interfacePojoTypeModel<T>
- Returns:
- A human-readable name for this type.
-
equals
- Specified by:
equals
in interfacePojoTypeModel<T>
- Overrides:
equals
in classObject
- Returns:
true
ifobj
is aPojoTypeModel
referencing the exact same type with the exact same exposed metadata.
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfacePojoTypeModel<T>
- Overrides:
hashCode
in classObject
-
property
- Specified by:
property
in interfacePojoTypeModel<T>
- Overrides:
property
in classAbstractPojoGenericTypeModel<T>
- Parameters:
propertyName
- The name of aproperty
in this type.- Returns:
- A representation of the property with the given name.
-
castTo
- Specified by:
castTo
in interfacePojoTypeModel<T>
- Type Parameters:
U
- The type to cast to.- Parameters:
target
- The type to cast to.- Returns:
- A new type model, representing the current type cast to the given type,
or
Optional.empty()
if casting is not supported. The type model will retain as much contextual type information as possible (type arguments, ...), so castingList<Integer>
toCollection
for example would returnCollection<Integer>
.
-
typeArgument
- Specified by:
typeArgument
in interfacePojoTypeModel<T>
- Parameters:
rawSuperType
- The supertype to resolve type parameters fortypeParameterIndex
- The index of the type parameter to resolve- Returns:
- The model for the type argument for the type parameter defined in
rawSuperType
at indextypeParameterIndex
, or an empty optional if the current type does not extendrawSuperType
. Implementations may decide to return a model of the raw type argument, or to retain generics information.
-
arrayElementType
- Specified by:
arrayElementType
in interfacePojoTypeModel<T>
- Returns:
- The model for the array element type, or an empty optional if the current type is not an array type. Implementations may decide to return a model of the raw array element type, or to retain generics information.
-