Class TypeFactory

    • Constructor Detail

      • TypeFactory

        public TypeFactory​(Factory factory)
        Creates a new type sub-factory.
        Parameters:
        factory - the parent factory
      • TypeFactory

        public TypeFactory()
    • Method Detail

      • nullType

        public CtTypeReference<?> nullType()
        Returns a reference on the null type (type of null).
      • voidType

        public CtTypeReference<java.lang.Void> voidType()
        Returns a reference on the void type.
      • voidPrimitiveType

        public CtTypeReference<java.lang.Void> voidPrimitiveType()
        Returns a reference on the void primitive type.
      • stringType

        public CtTypeReference<java.lang.String> stringType()
        Returns a reference on the string type.
      • booleanType

        public CtTypeReference<java.lang.Boolean> booleanType()
        Returns a reference on the boolean type.
      • booleanPrimitiveType

        public CtTypeReference<java.lang.Boolean> booleanPrimitiveType()
        Returns a reference on the boolean primitive type.
      • byteType

        public CtTypeReference<java.lang.Byte> byteType()
        Returns a reference on the byte type.
      • bytePrimitiveType

        public CtTypeReference<java.lang.Byte> bytePrimitiveType()
        Returns a reference on the byte primitive type.
      • characterType

        public CtTypeReference<java.lang.Character> characterType()
        Returns a reference on the character type.
      • characterPrimitiveType

        public CtTypeReference<java.lang.Character> characterPrimitiveType()
        Returns a reference on the character primitive type.
      • integerType

        public CtTypeReference<java.lang.Integer> integerType()
        Returns a reference on the integer type.
      • integerPrimitiveType

        public CtTypeReference<java.lang.Integer> integerPrimitiveType()
        Returns a reference on the integer primitive type.
      • longType

        public CtTypeReference<java.lang.Long> longType()
        Returns a reference on the long type.
      • longPrimitiveType

        public CtTypeReference<java.lang.Long> longPrimitiveType()
        Returns a reference on the long primitive type.
      • floatType

        public CtTypeReference<java.lang.Float> floatType()
        Returns a reference on the float type.
      • floatPrimitiveType

        public CtTypeReference<java.lang.Float> floatPrimitiveType()
        Returns a reference on the float primitive type.
      • doubleType

        public CtTypeReference<java.lang.Double> doubleType()
        Returns a reference on the double type.
      • doublePrimitiveType

        public CtTypeReference<java.lang.Double> doublePrimitiveType()
        Returns a reference on the double primitive type.
      • shortType

        public CtTypeReference<java.lang.Short> shortType()
        Returns a reference on the short type.
      • shortPrimitiveType

        public CtTypeReference<java.lang.Short> shortPrimitiveType()
        Returns a reference on the short primitive type.
      • dateType

        public CtTypeReference<java.util.Date> dateType()
        Returns a reference on the date type.
      • objectType

        public CtTypeReference<java.lang.Object> objectType()
        Returns a reference on the object type.
      • createArrayReference

        public <T> CtArrayTypeReference<T[]> createArrayReference​(CtType<T> type)
        Creates a reference to an array of given type.
        Type Parameters:
        T - type of array
        Parameters:
        type - type of array values
      • createArrayReference

        public <T> CtArrayTypeReference<T[]> createArrayReference​(CtTypeReference<T> reference)
        Creates a reference to a one-dimension array of given type.
      • createArrayReference

        public CtArrayTypeReference<?> createArrayReference​(CtTypeReference<?> reference,
                                                            int n)
        Creates a reference to a n-dimension array of given type.
      • createArrayReference

        public <T> CtArrayTypeReference<T> createArrayReference​(java.lang.String qualifiedName)
        Creates a reference to an array of given type.
      • createReference

        public <T> CtTypeReference<T> createReference​(java.lang.Class<T> type)
      • createReference

        public <T> CtTypeReference<T> createReference​(java.lang.Class<T> type,
                                                      boolean includingFormalTypeParameter)
        Creates a reference to a simple type
      • createReference

        public <T> CtTypeReference<T> createReference​(CtType<T> type)
        Create a reference to a simple type
      • createReference

        public <T> CtTypeReference<T> createReference​(CtType<T> type,
                                                      boolean includingFormalTypeParameter)
        Parameters:
        includingFormalTypeParameter - if true then references to formal type parameters are added as actual type arguments of returned CtTypeReference
      • createReference

        public <T> CtTypeReference<T> createReference​(java.lang.String qualifiedName)
        Create a reference to a simple type
      • createSimplyQualifiedReference

        public <T> CtTypeReference<T> createSimplyQualifiedReference​(java.lang.String qualifiedName)
        Create a reference to a simple type, setting the beginning of its fully qualified name as implicit
      • get

        public <T> CtType<T> get​(java.lang.String qualifiedName)
        Gets a created type from its qualified name if source in the source classpath. `TypeFactory#get(String)` returns null if the class is not in the source classpath (even if it is in the binary classpath). `TypeFactory#get(Class)` returns null if the class is neither in the source classpath nor in the binary classpath, and returns a [shadow class](http://spoon.gforge.inria.fr/reflection.html) if it is only in the binary classpath. Note that a shadow class has empty method bodies, if you need a shadow class with method bodies, see [spoon-decompiler](https://github.com/INRIA/spoon/tree/master/spoon-decompiler))
        Returns:
        a type if source in the source classpath or null if does not exist
      • getAll

        public java.util.List<CtType<?>> getAll()
        Gets the list of all top-level created types.
      • getAll

        public java.util.List<CtType<?>> getAll​(boolean includeNestedTypes)
        Gets the list of all created types.
      • get

        public <T> CtType<T> get​(java.lang.Class<?> cl)
        Gets a type from its runtime Java class. If the class isn't in the spoon path, the class will be built from the Java reflection and will be marked as shadow (see CtShadowable).
        Type Parameters:
        T - actual type of the class
        Parameters:
        cl - the java class: note that this class should be Class<T> but it then poses problem when T is a generic type itself
      • getDeclaringTypeName

        protected java.lang.String getDeclaringTypeName​(java.lang.String qualifiedName)
        Gets the declaring type name for a given Java qualified name.
      • createReferences

        public java.util.List<CtTypeReference<?>> createReferences​(java.util.List<java.lang.Class<?>> classes)
        Creates a collection of type references from a collection of classes.
      • getPackageName

        protected java.lang.String getPackageName​(java.lang.String qualifiedName)
        Gets the package name for a given Java qualified name.
      • getSimpleName

        protected java.lang.String getSimpleName​(java.lang.String qualifiedName)
        Gets the simple name for a given Java qualified name.
      • hasInnerType

        protected int hasInnerType​(java.lang.String qualifiedName)
        Tells if a given Java qualified name is that of an inner type.
      • hasPackage

        protected int hasPackage​(java.lang.String qualifiedName)
        Tells if a given Java qualified name contains a package name.
      • createTypeParameterReference

        public CtTypeParameterReference createTypeParameterReference​(java.lang.String name)
        Creates a type parameter reference with no bounds.
        Parameters:
        name - the name of the formal parameter
      • createIntersectionTypeReferenceWithBounds

        public <T> CtIntersectionTypeReference<T> createIntersectionTypeReferenceWithBounds​(java.util.List<CtTypeReference<?>> bounds)
        Creates an intersection type reference.
        Type Parameters:
        T - Type of the first bound.
        Parameters:
        bounds - List of bounds saved in the intersection type. The first bound will be the intersection type.
      • getDefaultBoundingType

        public CtTypeReference getDefaultBoundingType()
        Returns the default bounding type value
      • createImport

        public CtImport createImport​(CtReference reference)
        Creates an import declaration.
      • createUnresolvedImport

        public CtImport createUnresolvedImport​(java.lang.String reference,
                                               boolean isStatic)