-
Notifications
You must be signed in to change notification settings - Fork 8
3. Generator
The creation process is divided in 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.
The Generator in the package eme.generator consists out of eight different generator classes and a subpackage eme.generator.saving:
-
EcoreMetamodelGeneratoris 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 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() -
EPackageGeneratoris 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. Because this, it is important to create a newEObjectGeneratorfor each intermediate model. The class offers the methodgenerate()for the creation of a metamodel, which is of typeEPackage. The method automatically creates Ecore objects for all the contained elements (subpackages, classes, methods etc.) of the intermediate model. -
EClassifierGeneratoris used by theEPackageGeneratorto generate the content of the packages. It offers two methods:generateEClassifer()generates anEClassifierfrom anExtractedType. If the type already generated, it simply returns theEClassifierof the type.completeEClassifiers()finishes theEClassifiergeneration by adding methods and attributes to the classes. Also it sorts the external types. -
EOperationGeneratoris used by theEClassifierGeneratorto generate the methods of the classifiers. It offers only one method:addOperations(). That method takes anExtractedTypeand anEClassas parameters. It then generatesEOperationobjects for every method of theExtractedTypeand adds them to theEClass. -
EDataTypeGeneratoris used by the classesEClassifierGeneratorandEOperationGeneratorto 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 methodsgenerate(),generateGeneric(),addGenericArguments(),addTypeParameters()andisTypeParameter().generate()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
generateGenericcreates a generic type parameter, which is anEGenericType, from anExtractedDataType. The type parameter can be used as generic argument for methods and attributes. This has to be used instead ofgenerate()to create a data type, if a data type is a type parameter. The methodisTypeParameter()checks whether anExtractedDataTypeis a type parameter of anEClassifier. If this is the case, one has to use the methodgenerateGeneric()instead ofgenerate()for the data type creation.The method
addGenericArguments()adds all generic arguments with their own generic arguments from anExtractedDataTypeto anEGenericType. This method is separated from the methodgenerate(), because generic type arguments are added to theEGenericTypeinstead of theETypeof anETypedElement, even if the data type is not anEGenericType. The methodaddTypeParameters()creates all type parameters of anExtractedTypeand adds them to anEClassifier.To use the
EDataTypeGeneratorone has to call the constructor with three parameters. The first one is the intermediate model. The second is the list of createdEClassifierobjects of the EobjectGenerator. This is needed to check whether a data type is an already createdEClass. The third parameter is theExternalTypeHierarchyobject, which is needed to manage the containment of external types. - The
-
ExternalTypeHierarchybuilds the external data type package hierarchy in the root package. It adds a data type package to the root package and contains every externalEDataTypein a package hierarchy in the data type package to avoid name collisions. An external data type can be added with the methodadd(EDataType dataType), which automatically manages the package creation. The methodsort()sorts the content of the external type package hierarchy alphabetically. -
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.
