Home » Modeling » TMF (Xtext) » Problem serializing cross-reference after moving element to different resource
Problem serializing cross-reference after moving element to different resource [message #1731391] |
Wed, 04 May 2016 21:00 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Consider the following grammar (projects attached to this post), which is a modification to the standard Fowler's statemachine DSL example:
grammar org.eclipse.xtext.example.fowlerdsl.Statemachine with org.eclipse.xtext.common.Terminals
generate statemachine "http://www.eclipse.org/xtext/example/fowlerdsl/Statemachine"
Statemachine :
'Statemachine' name = QualifiedName '{'
('commands'
commands+=Command+
'end')?
states+=State*
'}'
;
Command:
name=QualifiedName code=ID
;
State:
'state' name=QualifiedName
('actions' '{' actions+=[Command|QualifiedName]+ '}')?
'end'
;
QualifiedName:
ID ('.' ID)*
;
In this grammar, elements are identified by a fully qualified name. References to other elements, possibly contained in different models, are specified by fully qualified name.
The MWE2 workflow shipped with the example is untouched. I believe the relevant fragments are declared as follows:
// old scoping and exporting API
// fragment = scoping.ImportURIScopingFragment auto-inject {}
// fragment = exporting.SimpleNamesFragment auto-inject {}
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
fragment = exporting.QualifiedNamesFragment auto-inject {}
fragment = builder.BuilderIntegrationFragment auto-inject {}
The following two models are valid statemachine models according to the specified grammar.
main.statemachine
Statemachine Main {
commands
clearAlarm alarm1
end
state state1
actions {
Commands.soundAlarm
clearAlarm
}
end
}
commands.statemachine
Statemachine Commands {
commands
soundAlarm alarm1
end
}
In our application, a use case exists to move elements, in this case for example elements of type Command, to another model resource using EMF based editors, e.g. Sirius based graphical editors or even standard tree editors generated by EMF.
When performing such a change, e,g, moving the clearAlarm command from resource main.statemachine to resource commands.statemachine, will result in the following error:
java.lang.RuntimeException: No EObjectDescription could be found in Scope State.actions for Statemachine'Commands'.commands[1]->Command'clearAlarm'
Semantic Object: Statemachine'Main'.states[0]->State'state1'
URI: platform:/resource/tst/main.statemachine
Steps to reproduce:
- Open main.statemachine with sample reflective Ecore model editor
- Load commands.statemachine (using menu Load Resource ...) to add commands.statemachine resource to the ResourceSet.
- Select clearAlarm Command from main.statemachine resource and drag it to the Statemachine Commands model element in the commands.statemachine resource.
- Save the resources
Saving the resources results in the above mentioned error message. From this message, I conclude that the Command element is searched in the global scope by name clearAlarm but fails to find it.
I can think of a couple of reasons why the element cannot be found:
- When the containment of the clearAlarm Command element changes from the Main statemachine to Commands statemachine, it's fully qualified name should become Commands.clearAlarm. So instead of searching the global scope for a Command element with name clearAlarm, it should search for a Command element with name Commands.clearAlarm. If so, how to correct for this behavior?
- The clearAlarm Command element is searched for in the incorrect scope. When debugging the code, I noticed that the element is searched for in the local scope as well as the parent scopes. It could be that the chain of scopes is incorrect, but I failed to discover any problem here. Also, I would expect the global scope to contain the element anyhow, since it's moved to a different resource. If the scopes are incorrect, how to fix this?
- It's the Xtext Builder's responsibility to update the global scope corresponding to the move of the clearAlarm Command element to the commands.statemachine resource. Could it be the case that the update hasn't been finished yet when the cross-reference to this element is serialized to disk? If so, how to correct for this?
- ...?
Feature versions:
- Eclipse Modeling Tools 4.5.2.20160218-0600
- Xtext Complete SDK 2.9.1.v201512180746
Anyone who can help me out?
-
Attachment: grammars.zip
(Size: 1.59MB, Downloaded 134 times)
Kind regards,
Niels Brouwers.
[Updated on: Wed, 04 May 2016 21:02] Report message to a moderator
|
|
| |
Re: Problem serializing cross-reference after moving element to different resource [message #1732040 is a reply to message #1731839] |
Thu, 12 May 2016 08:02 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Moritz Eysholdt wrote on Tue, 10 May 2016 08:40To avoid outdated scopes after programmatically changing the model, you'll need to enable "live scoping" via org.eclipse.xtext.ui.resource.LiveScopeResourceSetInitializer. See JavaDoc for an explanation.
Thanks for the hint. Fortunately, I was able to find it out by myself by a combination of reading the documentation and debugging the code. I am still pleased by your confirmation that it's the correct solution to fix the issue.
I have some follow-up questions that you, or someone else, are able to answer:
- The RuntimeModule contains the following snippet.
// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
public void configureIResourceDescriptionsPersisted(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.class);
}
The PERSISTED_DESCRIPTIONS key is apparently the default fro the ResourceDescriptionsProvider injected. I would have expected that in this case, the Xtext index would only be updated when the resources are modified, also in case of using the Xtext generated textual editors. However, when opening multiple Xtext resources, I see that the index is updated 'live'. I conclude this as the content assist is updated and cross-references are resolved correctly, even without saving the resources. My question therefore is what is the effect when injecting the ResourceDescriptionsProvider instance with the key set to LIVE_SCOPE?
- Is it possible to enable live scope for ResourceSet implementations other then the XtextResourceSet, e.g. the standard ResourceSetImpl implementation?
Thanks!
Kind regards,
Niels Brouwers.
|
|
| |
Re: Problem serializing cross-reference after moving element to different resource [message #1803592 is a reply to message #1731839] |
Tue, 05 March 2019 08:35 |
Alex Lotz Messages: 9 Registered: October 2017 |
Junior Member |
|
|
Moritz Eysholdt wrote on Tue, 10 May 2016 12:40To avoid outdated scopes after programmatically changing the model, you'll need to enable "live scoping" via org.eclipse.xtext.ui.resource.LiveScopeResourceSetInitializer. See JavaDoc for an explanation.
...
Hi,
I believe I have a similar problem as described above and I came to the same conclusion that this has to be related to the Xtext's live scope RS provider/initializer. However, I don't quite understand the exact place where to change the "regular" RS provider (or initializer?) for the live-scope version.
I have a newer version of Xtext and Sirius, more precisely:
- Eclipse Oxygen
- Xtext 2.12
- Sirius 5.1.1
I have installed the "Sirius Integration with Xtext" plugin, which I was thinking that it actually should do the Live Scoping for me, but apparently it does not. I also tried to implement my own extension for the "org.eclipse.sirius.resourceStrategy", but this extension point seems not to be triggered from Sirius at all.
Can anybody help me out, what am I missing?
Cheers,
Alex
|
|
| |
Re: Problem serializing cross-reference after moving element to different resource [message #1803596 is a reply to message #1803593] |
Tue, 05 March 2019 08:53 |
Alex Lotz Messages: 9 Registered: October 2017 |
Junior Member |
|
|
Thanks, that is actually my own post over there. :-) I managed to use the Live Scope Provider with plain Xtext and my own Project-Creation Wizard, but I fail to do so in combination with Sirius, because Sirius by itself seems to initialize the default resource-set provider instead of the live scope one. I am not sure where is the place that teaches Sirius to use the live scope provider. Or can I specify the Xtext runtime module itself to always use the live scope provider? Is this a good idea, and if so what is the exact binding rule in the runtime module that I have to override?
[Updated on: Tue, 05 March 2019 09:02] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Wed Sep 25 08:30:23 GMT 2024
Powered by FUDForum. Page generated in 0.04680 seconds
|