Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem saving model instances with cross-references(Referenced element not in context (sometimes))
Problem saving model instances with cross-references [message #1761158] Mon, 08 May 2017 11:18 Go to next message
Frowin Ziegler is currently offline Frowin ZieglerFriend
Messages: 3
Registered: October 2014
Junior Member
Context: I have a model transformation from Excel into a few instances (with cross-references) of my Xtext meta model.

Question: How can I save my model instances with cross-references properly?

Example:
Definition of objects Defs.mydsl (this file has about 300 kb and around 1000 definitons):
...
define A {...}
define B {...}
...


Usages of objects (e. g. cross-references) Usages.mydsl:
...
use A for myUsage0 ...
use B for myUsage1 ...
...


As Defs.mydsl model contains all definitions it has to be saved first. Then we can save the models referencing to the definition.
However sometimes I get the following error upon saving the Usages.mydsl model:
Exception during transformation: java.lang.RuntimeException: No EObjectDescription could be found in Scope FBUsage.def for FBModel.usages[1936]->FBDef'A'
Semantic Object: FBModel.usages[0]->FBUsage'myUsage0'
URI: platform:/resource/atest/onboardnet/Usages.mydsl
EStructuralFeature: defsUsages::FBUsage.def
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
	at org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.getCrossReferenceNameFromScope(CrossReferenceSerializer.java:131)
	at org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.serializeCrossRef(CrossReferenceSerializer.java:104)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.getToken(SequenceFeeder.java:481)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:244)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:419)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:478)
	at fz.defs.usages.dsl.serializer.DefsUsagesSemanticSequencer.sequence_FBBoardnetSignal(DefsUsagesSemanticSequencer.java:329)
	at fz.defs.usages.dsl.serializer.DefsUsagesSemanticSequencer.sequence(DefsUsagesSemanticSequencer.java:266)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:412)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:478)
	at fz.defs.usages.dsl.serializer.DefsUsagesSemanticSequencer.sequence_FBModel(DefsUsagesSemanticSequencer.java:366)
	at fz.defs.usages.dsl.serializer.DefsUsagesSemanticSequencer.sequence(DefsUsagesSemanticSequencer.java:275)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:118)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:142)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:206)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:369)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)
....


I tried debuging CrossReferenceSerializer however when in debug mode it seems that the scope always contains the definition of 'A' (and thus the exception will not be thrown). This seems to be some kind of data race condition as in case we would wait a sufficient amount of time between the save operations the issue does not occur.

But sleeping is not a solution for me. I think that some kind of indexing must be done in the background so that the scope contains all saved elements properly.

The solutions I found so far:

  1. Injecting my own CrossReferenceSerializer which will not check the scope. (I guess this is a hack) This will not work when we would need customized formatter or when we need fully qualified names. (not very nice)
  2. I found some code which works by using some kind of waiting mechanism for auto-build (see waitForAutoBuild-method) https://github.com/NumberFour/n4js/blob/beadd39ac96b7a48ad96a246165603e3b0da975d/testhelpers/eu.numberfour.n4js.ui.tests.helper/src/eu/numberfour/n4js/tests/util/ProjectUtils.java (this is not very nice either)
  3. Currently I am using XtextResourceSetProvider for my resource set, I found there is XtextLiveScopeResourceSetProvider, which might be a solution, but I am unsure. Maybe someone can shed light on this functionality in the context of saving programatically generated models.


Did someone encounter the same problems? And found feasible solutions?


Re: Problem saving model instances with cross-references [message #1761160 is a reply to message #1761158] Mon, 08 May 2017 11:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Is your save within an IUnitOfWork which should inhibit concurrent changes?

Regards

Ed Willink
Re: Problem saving model instances with cross-references [message #1761161 is a reply to message #1761158] Mon, 08 May 2017 11:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

do you reference existing definitions or do you create new ones as well? (hence do you create 1 file at a time or multiple ones?)
how do you create the resourceset / the resource?

if you create multiple files

=> XtextLiveScopeResourceSetProvider

is the way to go


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem saving model instances with cross-references [message #1761162 is a reply to message #1761161] Mon, 08 May 2017 12:28 Go to previous messageGo to next message
Frowin Ziegler is currently offline Frowin ZieglerFriend
Messages: 3
Registered: October 2014
Junior Member
Hi Christian,

my transformation creates both Definitions and Usages.

The transformation works as follows. It creates two (or more) model roots; exactly one for the definitions (Definitions-Model) and the others for Usages. Then it adds Definitions to to the Definitions-Model and adds Usages to any Usage-Model. It is ensured that every Usage references a Definition.
Up to this point there are no files created or Resources used.

Then I get the injected XtextResourceSetProvider. In the provided ResourceSet I create resources by uri, then I add the models to each resource's contents. (Each resource contains one model)
Then I call save on all resources. I start by saving with resource for the Definitions-Model and continue with the resources for the Usage-Models.

Problem is that sometimes/often I will encounter the error from above, even though the Definition exists and is saved, it cannot be found in the scope when saving the Usage.

I have found different methods to get a ResourceSet (each with @Inject):

  1. Provider<ResourceSet>
  2. XtextResourceSetProvider
  3. XtextLiveScopeResourceSetProvider
  4. ?and maybe more?

When should I use which ResourceSetProvider?
Re: Problem saving model instances with cross-references [message #1761164 is a reply to message #1761162] Mon, 08 May 2017 12:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it "depends"

- standalone / eclipse => IResourceSetProvider or subclasses
- which state should be visible (Workspace / Workspace + Open Editors / Workspace + Open Editor + Changes to Resourceset
.....


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem saving model instances with cross-references [message #1766196 is a reply to message #1761164] Sat, 17 June 2017 14:17 Go to previous messageGo to next message
Puneet Patwari is currently offline Puneet PatwariFriend
Messages: 64
Registered: November 2014
Member
Hi Christian

Thanks a lot for your valuable answer regarding the use of "XtextLiveScopeResourceSetProvider". I was struggling with this for the last week.

Puneet
Re: Problem saving model instances with cross-references [message #1799287 is a reply to message #1766196] Tue, 04 December 2018 05:53 Go to previous messageGo to next message
Amar Banerjee is currently offline Amar BanerjeeFriend
Messages: 14
Registered: November 2018
Junior Member
Hi Cristian,

I am getting started with Xtext and trying to generate multiple serialized dsl files. I am using XtextLiveScopeResourceSetProvider, but it gives me the same error. "No EObjectDescription could be found in Scope.....". I am trying to inject the XtextLiveScopeResourceSetProvider, but the ResourceSet seems to be empty.

Request your help on this.

Thanks in advance.

Cheers,
Amar
Re: Problem saving model instances with cross-references [message #1799291 is a reply to message #1799287] Tue, 04 December 2018 07:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
without anything to reproduce: no idea:
=> use the debugger and see what the serializerscopeprovider does


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Optional properties using XText
Next Topic:Why my grammar don't validate the program and how to fix it
Goto Forum:
  


Current Time: Wed Apr 24 18:45:55 GMT 2024

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

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

Back to the top