When you design and implement transformations, with processors or templates, you need to create new elements, fill their data and add them in the AST built by Spoon.

To do that, use Factory (javadoc). Factory is the entry point for all factories of Spoon. Each factory have a goal specific and help you in the creation of a new AST.

  • CoreFactory (javadoc) allows the creation of any element in the meta model. To set up the objects, there are setters to initialize the object.
  • CodeFactory (javadoc) contains utility methods to create code elements and asks minimal information to create a valid object.
  • PackageFactory (javadoc) contains utility methods to create and get package reference.
  • TypeFactory (javadoc) contains utility methods with a link to CtType (javadoc). You can get any type from its fully qualified name or a .class invocation
    and create all typed references like CtTypeReference (javadoc).
  • ClassFactory (javadoc) is a sub class of TypeFactory but specialized for CtClass (javadoc).
  • EnumFactory (javadoc) is a sub class of TypeFactory but specialized for CtEnum (javadoc).
  • InterfaceFactory (javadoc) is a sub class of TypeFactory but specialized for CtInterface (javadoc).
  • ExecutableFactory (javadoc) contains utility methods with a link to CtExecutable (javadoc). You can create executable objects and their parameters.
  • ConstructorFactory (javadoc) is a sub class of ExecutableFactory but specialized for CtConstructor (javadoc).
  • MethodFactory (javadoc) is a sub class of ExecutableFactory but specialized for CtMethod (javadoc).
  • FieldFactory (javadoc) contains utility methods to create a valid field or a field reference.
  • AnnotationFactory (javadoc) contains utility methods to annotate any elements or create a new one.

All these factories contribute to facilitate the creation of elements. When you have created an element from a factory, set it in an existing element to build a new AST.