Mapping DSL referencing existing Ecore Elements [message #1807628] |
Wed, 05 June 2019 07:05  |
Eclipse User |
|
|
|
Hello everyone,
I am completely new to Xtext and would like to write a DSL to create a mapping between codestructures and model elements based on an Ecore meta model. Here an example of what I want to do:
Let's say we have a simple Ecore meta model defined, containing a single class named "Component" with an attribute "name: EString".
With my DSL I want to be able to then write something like this:
MarkerInterface {
codestructure: class
modelelement: class
condition: codestructure implements modelelement.name
mapping: modelelement.attribute(name) = codestructure.name
}
Instantiation {
Component - MarkerInterface
XYZ - MarkerInterface
}
So, I define a reusable mapping construct 'MarkerInterface', in which I want to map codestructures from type class to a modelelement from type class. The condition for the mapping to be applied is that the codestructure (so the class) needs to implement an interface with the name of the modelelement. I then want to set the name-attribute of the modelelement to the name of the codestructure.
This reusable mapping for the marker interface design pattern is then applied to the Ecore-class of the underlying meta modell "Component". Meaning: I search a Java project for all classes that implement an interface named "Component" and then create an object instance of the Ecore class "Component" and set the name-attribute of "Component" to the name of the Java class.
Eventually I would of course like to extend the DSL with additional mapping possibilities, e.g. allowing a condition like condition: codestructure annotatedWith modelelement.name to map classes with an annotation named after the Ecore-Class to the Ecore object to be created etc. But for now this should suffice.
I am having a hard time finding sufficient information or tutorials on this topic to write such a DSL with Xtext. I guess I would have to import the existing Ecore meta model somehow to reference the "Component" class in my "Instantiation"-parser rule. But I cannot seem to find anything on how to create the syntactical elements I need to write my 'condition' and 'mapping' parser rules.
I would be extremely thankful for any referal to resources that help me implement this, tips in general or possible (partial) implementations of this in Xtext.
If any further clarifications are needed, please feel free to ask.
Thanks a lot!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04606 seconds