Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA » M2M using Xtext
M2M using Xtext [message #1770224] Wed, 09 August 2017 08:18 Go to next message
zhang ph is currently offline zhang phFriend
Messages: 17
Registered: March 2017
Junior Member
Hi,
Recently, I want to use VIATRA to finish M2M transformation, and my model is defined in Xtext, so how can I use VIATRA to finish this transfmation? Could you offer me any suggestions?
Re: M2M using Xtext [message #1770232 is a reply to message #1770224] Wed, 09 August 2017 09:33 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 187
Registered: September 2015
Senior Member
I assume the metamodel of your model is derived from an Xtext grammar and you want to run the transformation on the instance model. (If you want to query and transform an Xtext grammar, that's a bit different, but not much, since that is also an instance model loaded into an Xtext resource).

If you want to develop queries and try them in the Query Results view on a model, check this thread: https://www.eclipse.org/forums/index.php/t/1075596/

Otherwise, the transformation itself is the same as a regular EMF model once you have a reference to the ResourceSet, Resource or any EObject in the model.

One important note: when you change text in the Xtext editor, Xtext modifies the underlying EMF model in a way that some notifications will NOT be sent and therefore the incremental query results will be incorrect. There is a rather long discussion on this Xtext behavior in https://bugs.eclipse.org/bugs/show_bug.cgi?id=387119 and https://github.com/eclipse/xtext/pull/980

Maybe Zoltan can point to some more user friendly description of the limitations with querying Xtext based models.
Re: M2M using Xtext [message #1770247 is a reply to message #1770232] Wed, 09 August 2017 11:03 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 335
Registered: July 2015
Senior Member
Hi,

Xtext models can be used as sources or targets of the transformation when opening the model into an EMF Resource, however, the following things are necessary to consider:

* You have to make sure everything is registered as necessary. In Eclipse environments the UI plug-in generated by Xtext should do this automatically; in non-Eclipse environments you can use the standalone setup in the core language project. Make sure you don't mix them - use only the one necessary.
* If your language uses Xbase, you might need some additional registration steps (e.g. specifying the classloader to use) before you can open the model.
* As Ábel mentioned, don't try to react to EMF events on an open Xtext-based editors, as notifications can be missed. By using a DocumentListener you can find out the points when the model is stable, and there you can initialize a throwaway VIATRA Query engine for a batch transformation. If you open the model manually, you can rely on the VIATRA APIs to work as expected.
* If you are generating Xtext models, ensure that the generated model can be serialized at all points.

Best regards,
Zoltán
Re: M2M using Xtext [message #1771237 is a reply to message #1770247] Wed, 23 August 2017 08:25 Go to previous messageGo to next message
zhang ph is currently offline zhang phFriend
Messages: 17
Registered: March 2017
Junior Member
I have read the contents in above links and am still confused. Now I describe my scenario.
In my case, I follow the VIATRA totorial(https://www.eclipse.org/viatra/documentation/tutorial.php) and use incremental model transformation, The source and target model are all based on Xtext. After Starting the engine on traceability model, I edit the source model and save it in Xtext editor. I found incremental transformation cann't be triggered. Then I switched to traceability editor, the transformation is actived. I think it is because switching to traceability editor active loading process for model, whitch triggers the transformation. But this seems unavailable. So I want to implement the function that editing source model in Xtext editor, then incremental transformation can be executed automatically instead of switching editor. Could you offer me any suggestions about this?
Hope for your reply!
Re: M2M using Xtext [message #1771239 is a reply to message #1771237] Wed, 23 August 2017 08:36 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 335
Registered: July 2015
Senior Member
Hi,

in short, I do not recommend starting an incremental transformation over an Xtext _editor_, as Xtext is known to turn off notifications on model changes (see the previously referred bug [1] for a more detailed, but quite technical discussion about the issue) that causes incorrect results coming out from the query engine.

The only thing that can work is to listen to file changes (e.g. with an Eclipse builder [2]), and then parse the file when it was changed and start a batch transformation (not event-driven) that looks at the output model, and _updates_ it to represent the current state of the model. This is safe, as the Xtext model does not change during the transformation; and when the file changes again, the builder will be notified.

Hope this is helpful,
Zoltán

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=387119
[2] http://www.eclipse.org/articles/Article-Builders/builders.html
Re: M2M using Xtext [message #1771240 is a reply to message #1771237] Wed, 23 August 2017 09:17 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 187
Registered: September 2015
Senior Member
Quote:
Then I switched to traceability editor, the transformation is actived.


This occurs because the traceability editor and the Xtext editor work on separate ResourceSets with their own instances loaded from the Resources (files in this case).

The modifications in the Xtext editor are not visible to the VIATRA Query engine running on the traceability editor directly, since they use see different EObject instances.

When you save the Xtext editor, it writes to the file and switching to the traceability editor triggers a check on modified resources. In case of modfications, the resource is unloaded and loaded again, which causes model modifications that trigger the transformation.

The relevant code is handleActivate() and handleChangedResources() in the EMF generated Editor class.
Re: M2M using Xtext [message #1771317 is a reply to message #1771239] Thu, 24 August 2017 01:38 Go to previous messageGo to next message
zhang ph is currently offline zhang phFriend
Messages: 17
Registered: March 2017
Junior Member
Hi Zoltan,
Quote:
I do not recommend starting an incremental transformation over an Xtext _editor_

Maybe I don't explain my scenario clearly. Currently, I just use Xtext as source(Only one Xtext model) and target model. And I start an incremental transformation over traceability model(which is XMI format). So I think the bug mentioned by you may not occur in my scenario. Am I right?
Quote:
see the previously referred bug [1]

In this bug, "references to external resource" means what ? an Xtext model based on same or different meta-model ?

[Updated on: Thu, 24 August 2017 02:13]

Report message to a moderator

Re: M2M using Xtext [message #1771334 is a reply to message #1771317] Thu, 24 August 2017 07:41 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 335
Registered: July 2015
Senior Member
Hi,

zhang ph wrote on Thu, 24 August 2017 01:38
Hi Zoltan,
Quote:
I do not recommend starting an incremental transformation over an Xtext _editor_

Maybe I don't explain my scenario clearly. Currently, I just use Xtext as source(Only one Xtext model) and target model. And I start an incremental transformation over traceability model(which is XMI format). So I think the bug mentioned by you may not occur in my scenario. Am I right?


Sadly, the issue is not so simple. I am not exactly sure what happens inside the traceability editor in case the Xtext model is updated outside the editor, but I see two scenarios. (1) The model is either not reloaded at all; in this case, the transformation will trivially not update the target model; or (2) the model is reloaded, and thus reparsed, references on the Xtext model may or may not break (e.g. if you have reordered or inserted something into the Xtext model, there is a fair chance that references from the XMI model will break), and additionally it is possible that you trigger the original, notification-related bug as well (although I am not sure of this).

Basically, there are two required steps to trigger this issue: (1) you have at least a single query, that requires the Xtext resource indexed (e.g. its match set refers to that model), and (2) the textual syntax is reparsed (either because it was modified in the text editor; or it was modified outside the current ResourceSet, and needs to be reloaded); otherwise there is no chance that the index becomes stale.

The fact that I suggested a builder-based approach avoids this issue as there is no reparsing done in an already indexed model.

zhang ph wrote on Thu, 24 August 2017 01:38

Quote:
see the previously referred bug [1]

In this bug, "references to external resource" means what ? an Xtext model based on same or different meta-model ?

The original issue report was found where an Xtext resource (e.g. file) referred to model elements in another resource (e.g. file). But there are a lot of occurrences of this pattern throughout Xtext where notifications are turned off, so there might be other issues as well.

Best regards,
Zoltán
Previous Topic:M2M increamental transformation of CPS benchmark
Goto Forum:
  


Current Time: Sun Nov 19 03:18:05 GMT 2017

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

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