Creating Generic EMF Metamodels
With the Eclipse Modeling Framework (EMF) you can create Ecore metamodels with generic type parameters:
- Open an Ecore metamodel with the Sample Ecore Model Editor
- In the tab Menu "Sample Ecore Editor" click on the item "Show Generics"
- Create and edit generic metaclasses as you like
- As the editor is not really userfriendly the order of your action is important:
- First create your generic superclasses
- Set their type parameters: New Child -> EType Parameter
- Bind your types if needed (like in Java "T extends Something"): New Child -> EGeneric Bound Type
- Then create subclasses that extend your generic superclasses
- If you do it in this order the EGeneric Type Argument of the super type relationship will automatically be added and set to "?" for you (You can also do this by clicking New Child -> EGeneric Type Argument on the super type relationship)
- Ensure that you used generics correctly
- Make sure that all uses of bound type parameters of superclasses are also bound (to the same or a more restrictive type) in the subclasses
- Make sure that all subclasses of generic superclasses are parameterized
- Validate your metamodel
- If validation fails, then try creating a generator model as the validation in the generator model wizard during metamodel loading gives you more precise error messages.
P.S. If you like the textual metamodel editor OclInEcore then be aware of the fact that it does not support generic bound types. They have to be added in the Sample Ecore Editor afterwards.
An example can be found in the article DZone: Generics in Eclipse Modelling Framework