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 FieldScopecreateFieldScope(com.fasterxml.classmate.members.ResolvedField field, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)Construct aFieldScopeinstance for the given field.MethodScopecreateMethodScope(com.fasterxml.classmate.members.ResolvedMethod method, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)Construct aMethodScopeinstance for the given method.TypeScopecreateTypeScope(com.fasterxml.classmate.ResolvedType type)Construct aTypeScopeinstance for the type.com.fasterxml.classmate.ResolvedTypegetContainerItemType(com.fasterxml.classmate.ResolvedType containerType)Identify the element/item type of the givenSchemaKeyword.TAG_TYPE_ARRAY.StringgetFullTypeDescription(com.fasterxml.classmate.ResolvedType type)Constructing a string that fully represents the given type (including possible type parameters and their actual types).StringgetMethodPropertyArgumentTypeDescription(com.fasterxml.classmate.ResolvedType type)Returns the type description for an argument in a method's property name.StringgetSimpleTypeDescription(com.fasterxml.classmate.ResolvedType type)Constructing a string that represents the given type (including possible type parameters and their actual types).com.fasterxml.classmate.ResolvedTypegetTypeParameterFor(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.booleanisContainerType(com.fasterxml.classmate.ResolvedType type)Determine whether a given type should be treated asSchemaKeyword.TAG_TYPE_ARRAYin the generated schema.booleanisDerivingFieldsFromArgumentFreeMethods()Getter for the flag indicating whether to derive fields from argument-free methods.com.fasterxml.classmate.ResolvedTyperesolve(Type type, Type... typeParameters)Resolve actual type (mostly relevant for parameterised types, type variables and such.com.fasterxml.classmate.ResolvedTyperesolveSubtype(com.fasterxml.classmate.ResolvedType supertype, Class<?> subtype)Resolve subtype considering the given super-types (potentially) known type parameters.com.fasterxml.classmate.ResolvedTypeWithMembersresolveWithMembers(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 aFieldScopeinstance for the given field.- Parameters:
field- targeted fielddeclaringTypeMembers- collection of the declaring type's (other) fields and methods- Returns:
- created
FieldScopeinstance
-
createMethodScope
public MethodScope createMethodScope(com.fasterxml.classmate.members.ResolvedMethod method, com.fasterxml.classmate.ResolvedTypeWithMembers declaringTypeMembers)
Construct aMethodScopeinstance for the given method.- Parameters:
method- targeted methoddeclaringTypeMembers- collection of the declaring type's fields and (other) methods- Returns:
- created
MethodScopeinstance
-
createTypeScope
public TypeScope createTypeScope(com.fasterxml.classmate.ResolvedType type)
Construct aTypeScopeinstance for the type.- Parameters:
type- targeted type- Returns:
- created
TypeScopeinstance
-
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_ARRAYin 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)
-
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
-
-