Class TypeFactory

java.lang.Object
spoon.reflect.factory.SubFactory
spoon.reflect.factory.TypeFactory
Direct Known Subclasses:
AnnotationFactory, ClassFactory, EnumFactory, InterfaceFactory

public class TypeFactory extends SubFactory
The CtType sub-factory.
  • Field Details

  • Constructor Details

    • TypeFactory

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

      public TypeFactory()
  • Method Details

    • nullType

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public CtTypeReference<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(String qualifiedName)
      Creates a reference to an array of given type.
    • createReference

      public <T> CtTypeReference<T> createReference(Class<T> type)
    • createReference

      public <T> CtTypeReference<T> createReference(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
    • createTypeMemberWildcardImportReference

      public CtTypeMemberWildcardImportReference createTypeMemberWildcardImportReference(CtTypeReference typeReference)
      Create a wildcard 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 CtTypeParameterReference createReference(CtTypeParameter type)
      Create a reference to a simple type
    • createReference

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

      public <T> CtTypeReference<T> createSimplyQualifiedReference(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(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 List<CtType<?>> getAll()
      Gets the list of all top-level created types.
    • getAll

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

      public <T> CtType<T> get(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 String getDeclaringTypeName(String qualifiedName)
      Gets the declaring type name for a given Java qualified name.
    • createReferences

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

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

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

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

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

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

      public GenericTypeAdapter createTypeAdapter(CtFormalTypeDeclarer formalTypeDeclarer)
      Create a GenericTypeAdapter for adapting of formal type parameters from any compatible context to the context of provided `formalTypeDeclarer`
      Parameters:
      formalTypeDeclarer - the target scope of the returned GenericTypeAdapter
    • createIntersectionTypeReferenceWithBounds

      public <T> CtIntersectionTypeReference<T> createIntersectionTypeReferenceWithBounds(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(String reference, boolean isStatic)