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 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 Integer this method returns false.

      Returns:
      true if the referenced type is a primitive type
    • isAnonymous

      boolean isAnonymous()
      Return true if the referenced type is an anonymous type
    • isLocalType

      boolean isLocalType()
      Returns true if the referenced type is declared in an executable. e.g. a type declared in a method or a lambda. This corresponds to isLocalClass of java.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

      boolean isSubtypeOf(CtTypeReference<?> type)
      Checks if this type is a subtype of the given type.
      Parameters:
      type - the type that might be a parent of this type.
      Returns:
      true if the referenced type is a subtype of the given type, otherwise false. If this type is the same as the given type (typeX.isSubtypeOf(typeX)), this method returns true.
    • getSuperclass

      CtTypeReference<?> getSuperclass()
      Returns a reference to the type directly extended by this type.

      To get the CtType of the super class, use CtTypeReference.getDeclaration() or CtTypeReference.getTypeDeclaration() on the CtTypeReference returned by this method.

      Returns:
      the type explicitly extended by this type, or null if there is none or if the super type is not in the classpath (in noclasspath mode). If a class does not explicitly extend another class null is returned (not Object). For types like enums that implicitly extend a superclass like Enum, 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

      CtFieldReference<?> getDeclaredField(String name)
      Gets a field from its name.
      Returns:
      a reference to the field with the name or null if it does not exist
    • getDeclaredOrInheritedField

      CtFieldReference<?> getDeclaredOrInheritedField(String fieldName)
      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 null if 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
      If a method is overridden twice in the hierarchy, it counts for two different elements. The method can be abstract.
    • getTypeErasure

      CtTypeReference<?> getTypeErasure()
      This method returns a reference to the erased type.

      For example, this will return List for List<String>, or Enum for the type parameter E in the enum declaration.

      Returns:
      a reference to the erased type
      See Also:
      Type Erasure
    • isArray

      boolean isArray()
      Returns true if this type represents an array like Object[] or int[].
      Returns:
      true if this type represents an array like Object[] or int[]