Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Mapping DSL referencing existing Ecore Elements(Beginner trying to write their first DSL with general questions)
Mapping DSL referencing existing Ecore Elements [message #1807628] Wed, 05 June 2019 11:05 Go to next message
Kai S. is currently offline Kai S.Friend
Messages: 18
Registered: June 2019
Junior Member
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!
Re: Mapping DSL referencing existing Ecore Elements [message #1807666 is a reply to message #1807628] Wed, 05 June 2019 20:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13071
Registered: July 2009
Senior Member
- is there a reason you do use ecore and not java/ecore java classes, then you could look at what xbase does.
- if you want to have expressions and dont want to use xbase you can write them yourself. maybe this one is a starting point https://www.dietrich-it.de/xtext/2013/05/18/xtext-and-dot-expressions.html
- you may have a look at xcore https://github.com/eclipse/emf/blob/master/plugins/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/Xcore.xtext



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Mapping DSL referencing existing Ecore Elements [message #1807714 is a reply to message #1807666] Thu, 06 June 2019 15:24 Go to previous message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 50
Registered: February 2016
Member
You may also get some inspiration from the following blog posts:
https://blogs.itemis.com/en/how-to-reference-uml-elements-from-xtext-dsls
https://blogs.itemis.com/en/combining-emf-models-with-xtext-dsls
Previous Topic:Release of Xtext & Xtend 2.18
Next Topic:How to automatically compile and run mydsl application from eclipse?
Goto Forum:
  


Current Time: Fri Aug 23 20:13:37 GMT 2019

Powered by FUDForum. Page generated in 0.01767 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top