Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Is there a recommended way to turn the inferred Ecore model into imported one?(developing the grammar / Ecore)
Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810907] Wed, 21 August 2019 14:50 Go to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 9
Registered: May 2013
Junior Member
Hi,

I'd like to know, if there is any way to take the inferred Ecore model and to turn it into one that can be imported from the grammar file (.xtext) using the 'import' sentence?

Is there a recommended procedure for such a switch from inferred Ecore model to the imported one?

Thanks in advance,
Alexei

Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810911 is a reply to message #1810907] Wed, 21 August 2019 17:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This is https://bugs.eclipse.org/bugs/show_bug.cgi?id=340028 where you'll find some clues.

If you're familiar with EMF, it's only tedious, if not, it could be very frustrating.

https://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/plugins/org.eclipse.ocl.xtext.markup/model/Markup.ecore shows one of a family of Xtext DSLs that use manual Ecore+GenModel with all build functionality separated out into a separate build plugin to reduce delivered bloat.

Regards

Ed Willink
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810912 is a reply to message #1810911] Wed, 21 August 2019 18:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
http://www.lorenzobettini.it/2014/02/switching-from-an-inferred-ecore-model-to-an-imported-one-in-your-xtext-grammar/

Gives some hints but uses the old workflow

In general

If you want to add the meta model to the same project as the grammar
Make sure you invoke the xtext Generator first and the ecoregenerator component second


I am not sure why you are asking and what the specific problem is you have


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810923 is a reply to message #1810912] Thu, 22 August 2019 06:29 Go to previous messageGo to next message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 157
Registered: February 2016
Senior Member
You can also find a detailed description with examples in the book of Lorenzo Bettini:
Implementing Domain-Specific Languages with Xtext and Xtend (Second Edition)
- Switching to an imported Ecore model (page 358)
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810941 is a reply to message #1810923] Thu, 22 August 2019 11:07 Go to previous messageGo to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 9
Registered: May 2013
Junior Member
Thanks, Tamas (and thanks to Lorenzo!). I've used the procedure described in the second edition of his book on page 358, and it looks like everything goes fine. The only difference is that I chose the default build system when setting up the project (not the Maven, as Lorenzo recommended). Still see no problem that arise from this difference.

At present only one inconvenience is that I need to run the model code generation by hand each time I change the model. But this is tolerable (I think :-)).

Regards,
Alexei
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810943 is a reply to message #1810941] Thu, 22 August 2019 11:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
In principle it should also work with a *.xcore model and that auto generates whenever the *.xcore changes:

https://wiki.eclipse.org/Xcore#Converting_a_GenModel_to_an_Xcore_Model

Christian will know best if this actually works well in practice...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810947 is a reply to message #1810943] Thu, 22 August 2019 14:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
there are still gazillions of problems as we use and old emf in standalone mode (gradle/maven) so i am not a big fan of using xcore in the same project as xtext.
but i did not see that xcore was asked for in the first place


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810948 is a reply to message #1810947] Thu, 22 August 2019 14:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
the model generation by hand: is this about eclipse or about buildsystem / maven / gradle?
as i have said you could add it to the / a workflow


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 22 August 2019 14:25]

Report message to a moderator

Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810950 is a reply to message #1810948] Thu, 22 August 2019 15:38 Go to previous messageGo to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 9
Registered: May 2013
Junior Member
Christian, I am not very fluent with .mwe2 workflow specification language.

After moving the .ecore and .genmodel files to the model/custom directory and following other steps that Lorenzo Bettini described in second edition of his book, I got a situation, where I can use that inferred model as the imported one. But should regenerate model code by hand each time I change the model.

One of the final steps in the Lorenzo's procedure was adding something like
referencedResource ="platform:/resource/org.example.customgreetings/model/custom/Greetings.genmodel"

after the
language = StandardLanguage {
name = "org.example.customgreetings.Greetings"
fileExtensions = "greetings"

piece into the .mwe file.

Than I have tried adding the following line
			fragment = ecore2xtext.Ecore2XtextValueConverterServiceFragment2 auto-inject {}

immediately after the "referencedResource" line.

But seems, that doesn't turn the automatic model code generation on. Can you give me a clue, what lines and where should I add to the workflow? Is it possible that the source of problem is in my choice of the default build system when I was setting up the project?

And also is there any source of information on the mwe2 automagic related to the Xtext?

Thanks for your patience,
Alexei

[Updated on: Thu, 22 August 2019 15:42]

Report message to a moderator

Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810952 is a reply to message #1810950] Thu, 22 August 2019 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
As I have said

You need to add a second content after the Xtext generator

The component is called EcoreGenerator


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810955 is a reply to message #1810952] Thu, 22 August 2019 16:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Never mind then. :-P He did mention needing to generate manually, but if there is some other way to integrate that in the workflow, then just as wel...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810957 is a reply to message #1810952] Thu, 22 August 2019 16:27 Go to previous messageGo to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 9
Registered: May 2013
Junior Member
Thanks, Christian,
finally I got it!

Now model code is regenerated during each run of the .mwe2 workflow.

For other interested: to get imported model code regenerate each time I run the .mwe2 workflow, I have made the following changes in the .mwe2 file:

1. Added
import org.eclipse.emf.mwe2.ecore.EcoreGenerator

2. After the import section I have added line like
var projectName = "org.xtext.example.mydsl"

before the Workflow section
3. In the Workflow section body after the specification of the XtextGenerator component
component = XtextGenerator {
...
}

I have added the lines like
	component = EcoreGenerator {
		genModel = "platform:/resource/${projectName}/model/custom/MyDsl.genmodel"
		srcPath = "platform:/resource/${projectName}/src"
	}


Thats all!

Thanks for your replies and advices!

Alexei

[Updated on: Sat, 24 August 2019 14:11]

Report message to a moderator

Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810959 is a reply to message #1810955] Thu, 22 August 2019 16:42 Go to previous messageGo to next message
Alexei Adamovich is currently offline Alexei AdamovichFriend
Messages: 9
Registered: May 2013
Junior Member
Hi, Ed.

Possibly I expressed it incorrectly.

First, I wanted to edit the .ecore model by hand. So I don't need .ecore and .genmodel be generated automatically from the grammar specification.

This goal was reached by using the procedure that is described by Lorenzo Bettini in the second edition of his book.

Second, I prefer that the Java packages, that are produced by Ecore generator ouf of .genmodel/.ecore files, be regenerated automatically during each run of the .mwe2 workflow.

This was made by adding the EcoreGenerator component specification to the .mwe2 file.

Regards,
Alexei

[Updated on: Thu, 22 August 2019 16:47]

Report message to a moderator

Re: Is there a recommended way to turn the inferred Ecore model into imported one? [message #1810966 is a reply to message #1810959] Thu, 22 August 2019 17:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
I assume you wanted it generated automatically when you changed the *.ecore itself, which is what happens when you edit the *.xcore, but if you don't need that and it's problematic to integrate that, then forget I said anything.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Couldn't resolve reference in DSL using Xtext
Next Topic:Left recursive grammar rule
Goto Forum:
  


Current Time: Tue Apr 16 04:02:04 GMT 2024

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

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

Back to the top