Skip to content
Timur Sağlam edited this page Jan 16, 2018 · 31 revisions

The Ecore Metamodel Generator

The creation process is divided into two steps to avoid problems with cyclic data type references. First, all packages and types are created, including their inheritance and realization relations. Then, in a second step, all operations, references, and attributes are created. This step also created the data type package hierarchy, which contains all EDataType instances.

Generator Class Diagram

The Generator in the package eme.generator consists out of eight different generator classes a subpackage eme.generator.hierarchies and a subpackage eme.generator.saving:

  • EcoreMetamodelGenerator is the main generator class, it manages the whole generation process and handles the other generator classes. To create an Ecore metamodel from an intermediate model, use this class exclusively, it manages the calls to all other generators. Creating a metamodel can be achieved with the method generateMetamodel(), which returns a GeneratedEcoreMetamodel. 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().

  • GeneratedEcoreMetamodel is a container class encapsulates generated metamodels. It offers access to the metamodel root EPackage through the method getRoot(). The container class can additionally store saving information with a SavingInformation instance. This is made possible through the methods setSavingInformation() and getSavingInformation(). The method isSaved() checks whether a GeneratedEcoreMetamodel contains SavingInformation.

  • EPackageGenerator is the class that generates packages of the metamodel (EPackage objects) from the intermediate model. The functionality of the class is tied to its instance of an intermediate model. The class offers the method generate() for the creation of a metamodel, which is of type EPackage. The method automatically creates Ecore objects for all the contained elements (subpackages, classes, methods etc.) of the intermediate model.

  • EClassifierGenerator is used by the EPackageGenerator to generate the content of the packages. It offers three methods: generateEClassifer() generates an EClassifier from an ExtractedType. If the type already generated, it simply returns the EClassifier of the type. completeEClassifiers() finishes the EClassifier generation by adding methods and attributes to the classes. Also, it sorts the external types. generateDummy() generates an empty dummy EClass with a custom name.

  • EMemberGenerator is used by the EClassifierGenerator to generate the methods and attributes of the classifiers. It offers two methods. Both take an ExtractedType and an EClass as parameters. addOperations() generates EOperation objects for every method of the ExtractedType and adds them to the EClass. addAttributes() generates EStructuralFeature objects for every attribute of the ExtractedType and adds them to the EClass. Structural features can be an EAttribute or an EReference.

  • EDataTypeGenerator is used by the classes EClassifierGenerator and EOperationGenerator 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 addDataType(), addException(), addGenericArguments() and addTypeParameters().

    addDataType() adds either an EClassifier (for normal data types) or an EGenericType (for type parameters) to an ETypedElement from an ExtractedDataType. If it adds an EClassifier 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 addException() adds an exception from an ExtractedDataType to an EOperations. It works similar to the method addDataType().

    The method addGenericArguments() adds all generic arguments with their own generic arguments from an ExtractedDataType to an EGenericType. This method is separated from the method generate() because generic type arguments are added to the EGenericType instead of the EType of an ETypedElement, even if the data type is not an EGenericType.

    The method addTypeParameters() creates all type parameters and their bounds of an ExtractedType and adds them to an EClassifier.

    To use the EDataTypeGenerator one has to call the constructor with three parameters. The first one is the intermediate model. The second is the list of created EClassifier objects of the EPackageGenerator. This is needed to check whether a data type is an already created EClass. The third parameter is the ExternalTypeHierarchy object, which is needed to manage the containment of external types.

  • EPackageHierarchy is one of the three hierarchy classes in the subpackage eme.generator.hierarchies. It builds an EPackage hierarchy in a specific base package. The hierarchy is built from EClassifiers that are added to the class with an array of package names. An EClassifier can be added with the method add(EClassifier dataType, String[] path), which automatically manages the package creation. The method sort() sorts the content of the external type package hierarchy alphabetically. It has two subclasses that are also in the package eme.generator.hierarchies:

    1. InnerTypeHierarchy builds an inner type package hierarchy in a specific base package. This is used to manage nested types. The hierarchy is built from inner types that are added to the class with their relative path to the base package. An EClassifier can be added with the method add(EClassifier dataType, String relativePath).

    2. ExternalTypeHierarchy builds the external data type package hierarchy in the root package. It adds a data type package to the root package and contains every external EDataType in a package hierarchy in the data type package to avoid name collisions. An external data type can be added with the method add(EDataType dataType).

  • 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 must not be generated, the SelectionHelper stores that information. The method generateReport() then allows producing a report about what kind of elements were not generated and how many of them were not generated. The report distinguishes among 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