Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generating multiple objects within one rule
Generating multiple objects within one rule [message #1830378] Fri, 24 July 2020 12:25 Go to next message
Philémon Houdaille is currently offline Philémon HoudailleFriend
Messages: 1
Registered: July 2020
Junior Member
Hello ! I have encountered a problem with xtext that I'm not sure how to solve, and haven't been able to find a solution to online yet.


I have two classes (Data and DataPurpose) that have a name, a bidirectional reference between them and an enumeration for DataPurpose (ExternalData, InputData, OutputData, MeasuredData); what I would like to do is to write for instance "data1 as ExternalData, InputData;", and that internally the language would create 3 objects : a "Data" type object, which references two "DataPurpose" type objects with respectively the enumeration "ExternalData" and "InputData", and also that the three objects have the same name ("data1").

I thought I could get away with using "tree rewrite actions" (like "{DataPurpose.data = current}" in the Data rule) after reading the Xtext documentation, but Ifound out that they don't allow to change the attributes of the created objects and only seems to work for containments and not references (my two objects are contained by another unique object and not within e ach other).

Has anyone ever encountered a similar situation? I attached screenshots of the metamodel and the grammar rule to the post if it is of any help.

index.php/fa/38652/0/

index.php/fa/38653/0/

Please note that slight metamodel modifications to solve the problem aren't preferred, but not out of the question either if there is no other solution. Thanks in advance for the help!
Re: Generating multiple objects within one rule [message #1830392 is a reply to message #1830378] Fri, 24 July 2020 15:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
Hi,

sounds like a usecase for IDerivedStateComputer
http://xtextcasts.org/episodes/18-model-optimization

(unfortunately may not work with 100% the same metamodel as you need a metamodel for the actually parsed model)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generating multiple objects within one rule [message #1830422 is a reply to message #1830392] Sat, 25 July 2020 19:28 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think that you will find it impossible to do since EMF objects have default constructors and subsequent assignments.

Even in Java you have to be a bit tricky about using "this" before it is fully initialized.

Much better to recognize that loading an EMF-based model from a file requires construction a naked object and gradually elaborating it.

But actually your use case seems to match the capabilities of a bidirectional reference for which you assign one direction and EMF automatically does the other.

Regards

Ed Willink
Previous Topic:post processing of the inferred meta model
Next Topic:XText to VSCode integration
Goto Forum:
  


Current Time: Sat Apr 27 04:34:38 GMT 2024

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

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

Back to the top