Skip to content
Timur Sağlam edited this page Jan 20, 2017 · 31 revisions

TODO update outdated parts

The Ecore Metamodel Generator

The Generator in the package eme.generator consists out of different generator classes:

  • EcoreMetamodelGenerator is 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 method generateMetamodelFrom(). 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 call changeSavingStrategy(). A metamodel is saved (if previously generated) with the method saveMetamodel()

  • EObjectGenerator is 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 method prepareFor() is not recommended because it can lead to unwanted behavior. Between the creation of components for two different models, the class is cleared with the prepareFor() method call. The class offers methods for the creation of an EClass and an EPackage. 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 call completeGeneration() 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. call prepareFor(), 2. call generateEPackage() on model root, 3. call completeGeneration()

  • EDataTypeGenerator is used by the class EObjectGenerator to 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 methods generateFrom() and addGenericArguments(). generateFrom() creates an EClassifier from an ExtractedDataType. There are three possibilities what that EClassifier can be in that context:

    1. The EClassifier is an already created classifier (class, interface or enumeration).
    2. The EClassifier is a basic EDataType which has an Ecore equivalent (e.g. int, java.lang.Integer or java.lang.Object).
    3. The EClassifier is an external data type without an Ecore equivalent and is created and stored as new EDataType which is contained in the root package.

    The method addGenericArguments() adds all generic arguments with their own generic arguments from an ExtractedDataType to an EGenericType. This method is separated from the previous method, because generic type arguments are added to the EGenericType instead of the EType of an ETypedElement. To use the EDataTypeGenerator one has to set the root package of the metamodel with the method setRoot(). Between the use for two different metamodels the EDataTypeGenerator should be resetted with the method reset().

  • SelectionHelper contains 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, the SelectionHelper stores that information. The method generateReport() 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.

  • EMFProjectGenerator can be used by saving strategies to create an empty EMF project in for the Eclipse IDE.

  • The subpackage eme.generator.saving is explained in the next chapter.

Clone this wiki locally