Class TypeContext
- java.lang.Object
-
- com.github.victools.jsonschema.generator.TypeContext
-
public class TypeContext extends Object
Context in which types can be resolved (as well as their declared fields and methods).
-
-
Field Summary
Fields Modifier and Type Field Description protected static Predicate<Annotation>
IGNORE_ANNOTATIONS_ON_ANNOTATIONS
-
Constructor Summary
Constructors Constructor Description TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig)
Deprecated.TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description FieldScope
createFieldScope(com.fasterxml.classmate.members.ResolvedField field, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)
Construct aFieldScope
instance for the given field.MethodScope
createMethodScope(com.fasterxml.classmate.members.ResolvedMethod method, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)
Construct aMethodScope
instance for the given method.TypeScope
createTypeScope(com.fasterxml.classmate.ResolvedType type)
Construct aTypeScope
instance for the type.<A extends Annotation>
AgetAnnotationFromList(Class<A> annotationClass, List<Annotation> annotationList, Predicate<Annotation> considerOtherAnnotation)
Select the instance of the specified annotation type from the given list.com.fasterxml.classmate.ResolvedType
getContainerItemType(com.fasterxml.classmate.ResolvedType containerType)
Identify the element/item type of the givenSchemaKeyword.TAG_TYPE_ARRAY
.String
getFullTypeDescription(com.fasterxml.classmate.ResolvedType type)
Constructing a string that fully represents the given type (including possible type parameters and their actual types).String
getMethodPropertyArgumentTypeDescription(com.fasterxml.classmate.ResolvedType type)
Returns the type description for an argument in a method's property name.String
getSimpleTypeDescription(com.fasterxml.classmate.ResolvedType type)
Constructing a string that represents the given type (including possible type parameters and their actual types).<A extends Annotation>
AgetTypeAnnotationConsideringHierarchy(com.fasterxml.classmate.ResolvedType targetType, Class<A> annotationType)
Look-up the given annotation on the targeted type or one of its declared interfaces or super types.com.fasterxml.classmate.ResolvedType
getTypeConsideringHierarchyMatching(com.fasterxml.classmate.ResolvedType targetType, Predicate<com.fasterxml.classmate.ResolvedType> check)
Find the (super) type, including interfaces, that fulfils the given condition/check..<A extends Annotation>
AgetTypeParameterAnnotation(Class<A> annotationClass, AnnotatedType annotatedContainerType, Integer containerItemIndex)
Deprecated.<A extends Annotation>
AgetTypeParameterAnnotation(Class<A> annotationClass, Predicate<Annotation> considerOtherAnnotation, AnnotatedType annotatedContainerType, Integer containerItemIndex)
Return the annotation of the given type from the annotated container's item, if such an annotation is present.Stream<Annotation>
getTypeParameterAnnotations(AnnotatedType annotatedContainerType, Integer containerItemIndex)
Return the annotations from the annotated container's item.com.fasterxml.classmate.ResolvedType
getTypeParameterFor(com.fasterxml.classmate.ResolvedType type, Class<?> erasedSuperType, int parameterIndex)
Find type parameterization for the specified (super) type at return the type parameter at the given index.com.fasterxml.classmate.ResolvedType
getTypeWithAnnotation(com.fasterxml.classmate.ResolvedType targetType, Class<? extends Annotation> annotationType)
Find the (super) type, including interfaces, that has the designated type annotation.com.fasterxml.classmate.ResolvedType
getTypeWithAnnotation(com.fasterxml.classmate.ResolvedType targetType, Class<? extends Annotation> annotationType, Predicate<Annotation> considerOtherAnnotation)
Find the (super) type, including interfaces, that has the designated type annotation.boolean
isContainerType(com.fasterxml.classmate.ResolvedType type)
Determine whether a given type should be treated asSchemaKeyword.TAG_TYPE_ARRAY
in the generated schema.boolean
isDerivingFieldsFromArgumentFreeMethods()
Getter for the flag indicating whether to derive fields from argument-free methods.com.fasterxml.classmate.ResolvedType
resolve(Type type, Type... typeParameters)
Resolve actual type (mostly relevant for parameterised types, type variables and such).com.fasterxml.classmate.ResolvedType
resolveSubtype(com.fasterxml.classmate.ResolvedType supertype, Class<?> subtype)
Resolve subtype considering the given super-types (potentially) known type parameters.com.fasterxml.classmate.ResolvedTypeWithMembers
resolveWithMembers(com.fasterxml.classmate.ResolvedType resolvedType)
Collect a given type's declared fields and methods.
-
-
-
Field Detail
-
IGNORE_ANNOTATIONS_ON_ANNOTATIONS
protected static final Predicate<Annotation> IGNORE_ANNOTATIONS_ON_ANNOTATIONS
-
-
Constructor Detail
-
TypeContext
@Deprecated public TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig)
Deprecated.Constructor.- Parameters:
annotationConfig
- annotation configuration to apply when collecting resolved fields and methods
-
TypeContext
public TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig)
Constructor.
Note: when providing an instance ofAnnotationConfiguration.StdConfiguration
as first parameter, any configured annotation inclusion overrides are applied automatically.- Parameters:
annotationConfig
- annotation configuration to apply when collecting resolved fields and methodsgeneratorConfig
- generator configuration indicating whether argument free methods should be represented as fields
-
-
Method Detail
-
isDerivingFieldsFromArgumentFreeMethods
public boolean isDerivingFieldsFromArgumentFreeMethods()
Getter for the flag indicating whether to derive fields from argument-free methods.- Returns:
- whether argument-free methods should be represented as fields
-
resolve
public final com.fasterxml.classmate.ResolvedType resolve(Type type, Type... typeParameters)
Resolve actual type (mostly relevant for parameterised types, type variables and such).- Parameters:
type
- java type to resolvetypeParameters
- (optional) type parameters to pass on- Returns:
- resolved type
- See Also:
TypeResolver.resolve(Type, Type...)
-
resolveSubtype
public final com.fasterxml.classmate.ResolvedType resolveSubtype(com.fasterxml.classmate.ResolvedType supertype, Class<?> subtype)
Resolve subtype considering the given super-types (potentially) known type parameters.- Parameters:
supertype
- already resolved super typesubtype
- erased java subtype to resolve- Returns:
- resolved subtype
- See Also:
TypeResolver.resolveSubtype(ResolvedType, Class)
-
resolveWithMembers
public final com.fasterxml.classmate.ResolvedTypeWithMembers resolveWithMembers(com.fasterxml.classmate.ResolvedType resolvedType)
Collect a given type's declared fields and methods.- Parameters:
resolvedType
- type for which to collect declared fields and methods- Returns:
- collection of (resolved) fields and methods
-
createFieldScope
public FieldScope createFieldScope(com.fasterxml.classmate.members.ResolvedField field, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)
Construct aFieldScope
instance for the given field.- Parameters:
field
- targeted fielddeclaringTypeMembers
- collection of the declaring type's (other) fields and methods- Returns:
- created
FieldScope
instance
-
createMethodScope
public MethodScope createMethodScope(com.fasterxml.classmate.members.ResolvedMethod method, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)
Construct aMethodScope
instance for the given method.- Parameters:
method
- targeted methoddeclaringTypeMembers
- collection of the declaring type's fields and (other) methods- Returns:
- created
MethodScope
instance
-
createTypeScope
public TypeScope createTypeScope(com.fasterxml.classmate.ResolvedType type)
Construct aTypeScope
instance for the type.- Parameters:
type
- targeted type- Returns:
- created
TypeScope
instance
-
getTypeParameterFor
public com.fasterxml.classmate.ResolvedType getTypeParameterFor(com.fasterxml.classmate.ResolvedType type, Class<?> erasedSuperType, int parameterIndex)
Find type parameterization for the specified (super) type at return the type parameter at the given index.- Parameters:
type
- type to find type parameter forerasedSuperType
- (super) type to find declared type parameter forparameterIndex
- index of the single type parameter's declared type to return- Returns:
- declared parameter type; or
Object.class
if no parameters are defined; or null if the given type or index are invalid - See Also:
ResolvedType.typeParametersFor(Class)
-
isContainerType
public boolean isContainerType(com.fasterxml.classmate.ResolvedType type)
Determine whether a given type should be treated asSchemaKeyword.TAG_TYPE_ARRAY
in the generated schema.- Parameters:
type
- type to check- Returns:
- whether the given type is an array or subtype of
Collection
-
getContainerItemType
public com.fasterxml.classmate.ResolvedType getContainerItemType(com.fasterxml.classmate.ResolvedType containerType)
Identify the element/item type of the givenSchemaKeyword.TAG_TYPE_ARRAY
.- Parameters:
containerType
- type to extract type of element/item from- Returns:
- type of elements/items
- See Also:
isContainerType(ResolvedType)
-
getAnnotationFromList
public <A extends Annotation> A getAnnotationFromList(Class<A> annotationClass, List<Annotation> annotationList, Predicate<Annotation> considerOtherAnnotation)
Select the instance of the specified annotation type from the given list. Also considering meta annotations (i.e., annotations on annotations) if a meta annotation is deemed eligible according to the givenPredicate
.- Type Parameters:
A
- type of annotation- Parameters:
annotationClass
- type of annotationannotationList
- initial list of annotations to search in (potentially containing meta annotations)considerOtherAnnotation
- check whether some other annotation should also be checked for holding an instance of the target annotation- Returns:
- annotation instance (or
null
if no annotation of the given type is present) - Since:
- 4.30.0
-
getTypeParameterAnnotation
@Deprecated public <A extends Annotation> A getTypeParameterAnnotation(Class<A> annotationClass, AnnotatedType annotatedContainerType, Integer containerItemIndex)
Deprecated.Return the annotation of the given type from the annotated container's item, if such an annotation is present.- Type Parameters:
A
- type of annotation- Parameters:
annotationClass
- type of annotationannotatedContainerType
- annotated container type that is considered if it is anAnnotatedParameterizedType
containerItemIndex
- parameter index of the desired item on the container type- Returns:
- annotation instance (or
null
if no annotation of the given type is present)
-
getTypeParameterAnnotation
public <A extends Annotation> A getTypeParameterAnnotation(Class<A> annotationClass, Predicate<Annotation> considerOtherAnnotation, AnnotatedType annotatedContainerType, Integer containerItemIndex)
Return the annotation of the given type from the annotated container's item, if such an annotation is present.
Additionally, also consider annotations on annotations, if the given predicate indicates another annotation as eligible for holding the target.- Type Parameters:
A
- type of annotation- Parameters:
annotationClass
- type of annotationconsiderOtherAnnotation
- check whether some other annotation should also be checked for holding an instance of the target annotationannotatedContainerType
- annotated container type that is considered if it is anAnnotatedParameterizedType
containerItemIndex
- parameter index of the desired item on the container type- Returns:
- annotation instance (or
null
if no annotation of the given type is present) - Since:
- 4.30.0
-
getTypeParameterAnnotations
public Stream<Annotation> getTypeParameterAnnotations(AnnotatedType annotatedContainerType, Integer containerItemIndex)
Return the annotations from the annotated container's item.- Parameters:
annotatedContainerType
- annotated container type that is considered if it is anAnnotatedParameterizedType
containerItemIndex
- parameter index of the desired item on the container type- Returns:
- annotation instances (possibly empty if no annotation is present)
- Since:
- 4.30.0
-
getTypeWithAnnotation
public com.fasterxml.classmate.ResolvedType getTypeWithAnnotation(com.fasterxml.classmate.ResolvedType targetType, Class<? extends Annotation> annotationType)
Find the (super) type, including interfaces, that has the designated type annotation.- Parameters:
targetType
- type to check for the annotation, potentially iterating over its declared interfaces and super typesannotationType
- type of annotation to look for- Returns:
- (super) type with the targeted annotation (or
null
if the annotation wasn't found on any of its interfaces or super types) - Since:
- 4.28.0
-
getTypeWithAnnotation
public com.fasterxml.classmate.ResolvedType getTypeWithAnnotation(com.fasterxml.classmate.ResolvedType targetType, Class<? extends Annotation> annotationType, Predicate<Annotation> considerOtherAnnotation)
Find the (super) type, including interfaces, that has the designated type annotation.
Additionally, also consider annotations on annotations, if the given predicate indicates another annotation as eligible for holding the target.- Parameters:
targetType
- type to check for the annotation, potentially iterating over its declared interfaces and super typesannotationType
- type of annotation to look forconsiderOtherAnnotation
- check whether some other annotation should also be checked for holding an instance of the target annotation- Returns:
- (super) type with the targeted annotation (or
null
if the annotation wasn't found on any of its interfaces or super types) - Since:
- 4.30.0
-
getTypeConsideringHierarchyMatching
public com.fasterxml.classmate.ResolvedType getTypeConsideringHierarchyMatching(com.fasterxml.classmate.ResolvedType targetType, Predicate<com.fasterxml.classmate.ResolvedType> check)
Find the (super) type, including interfaces, that fulfils the given condition/check..- Parameters:
targetType
- type to check for the annotation, potentially iterating over its declared interfaces and super typescheck
- condition to be fulfilled- Returns:
- (super) type fulfilling the given condition (or
null
if the condition wasn't fulfilled by any of its interfaces or super types) - Since:
- 4.30.0
-
getTypeAnnotationConsideringHierarchy
public <A extends Annotation> A getTypeAnnotationConsideringHierarchy(com.fasterxml.classmate.ResolvedType targetType, Class<A> annotationType)
Look-up the given annotation on the targeted type or one of its declared interfaces or super types.- Type Parameters:
A
- type of annotation to look for- Parameters:
targetType
- type to find annotation on (or on any of its declared interfaces or super types)annotationType
- type of annotation to look for- Returns:
- annotation instance (or
null
if not found) - Since:
- 4.28.0
-
getSimpleTypeDescription
public final String getSimpleTypeDescription(com.fasterxml.classmate.ResolvedType type)
Constructing a string that represents the given type (including possible type parameters and their actual types).
This callsClass.getSimpleName()
for a single erased type – i.e. excluding package names.- Parameters:
type
- the type to represent- Returns:
- resulting string
-
getFullTypeDescription
public final String getFullTypeDescription(com.fasterxml.classmate.ResolvedType type)
Constructing a string that fully represents the given type (including possible type parameters and their actual types).
This callsClass.getName()
for a single erased type.- Parameters:
type
- the type to represent- Returns:
- resulting string
-
getMethodPropertyArgumentTypeDescription
public String getMethodPropertyArgumentTypeDescription(com.fasterxml.classmate.ResolvedType type)
Returns the type description for an argument in a method's property name.- Parameters:
type
- method argument's type to represent- Returns:
- argument type description
-
-