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 17:00  |
Eclipse User |
|
|
|
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 151 times)
[Updated on: Wed, 04 May 2016 17:02] by Moderator
|
|
| |
Re: Problem serializing cross-reference after moving element to different resource [message #1732040 is a reply to message #1731839] |
Thu, 12 May 2016 04:02   |
Eclipse User |
|
|
|
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!
|
|
| |
Re: Problem serializing cross-reference after moving element to different resource [message #1803592 is a reply to message #1731839] |
Tue, 05 March 2019 03:35   |
Eclipse User |
|
|
|
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 #1803610 is a reply to message #1803605] |
Tue, 05 March 2019 07:34  |
Eclipse User |
|
|
|
I have been trying to create a simple example that can trigger my problem and discovered that the problem seems to be related to my current version of Eclipse/Xtext/Sirius. I tried a more recent version of everything (Eclipse 2018-12, Sirius 6.1.1. and Xtext 2.16) and it seems that the problem does not appear there. My guess is, that during some intermediate update in the Eclipse Oxygen Modeling tools, the so far working Xtext-Sirius integration has been broken/corrupted. I tried to debug Sirius but that is quite tiresome if you are not familiar with the source code.
Anyways, since the newer version seems to work, I now have to face the decision to update all my current sources to the newer Eclipse release.
|
|
|
Goto Forum:
Current Time: Thu Jun 12 17:00:01 EDT 2025
Powered by FUDForum. Page generated in 0.05513 seconds
|