Class TypeModel


  • public class TypeModel
    extends Object
    Represents a model for handling GraphQL types, including information about the underlying Jandex Type.
    Author:
    mskacelik
    • Method Detail

      • of

        public static TypeModel of​(org.jboss.jandex.Type type)
        Factory method to create a TypeModel from a Jandex Type.
        Parameters:
        type - The Jandex Type.
        Returns:
        A TypeModel instance.
      • isPrimitive

        public boolean isPrimitive()
        Retrieves whether the type represents a primitive.
        Returns:
        true if the type is primitive, otherwise false.
      • isMap

        public boolean isMap()
        Retrieves whether the type represents a map.
        Returns:
        true if the type is a map, otherwise false.
      • isCollectionOrArray

        public boolean isCollectionOrArray()
        Retrieves whether the type is a collection or array.
        Returns:
        true if the type is a collection or array, otherwise false.
      • isClassType

        public boolean isClassType()
        Checks if the type is a class type (simple class, parametrized, or Object).
        Returns:
        true if the type is a class type, otherwise false.
      • isSimpleClassType

        public boolean isSimpleClassType()
        Checks if the type is a simple class type (not the primitive type).
        Returns:
        true if the type is a simple class type, otherwise false.
      • getMapValueType

        public TypeModel getMapValueType()
        Retrieves the value type of map type.
        Returns:
        A TypeModel representing the value type of the map.
        Throws:
        IllegalArgumentException - If the type is not a map.
      • isArray

        public boolean isArray()
        Checks if the type is an array.
        Returns:
        true if the type is an array, otherwise false.
      • isCollection

        public boolean isCollection()
        Checks if the type is a collection.
        Returns:
        true if the type is a collection, otherwise false.
      • getSimpleName

        public String getSimpleName()
        Retrieves the simple name of the type.
        Returns:
        The simple name of the type.
      • getName

        public String getName()
        Retrieves the full name of the type, considering parameters for generics.
        Returns:
        The full name of the type.
      • getItemTypes

        public Stream<TypeModel> getItemTypes()
        Retrieves a stream of TypeModel instances representing the parameters of parametrized type. (if parametrized).
        Returns:
        A stream of TypeModel parameter instances.
        Throws:
        IllegalArgumentException - If the type is not parametrized.
      • getArrayElementType

        public TypeModel getArrayElementType()
        Retrieves the element type for an array type.
        Returns:
        A TypeModel representing the element type of the array.
        Throws:
        IllegalArgumentException - If the type is not an array.
      • getItemTypeOrElementType

        public TypeModel getItemTypeOrElementType()
        Retrieves the item type for collections or arrays.
        Returns:
        A TypeModel representing the item type.
      • getCollectionElementType

        public TypeModel getCollectionElementType()
        Retrieves the element type for collections.
        Returns:
        A TypeModel representing the element type of the collection.
      • getFirstRawType

        public TypeModel getFirstRawType()
        Retrieves the first raw type.
        Returns:
        A TypeModel representing the first raw type.
      • isEnum

        public boolean isEnum()
        Checks if the type is an enum.
        Returns:
        true if the type is an enum, otherwise false.
      • isScalar

        public boolean isScalar()
        Checks if the type is a scalar (string, number, etc.).
        Returns:
        true if the type is a scalar, otherwise false.
      • isTypesafeResponse

        public boolean isTypesafeResponse()
        Checks if the type is a parametrized TypesafeResponse.
        Returns:
        true if the type is a parametrized TypesafeResponse, otherwise false.
      • isErrorOr

        public boolean isErrorOr()
        Checks if the type is a parametrized ErrorOr.
        Returns:
        true if the type is a parametrized ErrorOr, otherwise false.
      • isOptional

        public boolean isOptional()
        Checks if the type is a parametrized Optional. Optional* classes are considered as Scalars; this method checks if the type is an Optional<T>.
        Returns:
        true if the type is a parametrized Optional, otherwise false.
      • isAsync

        public boolean isAsync()
        Checks if the type is an asynchronous type.
        Returns:
        true if the type is asynchronous, otherwise false.
      • isParametrized

        public boolean isParametrized()
        Checks if the type is parametrized.
        Returns:
        true if the type is parametrized, otherwise false.
      • isTypeVariable

        public boolean isTypeVariable()
        Checks if the type is a type variable.
        Returns:
        true if the type is a type variable, otherwise false.
      • fields

        public Stream<FieldModel> fields()
        Retrieves a stream of FieldModel instances representing the fields of the type.
        Returns:
        A stream of FieldModel instances.
        Throws:
        IllegalArgumentException - If the type is not a class type.
      • hasClassAnnotation

        public boolean hasClassAnnotation​(org.jboss.jandex.DotName annotationName)
        Checks if the class represented by this TypeModel has a specific annotation.
        Parameters:
        annotationName - The name of the annotation to check.
        Returns:
        true if the class has the specified annotation, otherwise false.
      • getClassAnnotation

        public Optional<org.jboss.jandex.AnnotationInstance> getClassAnnotation​(org.jboss.jandex.DotName annotationName)
        Retrieves the annotation instance for a specific annotation on the class.
        Parameters:
        annotationName - The name of the annotation.
        Returns:
        An Optional containing the AnnotationInstance, or an empty Optional if the annotation is not present.
      • isCustomParametrizedType

        public boolean isCustomParametrizedType()
        Checks if the type is a custom user-made parametrized type, excluding certain standard types.
        Returns:
        true if the type is a custom user-made parametrized type, otherwise false.