Class TypeModel
- java.lang.Object
-
- io.smallrye.graphql.client.model.helper.TypeModel
-
public class TypeModel extends Object
Represents a model for handling GraphQL types, including information about the underlying Jandex Type.- Author:
- mskacelik
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stream<FieldModel>fields()Retrieves a stream of FieldModel instances representing the fields of the type.TypeModelgetArrayElementType()Retrieves the element type for an array type.Optional<org.jboss.jandex.AnnotationInstance>getClassAnnotation(org.jboss.jandex.DotName annotationName)Retrieves the annotation instance for a specific annotation on the class.TypeModelgetCollectionElementType()Retrieves the element type for collections.TypeModelgetFirstRawType()Retrieves the first raw type.TypeModelgetItemTypeOrElementType()Retrieves the item type for collections or arrays.Stream<TypeModel>getItemTypes()Retrieves a stream ofTypeModelinstances representing the parameters of parametrized type.TypeModelgetMapKeyType()Retrieves the key type of map type.TypeModelgetMapValueType()Retrieves the value type of map type.StringgetName()Retrieves the full name of the type, considering parameters for generics.StringgetSimpleName()Retrieves the simple name of the type.booleanhasClassAnnotation(org.jboss.jandex.DotName annotationName)Checks if the class represented by this TypeModel has a specific annotation.booleanisArray()Checks if the type is an array.booleanisAsync()Checks if the type is an asynchronous type.booleanisClassType()Checks if the type is a class type (simple class, parametrized, orObject).booleanisCollection()Checks if the type is a collection.booleanisCollectionOrArray()Retrieves whether the type is a collection or array.booleanisCustomParametrizedType()Checks if the type is a custom user-made parametrized type, excluding certain standard types.booleanisEnum()Checks if the type is an enum.booleanisErrorOr()Checks if the type is a parametrized ErrorOr.booleanisMap()Retrieves whether the type represents a map.booleanisNonNull()Checks if the type is non-null (primitive or annotated withAnnotations.NON_NULLorAnnotations.JAKARTA_NON_NULL).booleanisOptional()Checks if the type is a parametrized Optional.booleanisParametrized()Checks if the type is parametrized.booleanisPrimitive()Retrieves whether the type represents a primitive.booleanisScalar()Checks if the type is a scalar (string, number, etc.).booleanisSimpleClassType()Checks if the type is a simple class type (not the primitive type).booleanisTypesafeResponse()Checks if the type is a parametrized TypesafeResponse.booleanisTypeVariable()Checks if the type is a type variable.static TypeModelof(org.jboss.jandex.Type type)Factory method to create a TypeModel from a Jandex Type.
-
-
-
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:
trueif the type is primitive, otherwisefalse.
-
isMap
public boolean isMap()
Retrieves whether the type represents a map.- Returns:
trueif the type is a map, otherwisefalse.
-
isCollectionOrArray
public boolean isCollectionOrArray()
Retrieves whether the type is a collection or array.- Returns:
trueif the type is a collection or array, otherwisefalse.
-
isClassType
public boolean isClassType()
Checks if the type is a class type (simple class, parametrized, orObject).- Returns:
trueif the type is a class type, otherwisefalse.
-
isSimpleClassType
public boolean isSimpleClassType()
Checks if the type is a simple class type (not the primitive type).- Returns:
trueif the type is a simple class type, otherwisefalse.
-
getMapKeyType
public TypeModel getMapKeyType()
Retrieves the key type of map type.- Returns:
- A
TypeModelrepresenting the key type of the map. - Throws:
IllegalArgumentException- If the type is not a map.
-
getMapValueType
public TypeModel getMapValueType()
Retrieves the value type of map type.- Returns:
- A
TypeModelrepresenting the value type of the map. - Throws:
IllegalArgumentException- If the type is not a map.
-
isNonNull
public boolean isNonNull()
Checks if the type is non-null (primitive or annotated withAnnotations.NON_NULLorAnnotations.JAKARTA_NON_NULL).- Returns:
trueif the type is non-null, otherwisefalse.
-
isArray
public boolean isArray()
Checks if the type is an array.- Returns:
trueif the type is an array, otherwisefalse.
-
isCollection
public boolean isCollection()
Checks if the type is a collection.- Returns:
trueif the type is a collection, otherwisefalse.
-
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 ofTypeModelinstances representing the parameters of parametrized type. (if parametrized).- Returns:
- A stream of
TypeModelparameter instances. - Throws:
IllegalArgumentException- If the type is not parametrized.
-
getArrayElementType
public TypeModel getArrayElementType()
Retrieves the element type for an array type.- Returns:
- A
TypeModelrepresenting 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
TypeModelrepresenting the item type.
-
getCollectionElementType
public TypeModel getCollectionElementType()
Retrieves the element type for collections.- Returns:
- A
TypeModelrepresenting the element type of the collection.
-
getFirstRawType
public TypeModel getFirstRawType()
Retrieves the first raw type.- Returns:
- A
TypeModelrepresenting the first raw type.
-
isEnum
public boolean isEnum()
Checks if the type is an enum.- Returns:
trueif the type is an enum, otherwisefalse.
-
isScalar
public boolean isScalar()
Checks if the type is a scalar (string, number, etc.).- Returns:
trueif the type is a scalar, otherwisefalse.
-
isTypesafeResponse
public boolean isTypesafeResponse()
Checks if the type is a parametrized TypesafeResponse.- Returns:
trueif the type is a parametrized TypesafeResponse, otherwisefalse.
-
isErrorOr
public boolean isErrorOr()
Checks if the type is a parametrized ErrorOr.- Returns:
trueif the type is a parametrized ErrorOr, otherwisefalse.
-
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 anOptional<T>.- Returns:
trueif the type is a parametrized Optional, otherwisefalse.
-
isAsync
public boolean isAsync()
Checks if the type is an asynchronous type.- Returns:
trueif the type is asynchronous, otherwisefalse.
-
isParametrized
public boolean isParametrized()
Checks if the type is parametrized.- Returns:
trueif the type is parametrized, otherwisefalse.
-
isTypeVariable
public boolean isTypeVariable()
Checks if the type is a type variable.- Returns:
trueif the type is a type variable, otherwisefalse.
-
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:
trueif the class has the specified annotation, otherwisefalse.
-
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:
trueif the type is a custom user-made parametrized type, otherwisefalse.
-
-