Generating multiple objects within one rule [message #1830378] |
Fri, 24 July 2020 08:25  |
Eclipse User |
|
|
|
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.


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 #1830422 is a reply to message #1830392] |
Sat, 25 July 2020 15:28  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03420 seconds