-
Notifications
You must be signed in to change notification settings - Fork 8
3. Generator
TODO update outdated parts
The Generator in the package eme.generator consists out of different generator classes:
-
EcoreMetamodelGeneratoris the main generator class, it manages the whole generation process and handles the other generator classes. To create an Ecore metamodel, use this class exclusively, it manages the calls to all other generators. Creating a metamodel can be achieved with the methodgenerateMetamodelFrom(). The main generator class also manages the saving strategy. Initially the saving strategy is set according to the properties class, but it can be changed during the runtime with the method callchangeSavingStrategy(). A metamodel is saved (if previously generated) with the methodsaveMetamodel() -
EObjectGeneratoris the class that actually generates the metamodel components (Ecore objects) from the intermediate model. The functionality of the class is tied to its instance of an intermediate model. Creating metamodel components with this class without previously setting the intermediate model with the methodprepareFor()is not recommended because it can lead to unwanted behavior. Between the creation of components for two different models, the class is cleared with theprepareFor()method call. The class offers methods for the creation of anEClassand anEPackage. In both methods the Ecore objects for all the contained elements (subpackages, classes, methods etc.) are automatically created. That means those methods should be called for root elements. The creation process is divided in two steps to avoid problems with cyclic data type references. That is why it is important to callcompleteGeneration()after the desired packages and classes are generated. Only then it can be guaranteed that the classes are complete and all the methods and attributes are generated. The recommended workflow is: 1. callprepareFor(), 2. callgenerateEPackage()on model root, 3. callcompleteGeneration() -
EDataTypeGeneratoris used by the classEObjectGeneratorto manage data types. The class stores a map that maps data type names to the data types themselves. It also creates and stores new data types. It offers the methodsgenerateFrom()andaddGenericArguments().generateFrom()creates anEClassifierfrom anExtractedDataType. There are three possibilities what thatEClassifiercan be in that context:- The
EClassifieris an already created classifier (class, interface or enumeration). - The
EClassifieris a basicEDataTypewhich has an Ecore equivalent (e.g.int,java.lang.Integerorjava.lang.Object). - The
EClassifieris an external data type without an Ecore equivalent and is created and stored as newEDataTypewhich is contained in the root package.
The method
addGenericArguments()adds all generic arguments with their own generic arguments from anExtractedDataTypeto anEGenericType. This method is separated from the previous method, because generic type arguments are added to theEGenericTypeinstead of theETypeof anETypedElement. To use theEDataTypeGeneratorone has to set the root package of the metamodel with the methodsetRoot(). Between the use for two different metamodels theEDataTypeGeneratorshould be resetted with the methodreset(). - The
-
SelectionHelpercontains the check methods. These methods check for a specific model element whether it may be generated. This depends on whether the element is selected or not and whether the properties allow the generation of such elements. Whenever an element may must not be generated, theSelectionHelperstores that information. The methodgenerateReport()then allows to produce a report about what kind of elements were not generated and how many of them were not generated. The report distinguishes between Packages, Interfaces, Classes, Enumerations, Constructors, Methods and Attributes. -
EMFProjectGeneratorcan be used by saving strategies to create an empty EMF project in for the Eclipse IDE. -
The subpackage
eme.generator.savingis explained in the next chapter.