Package spoon.reflect.declaration
Interface CtTypeInformation
- All Known Subinterfaces:
CtAnnotationType<T>,CtArrayTypeReference<T>,CtClass<T>,CtEnum<T>,CtInterface<T>,CtIntersectionTypeReference<T>,CtRecord,CtType<T>,CtTypeParameter,CtTypeParameterReference,CtTypeReference<T>,CtWildcardReference
- All Known Implementing Classes:
CtAnnotationTypeImpl,CtArrayTypeReferenceImpl,CtClassImpl,CtEnumImpl,CtInterfaceImpl,CtIntersectionTypeReferenceImpl,CtRecordImpl,CtTypeImpl,CtTypeParameterImpl,CtTypeParameterReferenceImpl,CtTypeReferenceImpl,CtWildcardReferenceImpl
public interface CtTypeInformation
Returns information that can be obtained both at compile-time and run-time.
For
CtElement, the compile-time information is given.
For CtTypeReference, the runtime information is given (using the Reflection API)-
Method Summary
Modifier and TypeMethodDescriptionGets the executables declared by this type and by all its supertypes (static/instance methods, constructors, anonymous static blocks) if applicable.Gets the fields declared by this type and by all its supertypes if applicable.Gets the executables declared by this type if applicable.getDeclaredField(String name) Gets a field from its name.Gets the fields declared by this type.getDeclaredOrInheritedField(String fieldName) Gets a field from this type or any super type or any implemented interface by field name.Gets modifiers of this type.Returns the fully qualified name of this type declaration.Returns a reference to the type directly extended by this type.Set<CtTypeReference<?>>Returns the interface types directly implemented by this class or extended by this interface.This method returns a reference to the erased type.booleanReturns true if this type is an annotation type.booleanReturntrueif the referenced type is an anonymous typebooleanisArray()Returns true if this type represents an array likeObject[]orint[].booleanisClass()Returns true if this type is a class.booleanisEnum()Returns true if this type is an enum.booleanReturns true if it is not a concrete, resolvable class, it if refers to a type parameter directly or indirectly.booleanReturns true if this type is an interface.booleanReturnstrueif the referenced type is declared in an executable.booleanReturns true if it has any type parameter (generic or not).booleanChecks if the referenced type is a primitive type.booleanisSubtypeOf(CtTypeReference<?> type) Checks if this type is a subtype of the given type.
-
Method Details
-
getSuperInterfaces
Set<CtTypeReference<?>> getSuperInterfaces()Returns the interface types directly implemented by this class or extended by this interface. -
getQualifiedName
String getQualifiedName()Returns the fully qualified name of this type declaration. -
getModifiers
Set<ModifierKind> getModifiers()Gets modifiers of this type. -
isPrimitive
boolean isPrimitive()Checks if the referenced type is a primitive type.It is a primitive type, if it is one of the following types:
- byte
- short
- int
- long
- float
- double
- boolean
- char
- void
For boxed types like
Integerthis method returnsfalse.- Returns:
trueif the referenced type is a primitive type
-
isAnonymous
boolean isAnonymous()Returntrueif the referenced type is an anonymous type -
isLocalType
boolean isLocalType()Returnstrueif the referenced type is declared in an executable. e.g. a type declared in a method or a lambda. This corresponds toisLocalClassofjava.lang.Class.// Type declared in a method. public void make() { class Cook { } } // Type declared in a lambda. s -> { class Cook { } } -
isClass
boolean isClass()Returns true if this type is a class. Returns false for others (enum, interface, generics, annotation). -
isInterface
boolean isInterface()Returns true if this type is an interface. -
isEnum
boolean isEnum()Returns true if this type is an enum. -
isAnnotationType
boolean isAnnotationType()Returns true if this type is an annotation type. -
isGenerics
boolean isGenerics()Returns true if it is not a concrete, resolvable class, it if refers to a type parameter directly or indirectly. Direct: "T foo" isGenerics returns true. Indirect: List<T>, or Set<List<T>> isGenerics returns true -
isParameterized
boolean isParameterized()Returns true if it has any type parameter (generic or not). -
isSubtypeOf
Checks if this type is a subtype of the given type.- Parameters:
type- the type that might be a parent of this type.- Returns:
trueif the referenced type is a subtype of the given type, otherwisefalse. If this type is the same as the given type (typeX.isSubtypeOf(typeX)), this method returnstrue.
-
getSuperclass
CtTypeReference<?> getSuperclass()Returns a reference to the type directly extended by this type.To get the
CtTypeof the super class, useCtTypeReference.getDeclaration()orCtTypeReference.getTypeDeclaration()on theCtTypeReferencereturned by this method.- Returns:
- the type explicitly extended by this type, or
nullif there is none or if the super type is not in the classpath (in noclasspath mode). If a class does not explicitly extend another classnullis returned (notObject). For types like enums that implicitly extend a superclass likeEnum, this method returns that class.
-
getDeclaredFields
Collection<CtFieldReference<?>> getDeclaredFields()Gets the fields declared by this type. -
getAllFields
Collection<CtFieldReference<?>> getAllFields()Gets the fields declared by this type and by all its supertypes if applicable. -
getDeclaredField
Gets a field from its name.- Returns:
- a reference to the field with the name or
nullif it does not exist
-
getDeclaredOrInheritedField
Gets a field from this type or any super type or any implemented interface by field name.- Returns:
- a reference to the field with the name or
nullif it does not exist
-
getDeclaredExecutables
Collection<CtExecutableReference<?>> getDeclaredExecutables()Gets the executables declared by this type if applicable. -
getAllExecutables
Collection<CtExecutableReference<?>> getAllExecutables()Gets the executables declared by this type and by all its supertypes (static/instance methods, constructors, anonymous static blocks) if applicable. This method returns:- static, instance and default methods
- constructors
-
getTypeErasure
CtTypeReference<?> getTypeErasure()This method returns a reference to the erased type.For example, this will return
ListforList<String>, orEnumfor the type parameterEin the enum declaration.- Returns:
- a reference to the erased type
- See Also:
-
isArray
boolean isArray()Returns true if this type represents an array likeObject[]orint[].- Returns:
- true if this type represents an array like
Object[]orint[]
-