Class GenericContextAwarePojoGenericTypeModel<T>

  • All Implemented Interfaces:
    PojoGenericTypeModel<T>, PojoTypeModel<T>

    public final class GenericContextAwarePojoGenericTypeModel<T>
    extends AbstractPojoGenericTypeModel<T>
    implements PojoGenericTypeModel<T>
    An implementation of PojoGenericTypeModel 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.
    • Method Detail

      • name

        public String name()
        Specified by:
        name in interface PojoTypeModel<T>
        A human-readable name for this type.
      • castTo

        public <U> Optional<PojoTypeModel<? extends U>> castTo​(Class<U> target)
        Specified by:
        castTo in interface PojoTypeModel<T>
        Type Parameters:
        U - The type to cast to.
        target - The type to cast to.
        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 casting List<Integer> to Collection for example would return Collection<Integer>.
      • typeArgument

        public Optional<PojoGenericTypeModel<?>> typeArgument​(Class<?> rawSuperType,
                                                              int typeParameterIndex)
        Specified by:
        typeArgument in interface PojoGenericTypeModel<T>
        typeArgument in class AbstractPojoGenericTypeModel<T>
        rawSuperType - The supertype to resolve type parameters for
        typeParameterIndex - The index of the type parameter to resolve
        The model for the type argument for the type parameter defined in rawSuperType at index typeParameterIndex, or an empty optional if the current type does not extend rawSuperType. Implementations may decide to return a model of the raw type argument, or to retain generics information.