Class TypeContext


  • public class TypeContext
    extends Object
    Context in which types can be resolved (as well as their declared fields and methods).
    • Field Detail

      • IGNORE_ANNOTATIONS_ON_ANNOTATIONS

        protected static final Predicate<Annotation> IGNORE_ANNOTATIONS_ON_ANNOTATIONS
    • Constructor Detail

      • TypeContext

        public TypeContext​(com.fasterxml.classmate.AnnotationConfiguration annotationConfig,
                           SchemaGeneratorConfig generatorConfig)
        Constructor.
        Note: when providing an instance of AnnotationConfiguration.StdConfiguration as first parameter, any configured annotation inclusion overrides are applied automatically.
        Parameters:
        annotationConfig - annotation configuration to apply when collecting resolved fields and methods
        generatorConfig - 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 resolve
        typeParameters - (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 type
        subtype - 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,
                                           MemberScope.DeclarationDetails declarationDetails)
        Construct a FieldScope instance for the given field.
        Parameters:
        field - targeted field
        declarationDetails - context of declaration
        Returns:
        created FieldScope instance
        Since:
        4.33.0
      • createMethodScope

        public MethodScope createMethodScope​(com.fasterxml.classmate.members.ResolvedMethod method,
                                             MemberScope.DeclarationDetails declarationDetails)
        Construct a MethodScope instance for the given method.
        Parameters:
        method - targeted method
        declarationDetails - context of declaration
        Returns:
        created MethodScope instance
        Since:
        4.33.0
      • createTypeScope

        public TypeScope createTypeScope​(com.fasterxml.classmate.ResolvedType type)
        Construct a TypeScope 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 for
        erasedSuperType - (super) type to find declared type parameter for
        parameterIndex - 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 as SchemaKeyword.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 given SchemaKeyword.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 given Predicate.
        Type Parameters:
        A - type of annotation
        Parameters:
        annotationClass - type of annotation
        annotationList - 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)
        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 annotation
        annotatedContainerType - annotated container type that is considered if it is an AnnotatedParameterizedType
        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 annotation
        considerOtherAnnotation - check whether some other annotation should also be checked for holding an instance of the target annotation
        annotatedContainerType - annotated container type that is considered if it is an AnnotatedParameterizedType
        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 an AnnotatedParameterizedType
        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 types
        annotationType - 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 types
        annotationType - type of annotation to look for
        considerOtherAnnotation - 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 types
        check - 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 calls Class.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 calls Class.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