public class GenericTypeReflector
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
GenericTypeReflector.AnnotatedCaptureCacheKey |
(package private) static class |
GenericTypeReflector.CaptureCacheKey
A key representing a
CaptureType . |
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
BOX_TYPES |
private static java.lang.reflect.WildcardType |
UNBOUND_WILDCARD |
Constructor and Description |
---|
GenericTypeReflector() |
Modifier and Type | Method and Description |
---|---|
static java.lang.reflect.Type |
addWildcardParameters(java.lang.Class<?> clazz)
Returns a type representing the class, with all type parameters the unbound wildcard ("?").
|
static java.lang.reflect.AnnotatedType |
annotate(java.lang.reflect.Type type)
Recursively wraps a
Type into an AnnotatedType using the annotations found on
the erasure classes. |
static java.lang.reflect.AnnotatedType |
annotate(java.lang.reflect.Type type,
java.lang.annotation.Annotation[] annotations)
Recursively wraps a
Type into an AnnotatedType using the annotations found on
the erasure classes, plus adding the provided annotations to the top level Type only. |
private static java.lang.reflect.AnnotatedType |
annotate(java.lang.reflect.Type type,
boolean expandGenerics) |
private static java.lang.reflect.AnnotatedType |
annotate(java.lang.reflect.Type type,
boolean expandGenerics,
java.util.Map<GenericTypeReflector.CaptureCacheKey,java.lang.reflect.AnnotatedType> cache)
This is the method underlying both
annotate(Type) and annotate(Type, Annotation[]) . |
static java.lang.reflect.Type |
box(java.lang.reflect.Type type) |
private static void |
buildUpperBoundClassAndInterfaces(java.lang.reflect.Type type,
java.util.Set<java.lang.Class<?>> result)
Helper method for getUpperBoundClassAndInterfaces, adding the result to the given set.
|
static java.lang.reflect.AnnotatedParameterizedType |
capture(java.lang.reflect.AnnotatedParameterizedType type)
Applies capture conversion to the given type.
|
static java.lang.reflect.AnnotatedType |
capture(java.lang.reflect.AnnotatedType type)
Applies capture conversion to the given type.
|
private static boolean |
contains(java.lang.reflect.Type containingType,
java.lang.reflect.Type containedType) |
static boolean |
equals(java.lang.reflect.AnnotatedType t1,
java.lang.reflect.AnnotatedType t2)
Checks whether the two provided types are of the same structure and annotations on all levels.
|
static java.lang.Class<?> |
erase(java.lang.reflect.Type type)
Returns the erasure of the given type.
|
private static java.lang.reflect.AnnotatedParameterizedType |
expandClassGenerics(java.lang.Class<?> type) |
private static java.lang.reflect.AnnotatedType |
expandGenerics(java.lang.reflect.AnnotatedType type) |
private static void |
extractVariables(java.lang.reflect.AnnotatedParameterizedType resolvedTyped,
java.lang.reflect.AnnotatedParameterizedType unresolvedType,
java.lang.Class<?> declaringClass,
VarMap variables) |
static java.lang.reflect.AnnotatedType |
getArrayComponentType(java.lang.reflect.AnnotatedType type)
If type is an array type, returns the annotated type of the component of the array.
|
static java.lang.reflect.Type |
getArrayComponentType(java.lang.reflect.Type type)
If type is an array type, returns the type of the component of the array.
|
private static java.lang.reflect.AnnotatedType[] |
getArrayExactDirectSuperTypes(java.lang.reflect.AnnotatedType arrayType) |
private static java.lang.reflect.AnnotatedType[] |
getExactDirectSuperTypes(java.lang.reflect.AnnotatedType type)
Returns the direct supertypes of the given type.
|
static java.lang.reflect.AnnotatedType |
getExactFieldType(java.lang.reflect.Field f,
java.lang.reflect.AnnotatedType declaringType)
Resolves the exact type of the given field in the given type.
|
static java.lang.reflect.Type |
getExactFieldType(java.lang.reflect.Field f,
java.lang.reflect.Type type)
Resolves the exact type of the given field in the given type.
|
static java.lang.reflect.AnnotatedType[] |
getExactParameterTypes(java.lang.reflect.Executable exe,
java.lang.reflect.AnnotatedType declaringType)
Resolves the exact annotated parameter types of the given method/constructor in the given type.
|
static java.lang.reflect.Type[] |
getExactParameterTypes(java.lang.reflect.Executable exe,
java.lang.reflect.Type declaringType)
Resolves the exact parameter types of the given method/constructor in the given type.
|
static java.lang.reflect.AnnotatedType |
getExactReturnType(java.lang.reflect.Method m,
java.lang.reflect.AnnotatedType declaringType)
Resolves the exact return type of the given method in the given type.
|
static java.lang.reflect.Type |
getExactReturnType(java.lang.reflect.Method m,
java.lang.reflect.Type declaringType)
Resolves the exact return type of the given method in the given type.
|
static java.lang.reflect.AnnotatedType |
getExactSubType(java.lang.reflect.AnnotatedType superType,
java.lang.Class<?> searchSubClass)
The equivalent of
getExactSubType(Type, Class) but works with AnnotatedType s |
static java.lang.reflect.Type |
getExactSubType(java.lang.reflect.Type superType,
java.lang.Class<?> searchSubClass)
Finds the most specific subtype of
superType whose erasure is searchSubClass . |
static java.lang.reflect.AnnotatedType |
getExactSuperType(java.lang.reflect.AnnotatedType subType,
java.lang.Class<?> searchSuperClass)
The equivalent of
getExactSuperType(Type, Class) but works with AnnotatedType s |
static java.lang.reflect.Type |
getExactSuperType(java.lang.reflect.Type subType,
java.lang.Class<?> searchSuperClass)
Finds the most specific supertype of
subType whose erasure is searchSuperClass . |
static java.lang.reflect.AnnotatedType |
getFieldType(java.lang.reflect.Field f,
java.lang.reflect.AnnotatedType declaringType)
Resolves the type of the given field in the given type.
|
private static java.lang.reflect.AnnotatedType |
getFieldType(java.lang.reflect.Field f,
java.lang.reflect.AnnotatedType declaringType,
VarMap.MappingMode mappingMode) |
static java.lang.reflect.Type |
getFieldType(java.lang.reflect.Field f,
java.lang.reflect.Type type)
Resolves the type of the given field in the given type.
|
static java.lang.reflect.AnnotatedType[] |
getParameterTypes(java.lang.reflect.Executable exe,
java.lang.reflect.AnnotatedType declaringType) |
private static java.lang.reflect.AnnotatedType[] |
getParameterTypes(java.lang.reflect.Executable exe,
java.lang.reflect.AnnotatedType declaringType,
VarMap.MappingMode mappingMode) |
static java.lang.reflect.Type[] |
getParameterTypes(java.lang.reflect.Executable exe,
java.lang.reflect.Type declaringType) |
static java.lang.reflect.AnnotatedType |
getReturnType(java.lang.reflect.Method m,
java.lang.reflect.AnnotatedType declaringType)
Resolves the return type of the given method in the given type.
|
private static java.lang.reflect.AnnotatedType |
getReturnType(java.lang.reflect.Method m,
java.lang.reflect.AnnotatedType declaringType,
VarMap.MappingMode mappingMode) |
static java.lang.reflect.Type |
getReturnType(java.lang.reflect.Method m,
java.lang.reflect.Type declaringType)
Resolves the return type of the given method in the given type.
|
static java.lang.String |
getTypeName(java.lang.reflect.Type type)
Returns the display name of a Type.
|
static java.lang.reflect.AnnotatedType |
getTypeParameter(java.lang.reflect.AnnotatedType type,
java.lang.reflect.TypeVariable<? extends java.lang.Class<?>> variable)
Gets the type parameter for a given type that is the value for a given type variable.
|
static java.lang.reflect.Type |
getTypeParameter(java.lang.reflect.Type type,
java.lang.reflect.TypeVariable<? extends java.lang.Class<?>> variable) |
static java.util.List<java.lang.Class<?>> |
getUpperBoundClassAndInterfaces(java.lang.reflect.Type type)
Returns list of classes and interfaces that are supertypes of the given type.
|
static int |
hashCode(java.lang.reflect.AnnotatedType... types) |
(package private) static int |
hashCode(java.util.stream.Stream<java.lang.annotation.Annotation> annotations) |
private static boolean |
isArraySupertype(java.lang.reflect.Type arraySuperType,
java.lang.reflect.Type subType) |
static boolean |
isBoxType(java.lang.reflect.Type type) |
static boolean |
isFullyBound(java.lang.reflect.Type type) |
static boolean |
isMissingTypeParameters(java.lang.reflect.Type type)
Checks if the given type is a class that is supposed to have type parameters, but doesn't.
|
static boolean |
isSuperType(java.lang.reflect.Type superType,
java.lang.reflect.Type subType)
Checks if the capture of subType is a subtype of superType
|
private static java.lang.reflect.AnnotatedType |
mapTypeParameters(java.lang.reflect.AnnotatedType toMapType,
java.lang.reflect.AnnotatedType typeAndParams)
Maps type parameters in a type to their values.
|
private static java.lang.reflect.AnnotatedType |
mapTypeParameters(java.lang.reflect.AnnotatedType toMapType,
java.lang.reflect.AnnotatedType typeAndParams,
VarMap.MappingMode mappingMode) |
static java.lang.annotation.Annotation[] |
merge(java.lang.annotation.Annotation[]... annotations)
Merges an arbitrary number of annotations arrays, and removes duplicates.
|
static <T extends java.lang.reflect.AnnotatedType> |
mergeAnnotations(T t1,
T t2) |
static java.lang.reflect.AnnotatedType |
reduceBounded(java.lang.reflect.AnnotatedType type)
Recursively traverses the structure of the given type, reducing all bounded types
(
AnnotatedTypeVariable , AnnotatedWildcardType and AnnotatedCaptureType )
to their first bound. |
static <T extends java.lang.reflect.AnnotatedType> |
replaceAnnotations(T original,
java.lang.annotation.Annotation[] annotations)
Creates a new
AnnotatedType of the same type as the original, but with its annotations
replaced with the provided ones. |
static java.lang.reflect.AnnotatedParameterizedType |
replaceParameters(java.lang.reflect.AnnotatedParameterizedType type,
java.lang.reflect.AnnotatedType[] typeParameters)
Creates a new
AnnotatedParameterizedType of the same raw class as the provided type
by with all of its type parameters replaced by typeParameters . |
private static java.lang.reflect.AnnotatedParameterizedType |
replaceParameters(java.lang.reflect.AnnotatedParameterizedType type,
java.lang.annotation.Annotation[] annotations,
java.lang.reflect.AnnotatedType[] typeParameters) |
static java.lang.reflect.AnnotatedType |
resolveExactType(java.lang.reflect.AnnotatedType unresolved,
java.lang.reflect.AnnotatedType typeAndParams) |
static java.lang.reflect.Type |
resolveExactType(java.lang.reflect.Type unresolved,
java.lang.reflect.Type typeAndParams) |
static java.lang.reflect.AnnotatedType |
resolveType(java.lang.reflect.AnnotatedType unresolved,
java.lang.reflect.AnnotatedType typeAndParams) |
private static java.lang.reflect.AnnotatedType |
resolveType(java.lang.reflect.AnnotatedType unresolved,
java.lang.reflect.AnnotatedType typeAndParams,
VarMap.MappingMode mappingMode) |
static java.lang.reflect.Type |
resolveType(java.lang.reflect.Type unresolved,
java.lang.reflect.Type typeAndParams) |
static <T extends java.lang.reflect.AnnotatedType> |
toCanonical(T type)
Returns an
AnnotatedType functionally identical to the given one, but in a canonical form that
implements equals and hashCode . |
private static <T extends java.lang.reflect.AnnotatedType> |
toCanonical(T type,
java.util.function.Function<java.lang.reflect.Type,java.lang.reflect.Type> leafTransformer)
This is the method underlying
toCanonical(AnnotatedType) . |
static <T extends java.lang.reflect.AnnotatedType> |
toCanonicalBoxed(T type)
Returns an
AnnotatedType functionally identical to the given one, but in a canonical form that
implements equals and hashCode and has all the primitives replaced by their boxed form. |
static java.lang.reflect.AnnotatedType |
transform(java.lang.reflect.AnnotatedType type,
TypeVisitor visitor)
Recursively applies a transformation implemented by the provided
TypeVisitor
to the structure of the given type. |
(package private) static boolean |
typeArraysEqual(java.lang.reflect.AnnotatedType[] t1,
java.lang.reflect.AnnotatedType[] t2) |
static <T extends java.lang.reflect.AnnotatedType> |
updateAnnotations(T original,
java.lang.annotation.Annotation[] annotations)
Creates a new
AnnotatedType of the same structure as the original, but with its annotations
replaced with the provided ones. |
private static final java.lang.reflect.WildcardType UNBOUND_WILDCARD
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> BOX_TYPES
public static java.lang.Class<?> erase(java.lang.reflect.Type type)
public static java.lang.reflect.Type box(java.lang.reflect.Type type)
public static boolean isBoxType(java.lang.reflect.Type type)
public static boolean isFullyBound(java.lang.reflect.Type type)
private static java.lang.reflect.AnnotatedType mapTypeParameters(java.lang.reflect.AnnotatedType toMapType, java.lang.reflect.AnnotatedType typeAndParams)
toMapType
- Type possibly containing type argumentstypeAndParams
- must be either ParameterizedType, or (in case there are no type arguments, or it's a raw type) Classprivate static java.lang.reflect.AnnotatedType mapTypeParameters(java.lang.reflect.AnnotatedType toMapType, java.lang.reflect.AnnotatedType typeAndParams, VarMap.MappingMode mappingMode)
public static java.lang.reflect.AnnotatedType resolveExactType(java.lang.reflect.AnnotatedType unresolved, java.lang.reflect.AnnotatedType typeAndParams)
public static java.lang.reflect.Type resolveExactType(java.lang.reflect.Type unresolved, java.lang.reflect.Type typeAndParams)
public static java.lang.reflect.AnnotatedType resolveType(java.lang.reflect.AnnotatedType unresolved, java.lang.reflect.AnnotatedType typeAndParams)
public static java.lang.reflect.Type resolveType(java.lang.reflect.Type unresolved, java.lang.reflect.Type typeAndParams)
private static java.lang.reflect.AnnotatedType resolveType(java.lang.reflect.AnnotatedType unresolved, java.lang.reflect.AnnotatedType typeAndParams, VarMap.MappingMode mappingMode)
public static boolean isMissingTypeParameters(java.lang.reflect.Type type)
public static java.lang.reflect.Type addWildcardParameters(java.lang.Class<?> clazz)
addWildcardParameters(Map.class)
returns a type representing Map<?,?>
.public static java.lang.reflect.AnnotatedType getExactSuperType(java.lang.reflect.AnnotatedType subType, java.lang.Class<?> searchSuperClass)
getExactSuperType(Type, Class)
but works with AnnotatedType
ssubType
- The type whose supertype is to be searched forsearchSuperClass
- The class of the supertype to search forsearchSuperClass
with type parameters from subType
public static java.lang.reflect.Type getExactSuperType(java.lang.reflect.Type subType, java.lang.Class<?> searchSuperClass)
subType
whose erasure is searchSuperClass
.
In other words, returns a type representing the class searchSuperClass
plus its exact type parameters in subType
.
ParameterizedType
if searchSuperClass
is a real class or interface and subType
has parameters for itGenericArrayType
if searchSuperClass
is an array type, and subType
has type parameters for itClass
if subType
is a raw type, or has no type parameters for searchSuperClass
searchSuperClass
is not a superclass of subType
.For example, with class StringList implements List<String>
, getExactSuperType(StringList.class, Collection.class)
returns a ParameterizedType
representing Collection<String>
.
subType
- The type whose supertype is to be searched forsearchSuperClass
- The class of the supertype to search forsearchSuperClass
with type parameters from subType
public static java.lang.reflect.AnnotatedType getExactSubType(java.lang.reflect.AnnotatedType superType, java.lang.Class<?> searchSubClass)
getExactSubType(Type, Class)
but works with AnnotatedType
ssuperType
- The type whose subtype is to be searched forsearchSubClass
- The class of the subtype to search forsearchSubClass
with type parameters from superType
public static java.lang.reflect.Type getExactSubType(java.lang.reflect.Type superType, java.lang.Class<?> searchSubClass)
superType
whose erasure is searchSubClass
.
In other words, returns a type representing the class searchSubClass
plus its exact type parameters in superType
,
if they are possible to resolve.
AnnotatedParameterizedType
if searchSubClass
is a real class or interface and superType
has parameters for itAnnotatedArrayType
if searchSubClass
is an array type, and superType
has type parameters for itAnnotatedType
if superType
is a raw type, or has no type parameters for searchSubClass
searchSubClass
is not a subclass of superType
.For example, with getExactSubType(new TypeToken<List<String>>(){}.getAnnotatedType(), ArrayList.class)
returns a AnnotatedParameterizedType
representing ArrayList<String>
.
public static java.lang.reflect.AnnotatedType getTypeParameter(java.lang.reflect.AnnotatedType type, java.lang.reflect.TypeVariable<? extends java.lang.Class<?>> variable)
class StringList implements List<String>
,
getTypeParameter(StringList.class, Collection.class.getTypeParameters()[0])
returns String
.type
- The type to inspect.variable
- The type variable to find the value for.public static java.lang.reflect.Type getTypeParameter(java.lang.reflect.Type type, java.lang.reflect.TypeVariable<? extends java.lang.Class<?>> variable)
public static boolean isSuperType(java.lang.reflect.Type superType, java.lang.reflect.Type subType)
private static boolean isArraySupertype(java.lang.reflect.Type arraySuperType, java.lang.reflect.Type subType)
public static java.lang.reflect.AnnotatedType getArrayComponentType(java.lang.reflect.AnnotatedType type)
public static java.lang.reflect.Type getArrayComponentType(java.lang.reflect.Type type)
private static boolean contains(java.lang.reflect.Type containingType, java.lang.reflect.Type containedType)
private static void extractVariables(java.lang.reflect.AnnotatedParameterizedType resolvedTyped, java.lang.reflect.AnnotatedParameterizedType unresolvedType, java.lang.Class<?> declaringClass, VarMap variables)
private static java.lang.reflect.AnnotatedType[] getExactDirectSuperTypes(java.lang.reflect.AnnotatedType type)
private static java.lang.reflect.AnnotatedType[] getArrayExactDirectSuperTypes(java.lang.reflect.AnnotatedType arrayType)
public static java.lang.reflect.AnnotatedType getExactReturnType(java.lang.reflect.Method m, java.lang.reflect.AnnotatedType declaringType)
m.getAnnotatedReturnType()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in the return type, or declaringType
is a raw type.public static java.lang.reflect.Type getExactReturnType(java.lang.reflect.Method m, java.lang.reflect.Type declaringType)
m.getGenericReturnType()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in the return type, or declaringType
is a raw type.public static java.lang.reflect.AnnotatedType getReturnType(java.lang.reflect.Method m, java.lang.reflect.AnnotatedType declaringType)
getExactReturnType(Method, AnnotatedType)
.
This may be different from m.getAnnotatedReturnType()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in the return type, or declaringType
is a raw type.public static java.lang.reflect.Type getReturnType(java.lang.reflect.Method m, java.lang.reflect.Type declaringType)
getExactReturnType(Method, Type)
.
This may be different from m.getGenericReturnType()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in the return type, or declaringType
is a raw type.private static java.lang.reflect.AnnotatedType getReturnType(java.lang.reflect.Method m, java.lang.reflect.AnnotatedType declaringType, VarMap.MappingMode mappingMode)
public static java.lang.reflect.AnnotatedType getExactFieldType(java.lang.reflect.Field f, java.lang.reflect.AnnotatedType declaringType)
f.getAnnotatedType()
when the field was declared in a superclass,
or declaringType
has a type parameter that is used in the type of the field, or declaringType
is a raw type.public static java.lang.reflect.Type getExactFieldType(java.lang.reflect.Field f, java.lang.reflect.Type type)
f.getGenericType()
when the field was declared in a superclass,
or declaringType
has a type parameter that is used in the type of the field, or declaringType
is a raw type.public static java.lang.reflect.AnnotatedType getFieldType(java.lang.reflect.Field f, java.lang.reflect.AnnotatedType declaringType)
getExactFieldType(Field, AnnotatedType)
).
This may be different from f.getAnnotatedType()
when the field was declared in a superclass,
or declaringType
has a type parameter that is used in the type of the field, or declaringType
is a raw type.public static java.lang.reflect.Type getFieldType(java.lang.reflect.Field f, java.lang.reflect.Type type)
getExactFieldType(Field, Type)
).
This may be different from f.getGenericType()
when the field was declared in a superclass,
or declaringType
has a type parameter that is used in the type of the field, or declaringType
is a raw type.private static java.lang.reflect.AnnotatedType getFieldType(java.lang.reflect.Field f, java.lang.reflect.AnnotatedType declaringType, VarMap.MappingMode mappingMode)
public static java.lang.reflect.AnnotatedType[] getExactParameterTypes(java.lang.reflect.Executable exe, java.lang.reflect.AnnotatedType declaringType)
exe.getAnnotatedParameterTypes()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in one of the parameters, or declaringType
is a raw type.public static java.lang.reflect.Type[] getExactParameterTypes(java.lang.reflect.Executable exe, java.lang.reflect.Type declaringType)
exe.getParameterTypes()
when the method was declared in a superclass,
or declaringType
has a type parameter that is used in one of the parameters, or declaringType
is a raw type.public static java.lang.reflect.AnnotatedType[] getParameterTypes(java.lang.reflect.Executable exe, java.lang.reflect.AnnotatedType declaringType)
public static java.lang.reflect.Type[] getParameterTypes(java.lang.reflect.Executable exe, java.lang.reflect.Type declaringType)
private static java.lang.reflect.AnnotatedType[] getParameterTypes(java.lang.reflect.Executable exe, java.lang.reflect.AnnotatedType declaringType, VarMap.MappingMode mappingMode)
public static java.lang.reflect.AnnotatedType capture(java.lang.reflect.AnnotatedType type)
public static java.lang.reflect.AnnotatedParameterizedType capture(java.lang.reflect.AnnotatedParameterizedType type)
capture(AnnotatedType)
public static java.lang.String getTypeName(java.lang.reflect.Type type)
public static java.util.List<java.lang.Class<?>> getUpperBoundClassAndInterfaces(java.lang.reflect.Type type)
class {@literal Foo<A extends Number & Iterable<A>, B extends A>}
B
(Foo.class.getTypeParameters()[1]
)
returns a list containing Number
and Iterable
.
This is mostly useful if you get a type from one of the other methods in GenericTypeReflector
,
but you don't want to deal with all the different sorts of types,
and you are only really interested in concrete classes and interfaces.
private static java.lang.reflect.AnnotatedType annotate(java.lang.reflect.Type type, boolean expandGenerics)
public static java.lang.reflect.AnnotatedType annotate(java.lang.reflect.Type type)
Type
into an AnnotatedType
using the annotations found on
the erasure classes.type
- Type to annotatepublic static java.lang.reflect.AnnotatedType annotate(java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations)
Type
into an AnnotatedType
using the annotations found on
the erasure classes, plus adding the provided annotations to the top level Type
only.type
- Type to annotateSee annotate(Type)
private static java.lang.reflect.AnnotatedType annotate(java.lang.reflect.Type type, boolean expandGenerics, java.util.Map<GenericTypeReflector.CaptureCacheKey,java.lang.reflect.AnnotatedType> cache)
annotate(Type)
and annotate(Type, Annotation[])
.
If goes recursively through the structure of the provided Type
wrapping all type parameters,
bounds etc encountered into AnnotatedType
s using annotations found directly on the
corresponding erasure class, with a special treatment for CaptureType
which can have
infinitely recursive structure by having itself as its upper bound.type
- The type to annotatecache
- The cache for already encountered CaptureType
s. Necessary because
CaptureType
s can have infinitely recursive structure.See annotate(Type)
See annotate(Type, Annotation[])
See GenericTypeReflector.CaptureCacheKey
See CaptureType
public static <T extends java.lang.reflect.AnnotatedType> T replaceAnnotations(T original, java.lang.annotation.Annotation[] annotations)
AnnotatedType
of the same type as the original, but with its annotations
replaced with the provided ones.original
- The type whose structure is to be copiedannotations
- Annotations to use instead of the ones found on the original
public static <T extends java.lang.reflect.AnnotatedType> T updateAnnotations(T original, java.lang.annotation.Annotation[] annotations)
AnnotatedType
of the same structure as the original, but with its annotations
replaced with the provided ones.original
- The type whose structure is to be copiedannotations
- Extra annotations to be added on top of the ones found on the original
public static <T extends java.lang.reflect.AnnotatedType> T mergeAnnotations(T t1, T t2)
public static java.lang.reflect.AnnotatedParameterizedType replaceParameters(java.lang.reflect.AnnotatedParameterizedType type, java.lang.reflect.AnnotatedType[] typeParameters)
AnnotatedParameterizedType
of the same raw class as the provided type
by with all of its type parameters replaced by typeParameters
.type
- The original parameterized type from which the raw class is to be takentypeParameters
- The new type parameters to useprivate static java.lang.reflect.AnnotatedParameterizedType replaceParameters(java.lang.reflect.AnnotatedParameterizedType type, java.lang.annotation.Annotation[] annotations, java.lang.reflect.AnnotatedType[] typeParameters)
public static <T extends java.lang.reflect.AnnotatedType> T toCanonical(T type)
AnnotatedType
functionally identical to the given one, but in a canonical form that
implements equals
and hashCode
.type
- The type to turn into the canonical formpublic static <T extends java.lang.reflect.AnnotatedType> T toCanonicalBoxed(T type)
AnnotatedType
functionally identical to the given one, but in a canonical form that
implements equals
and hashCode
and has all the primitives replaced by their boxed form.type
- The type to turn into the canonical formprivate static <T extends java.lang.reflect.AnnotatedType> T toCanonical(T type, java.util.function.Function<java.lang.reflect.Type,java.lang.reflect.Type> leafTransformer)
toCanonical(AnnotatedType)
.
It recursively traverses the structure of the provided AnnotatedType
turning all type parameters,
bounds etc. into their canonical forms, with a special treatment for AnnotatedCaptureType
which can have infinitely recursive structure by having itself as its upper bound.type
- The type to annotateleafTransformer
- The transformer function to apply to leaf types (e.g. to box primitives)See toCanonical(AnnotatedType)
See GenericTypeReflector.AnnotatedCaptureCacheKey
See CaptureType
private static java.lang.reflect.AnnotatedType expandGenerics(java.lang.reflect.AnnotatedType type)
public static java.lang.reflect.AnnotatedType transform(java.lang.reflect.AnnotatedType type, TypeVisitor visitor)
TypeVisitor
to the structure of the given type.type
- The type to transformvisitor
- Visitor implementing the transformationpublic static java.lang.reflect.AnnotatedType reduceBounded(java.lang.reflect.AnnotatedType type)
AnnotatedTypeVariable
, AnnotatedWildcardType
and AnnotatedCaptureType
)
to their first bound.type
- The type to transformprivate static java.lang.reflect.AnnotatedParameterizedType expandClassGenerics(java.lang.Class<?> type)
public static java.lang.annotation.Annotation[] merge(java.lang.annotation.Annotation[]... annotations)
annotations
- Annotation arrays to merge and deduplicatestatic boolean typeArraysEqual(java.lang.reflect.AnnotatedType[] t1, java.lang.reflect.AnnotatedType[] t2)
public static int hashCode(java.lang.reflect.AnnotatedType... types)
static int hashCode(java.util.stream.Stream<java.lang.annotation.Annotation> annotations)
public static boolean equals(java.lang.reflect.AnnotatedType t1, java.lang.reflect.AnnotatedType t2)
t1
- The first type to be comparedt2
- The second type to be comparedprivate static void buildUpperBoundClassAndInterfaces(java.lang.reflect.Type type, java.util.Set<java.lang.Class<?>> result)