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()
      Return true if the referenced type is a primitive type (int, double, boolean...).
    • isAnonymous

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

      boolean isLocalType()
      Return 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)
      Returns true if the referenced type is a sub-type of the given type. Returns true is type is self, it means: typeX.isSubtypeOf(typeX) is true too
    • getSuperclass

      CtTypeReference<?> getSuperclass()
      Returns the class type directly extended by this class. getSuperClass().getDeclaration()/getTypeDeclaration() returns the corresponding CtType (if in the source folder of Spoon).
      the class type directly extended by this class, or null if there is none or if the super class is not in the classpath (in noclasspath mode)
    • 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.
      null if does not exit
    • getDeclaredOrInheritedField

      CtFieldReference<?> getDeclaredOrInheritedField(String fieldName)
      Gets a field from this type or any super type or any implemented interface by field name.
      null if does not exit
    • 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()
      the type erasure, which is computed by the java compiler to ensure that no new classes are created for parametrized types so that generics incur no runtime overhead. See
    • isArray

      boolean isArray()
      true if this represents an array e.g. Object[] or int[]