Class GenericTypeContext
- java.lang.Object
-
- org.hibernate.search.util.common.reflect.impl.GenericTypeContext
-
public final class GenericTypeContext extends Object
A representation of generic parameters and their mapped values.Currently only used as a representation of type variables of a given type and its supertypes, in order to retrieve the type arguments of its supertypes. For instance this class, given the type
ArrayList<? extends Map<String, Integer>>, is able to determine that the type argument forList<?>is? extends Map<String, Integer>.This class is able to take into account the declaring context when performing resolution. For instance, given the following model:
... if an instance of this implementation was used to model the type ofclass A<T extends C> { GenericType<T> propertyOfA; } class B extends A<D> { } class C { } class D extends C { } class GenericType<T> { T propertyOfGenericType; }B.propertyOfA, then the propertyB.propertyOfAwould appear to have typeList<D>as one would expect, instead of typeT extends Cif we inferred the type solely based on generics information from typeA.This will also be true for more deeply nested references to a type variable, for instance the type of property
B.propertyOfA.propertyOfGenericTypewill correctly be inferred as D.Note that "type resolution" here only covers the resolution of a type parameter to the corresponding argument, i.e. "shallow" resolution. This class will not build new
ParameterizedTypeinstances to recursively replace type variables with their known value, unlike other libraries such as Guava.
-
-
Constructor Summary
Constructors Constructor Description GenericTypeContext(Type type)GenericTypeContext(GenericTypeContext declaringContext, Type type)GenericTypeContext(GenericTypeContext declaringContext, GenericTypeContext castBase, Type type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GenericTypeContextcastTo(Class<?> target)GenericTypeContextdeclaringContext()Stringname()Class<?>rawType()Optional<Type>resolveArrayElementType()Optional<Type>resolveTypeArgument(Class<?> rawSuperType, int typeParameterIndex)StringtoString()
-
-
-
Constructor Detail
-
GenericTypeContext
public GenericTypeContext(Type type)
-
GenericTypeContext
public GenericTypeContext(GenericTypeContext declaringContext, Type type)
-
GenericTypeContext
public GenericTypeContext(GenericTypeContext declaringContext, GenericTypeContext castBase, Type type)
-
-
Method Detail
-
rawType
public Class<?> rawType()
-
name
public String name()
-
declaringContext
public GenericTypeContext declaringContext()
-
castTo
public GenericTypeContext castTo(Class<?> target)
-
resolveTypeArgument
public Optional<Type> resolveTypeArgument(Class<?> rawSuperType, int typeParameterIndex)
-
-