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).
-
-
Constructor Summary
Constructors Constructor Description TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig)
Constructor.TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete 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.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.<A extends Annotation>
AgetTypeParameterAnnotation(Class<A> annotationClass, AnnotatedType annotatedContainerType, Integer containerItemIndex)
Return the annotation of the given type from the annotated container's item, if such an annotation is present.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.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.
-
-
-
Constructor Detail
-
TypeContext
public TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig)
Constructor.- Parameters:
annotationConfig
- annotation configuration to apply when collecting resolved fields and methods
-
TypeContext
public TypeContext(com.fasterxml.classmate.AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig)
Constructor.- 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 sub type 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)
-
getTypeParameterAnnotation
public <A extends Annotation> A getTypeParameterAnnotation(Class<A> annotationClass, AnnotatedType annotatedContainerType, Integer containerItemIndex)
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)
-
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
-
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
-
-