Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Niels Brouwers is currently offline Niels BrouwersFriend
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:


  1. Open main.statemachine with sample reflective Ecore model editor
  2. Load commands.statemachine (using menu Load Resource ...) to add commands.statemachine resource to the ResourceSet.
  3. Select clearAlarm Command from main.statemachine resource and drag it to the Statemachine Commands model element in the commands.statemachine resource.
  4. 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:

  1. 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?
  2. 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?
  3. 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?
  4. ...?


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 120 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 #1731839 is a reply to message #1731391] Tue, 10 May 2016 12:40 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
To 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.

Regarding your questions:
1. Your expectation is correct, live scoping should fix the issue.
2. again, live scoping is the answer.
3. Close call. The Xtext builder is responsible for updating the index and global scoping is a view on the index. Problem is, the builder only runs when a file is saved to disk, i.e. *after* your serialization happens. Live scoping creates an overlay on top of the index based on your ResourceSet's contents. Thereby, changes that you apply programmatically to your model immediately become visible in the index and therefore in scoping.

hth,
Moritz
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 Go to previous messageGo to next message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Moritz Eysholdt wrote on Tue, 10 May 2016 08:40
To 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:


  1. 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?
  2. 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 #1732573 is a reply to message #1732040] Wed, 18 May 2016 10:45 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
1) The key is usually stored in the resource set, as its creator knows best in which context it is used. You should not change that for a resource set you haven't created yourself.
The IResourceDescriptions are usually chained, and the first ones can shadow the ones later in the chain. This is how the live scope only holds the descriptions of the currently dirty resources, and delegates to the persisted scope for all other cases.

2) Yes, the LiveScopeResourceSetInitializer can use any kind of resource set.


---
Get professional support from the Xtext committers at www.typefox.io
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 Go to previous messageGo to next message
Alex Lotz is currently offline Alex LotzFriend
Messages: 9
Registered: October 2017
Junior Member
Moritz Eysholdt wrote on Tue, 10 May 2016 12:40
To 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 #1803593 is a reply to message #1803592] Tue, 05 March 2019 08:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
@Alex see https://www.eclipse.org/forums/index.php/t/1097789/

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 Go to previous messageGo to next message
Alex Lotz is currently offline Alex LotzFriend
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

Re: Problem serializing cross-reference after moving element to different resource [message #1803605 is a reply to message #1803596] Tue, 05 March 2019 10:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
i dont know how sirius creates the resourceset in their xtext integration
did you try to debug for creators of xtextresourceset?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 05 March 2019 10:28]

Report message to a moderator

Re: Problem serializing cross-reference after moving element to different resource [message #1803610 is a reply to message #1803605] Tue, 05 March 2019 12:34 Go to previous message
Alex Lotz is currently offline Alex LotzFriend
Messages: 9
Registered: October 2017
Junior Member
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.
Previous Topic:Xtext / Xtend 2.17 Release
Next Topic:XImportSection and global scoping
Goto Forum:
  


Current Time: Tue Apr 16 11:27:48 GMT 2024

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

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

Back to the top