Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializing several resources with cross references
Serializing several resources with cross references [message #1821111] Wed, 05 February 2020 17:21 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
I generated several models with cross references between them as a graph of semantic objects.

I serialized some models into their own resources using simple resource.save() - worked well.

Then I tried to serialize another model with cross references to an already saved model, but now the serializer informed me that it could not find the target of a cross reference in the scope and refused to create the file.

Should this be supported by Xtext? Out of the box or with some additional tricks?

I did ensure that all resources live in the same resource set.

For a moment I was thinking I might need to invoke a build between save()s, but then the EObjects in any cross references would be invalid anyway right?

Cross references into models existing prior to my operation can be serialized OK.

When manually creating the intended models (DSL text) then all cross references can be successfully resolved. In my particular situation, the cross reference is free to use either a qualified name or a simple name plus import.
Re: Serializing several resources with cross references [message #1821112 is a reply to message #1821111] Wed, 05 February 2020 17:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13629
Registered: July 2009
Senior Member
if you are in eclipse make sure

- you create the resourceset with IResourceSetProvider
- initialize it with livescopeResourceSetInitializer
- add all resources to the resourceset before start saving


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing several resources with cross references [message #1821151 is a reply to message #1821112] Thu, 06 February 2020 11:26 Go to previous messageGo to next message
Marie-Saphira Flug is currently offline Marie-Saphira FlugFriend
Messages: 21
Registered: January 2019
Junior Member
Hi,
I have a follow up question concerning the resources and and cross references between them. I have a project in which some resources already exist and I want to add additional resources that reference the existing ones. To achieve that I had to "load" all resources once:
private void addResources(IProject project) {
		XtextResourceSet resourceSet = (XtextResourceSet) Activator.getInstance().getInjector(Activator.MYDSL)
                         .getInstance(XtextLiveScopeResourceSetProvider.class).get(project);
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		IResource members[] = null;
		try {
			members = project.members();
		} catch (CoreException e) {
			e.printStackTrace();
		}
		for (IResource member : members) {
			if (member instanceof IFile) {
				if (((IFile) member).getFileExtension().equals("mydsl")) {
					resourceSet.getResource(URI.createPlatformResourceURI(member.getFullPath().toString(), true), true);
				}
			}
		}
	}


But I recently learned that you should never use getResource() explicitly https://de.slideshare.net/holgerschill/deep-dive-into-xtext-scoping-local-and-global-scopes-explained. Is there documentation that explains why not? And what to do instead?

Also I read a lot of posts asking about the resources and people having problems with them, maybe it would be very helpful to many people to add a chapter to the documentation https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html?
Re: Serializing several resources with cross references [message #1821155 is a reply to message #1821151] Thu, 06 February 2020 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13629
Registered: July 2009
Senior Member
@marie-saphira.

You should not load a resource explicitly during scoping
That is what the presentation is about.
It's tremendously slow compared to using the global scope

There is also a difference between standalone and ui (Eclipse)
Usecase


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing several resources with cross references [message #1821160 is a reply to message #1821155] Thu, 06 February 2020 12:34 Go to previous messageGo to next message
Marie-Saphira Flug is currently offline Marie-Saphira FlugFriend
Messages: 21
Registered: January 2019
Junior Member
Ah ok, thanks for clearing that up!
Re: Serializing several resources with cross references [message #1821219 is a reply to message #1821112] Fri, 07 February 2020 10:20 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
Christian Dietrich wrote on Wed, 05 February 2020 18:26
if you are in eclipse make sure

- you create the resourceset with IResourceSetProvider
- initialize it with livescopeResourceSetInitializer
- add all resources to the resourceset before start saving


Works like a charm. Thanks, Christian!
Re: Serializing several resources with cross references [message #1821288 is a reply to message #1821219] Mon, 10 February 2020 12:25 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 164
Registered: July 2009
Location: Canada
Senior Member
Hi Stephan,

By any chance, do you have a unit-test that simulates the error condition?

I have tried 3 different ways to reproduce the error, but nothing worked for me. PS - https://bit.ly/2SyRBop

Thanks in advance.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Serializing several resources with cross references [message #1821302 is a reply to message #1821288] Mon, 10 February 2020 14:54 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
@Neeraj, sorry, no unit test, this is work-in-progress on several internal / proprietary DSLs.

Is a test needed as a regression test for xtext? Otherwise I don't see the need to create a standalone reproducer.
Re: Serializing several resources with cross references [message #1821313 is a reply to message #1821302] Mon, 10 February 2020 18:15 Go to previous message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 164
Registered: July 2009
Location: Canada
Senior Member
Hi Stephan,

Thanks for your comments.

I wanted a reproducible test so that I could try out @Christian's suggestion. It was not meant for xtext regression. Tx.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Previous Topic:Serialization requires names to be "more unique" than other parts of the language implemen
Next Topic:Changing Formatter2 Indentation Preferences from Tab to Spaces?
Goto Forum:
  


Current Time: Fri Oct 23 08:37:19 GMT 2020

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

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

Back to the top