Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextLinkingDiagnostic Error while loading xtext model
XtextLinkingDiagnostic Error while loading xtext model [message #1791009] Thu, 21 June 2018 11:35 Go to next message
Peter Altmayer is currently offline Peter AltmayerFriend
Messages: 7
Registered: April 2018
Junior Member
Hi,

I'm loading a xtext model in an java application.
There are no errors if a load a model with no further reference to other models.
But if I load a xtext model that has a reference to another model I get following error message:
XtextLinkingDiagnostic: null:27 Couldn't resolve reference to <[Referenced Element Type]> '[Reference Element Name]'.
(I replaced the real names of Element and Element Type)

This is the way I load the model:
public static void main(String[] args) {		
	Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
	new MySecondDslStandaloneSetup().register(injector);
	
	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		
	resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
	File file = new File("/path/to/model.mdl");
	Resource resource = resourceSet.getResource(URI.createURI(file.toURI().toString()), true);
		
	for(Diagnostic error : resource.getErrors() )
		System.err.println(error.toString());


Just to make it clear: The application does not throw any exception. The error is obtained from the resource (see for-loop). Also the model itself is loaded properly, only the references to the other model are missing.
I think the problem is the way, I import the referenced model (this is the first line of model.mdl):
IMPORT "my_second_model.mdl2"

Both of the two models are in the same folder. Do I have to write something like IMPORT "/platform..."?
Currently, even if i import a non existing model, there are no further errors. It seems like the import statement is just ignored while loading the model like this (the models itself are working properly, references are resolved while editing the model).
Re: XtextLinkingDiagnostic Error while loading xtext model [message #1791010 is a reply to message #1791009] Thu, 21 June 2018 11:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12239
Registered: July 2009
Senior Member
there is no import traversal => you need to populate the resourceset with all resources upfront.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XtextLinkingDiagnostic Error while loading xtext model [message #1791011 is a reply to message #1791010] Thu, 21 June 2018 11:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12239
Registered: July 2009
Senior Member
and you should remove the resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
and do a manual ecoreuril.resolveall after loading all resources


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XtextLinkingDiagnostic Error while loading xtext model [message #1791012 is a reply to message #1791010] Thu, 21 June 2018 11:50 Go to previous messageGo to next message
Peter Altmayer is currently offline Peter AltmayerFriend
Messages: 7
Registered: April 2018
Junior Member
Thanks very much.
I do not clearly understand, how to do that.
Can you show some lines of code?
Re: XtextLinkingDiagnostic Error while loading xtext model [message #1791019 is a reply to message #1791012] Thu, 21 June 2018 13:20 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12239
Registered: July 2009
Senior Member
Resource resource = resourceSet.getResource(URI.createURI(file.toURI().toString()), true);
Resource resource2 = resourceSet.getResource(URI.createURI(file2.toURI().toString()), true);
Resource resource3 = resourceSet.getResource(URI.createURI(file3.toURI().toString()), true);
Resource resource4 = resourceSet.getResource(URI.createURI(file4.toURI().toString()), true);
Resource resource5 = resourceSet.getResource(URI.createURI(file5.toURI().toString()), true);


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Syntax Error in lambda implementing Xtext quickfixes
Next Topic:Formatting multiple parser rules within curly brackets
Goto Forum:
  


Current Time: Mon Sep 24 23:41:46 GMT 2018

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

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

Back to the top