Interface CtTypeReference<T>

    • Field Detail


        static final java.lang.String NULL_TYPE_NAME
        The name of the null type ("<nulltype>").
        See Also:
        Constant Field Values

        static final java.lang.String OMITTED_TYPE_ARG_NAME
        Special type used as a type argument when actual type arguments can't be inferred.
        See Also:
        Constant Field Values
    • Method Detail

      • getSimpleName

        java.lang.String getSimpleName()
        Returns the simple (unqualified) name of this element. Following the compilation convention, if the type is a local type, the name starts with a numeric prefix (e.g. local class Foo has simple name 1Foo).
        Specified by:
        getSimpleName in interface CtReference
      • getActualClass

        java.lang.Class<T> getActualClass()
        (Since Spoon 7.0.0) use getTypeDeclaration() instead
        Gets the Java runtime class of the referenced type. This is a low-level feature, it should never been used. For CtTypeReference, use getTypeDeclaration() instead, in order to only stay in the Spoon world and manipulate CtType instead of java.lang.Class.
        the Java class or throws a SpoonClassNotFoundException if the class is not found.
        SpoonClassNotFoundException - if the class is not in the classpath
      • getDeclaration

        CtType<T> getDeclaration()
        Returns the CtType, that corresponds to the reference or null if the type declaration is not in the analyzed source files, getTypeDeclaration() is a newer and better alternative that less often returns null.
        Specified by:
        getDeclaration in interface CtReference
        the referenced element or null if the type declaration is not the analyzed source files.
      • getTypeDeclaration

        CtType<T> getTypeDeclaration()
        Returns the CtType that corresponds to the reference even if the type isn't in the Spoon source path (in this case, the Spoon elements are built with runtime reflection, and the resulting CtType is called a "shadow" class, see CtShadowable.isShadow()).
        the type declaration that corresponds to the reference or null if the reference points to a class that is not in the classpath.
      • getDeclaringType

        CtTypeReference<?> getDeclaringType()
        Gets the type that declares the referenced type.
        the declaring type if this references an inner class; null in other cases
      • getPackage

        CtPackageReference getPackage()
        Gets the package of the referenced type.
        the declaring package or null if this if a inner class
      • box

        CtTypeReference<?> box()
        Returns the corresponding non-primitive type for a primitive type (the same type otherwise).
      • unbox

        CtTypeReference<?> unbox()
        Returns the primitive type for a boxing type (unchanged if the type does not correspond to a boxing type).
      • setDeclaringType

        <C extends CtTypeReference<T>> C setDeclaringType​(CtTypeReference<?> type)
        Sets the reference to the declaring type. Should be set to null if the referenced type is not a inner type.
      • clone

        CtTypeReference<T> clone()
        Description copied from interface: CtElement
        Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
        Specified by:
        clone in interface CtElement
        Specified by:
        clone in interface CtReference
      • getSuperclass

        CtTypeReference<?> getSuperclass()
        Description copied from interface: CtTypeInformation
        Returns the class type directly extended by this class. getSuperClass().getDeclaration()/getTypeDeclaration() returns the corresponding CtType (if in the source folder of Spoon).
        Specified by:
        getSuperclass in interface CtTypeInformation
        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)
      • canAccess

        boolean canAccess​(CtTypeReference<?> type)
        Checks visibility based on public, protected, package protected and private modifiers of type
        type -
        true if this can access that type
      • canAccess

        boolean canAccess​(CtTypeMember typeMember)
        true if this type can access that the `typeMember` in another type based on public, protected, package protected and private modifiers.
      • getTopLevelType

        CtTypeReference<?> getTopLevelType()
        Returns this, or top level type of this, if this is an inner type
      • getAccessType

        CtTypeReference<?> getAccessType()
        Computes nearest access path parent to this type from the context of this type reference. The context is defined by this.getParent(CtType.class). Normally the declaring type can be used as access path. For example in this class hierarchy
         class A {
            class B {
               class C {}
        The C.getAccessParentFrom(null) will return B, because B can be used to access C, using code like B.C
        But when some class (A or B) on the access path is not visible in type X, then we must found an alternative path. For example in case like, when A and B are invisible, e.g because of modifier protected:
         class D extends B {
         class X extends D {
                 class F extends C
        The C.getAccessParentFrom(X) will return D, because D can be used to access C in scope of X.
        type reference which can be used to access this type in scope of contextType.
      • getTypeParameterDeclaration

        CtTypeParameter getTypeParameterDeclaration()
        If this type reference is used as a type argument (see CtActualTypeContainer.getActualTypeArguments()), returns the type parameter declaration in the target type, returns null otherwise. In the following example, getTypeParameterDeclaration of "String" returns the type parameter definition "X".
         class Dog<X>{}
         Dog<String>var = ...;
        In this other example, getTypeParameterDeclaration of T in Dog<T> returns the type parameter definition "X" (while getDeclaration() returns the "T" of Cat).
         class Dog<X>{}
         class Cat<T> {
         Dog<T> dog;
      • setSimplyQualified

        CtTypeReference<T> setSimplyQualified​(boolean isSimplyQualified)
        isSimplyQualified - false then the reference is printed fully qualified name. true then only the type name is printed.
      • isSimplyQualified

        boolean isSimplyQualified()
        false then fully qualified name is printed. true then type simple name is printed.