Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Remember/derive source location when loading model from xml
Remember/derive source location when loading model from xml [message #1766728] Mon, 26 June 2017 14:36 Go to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 294
Registered: July 2009
Location: Germany
Senior Member
Hi,

short context description:
In our project we have created several Ecore models from XSD files.
Also, we have created ResourceServiceProviders and ResourceDescriptionStrategies to include them in the Xtext index.
Now, we want to validate them as part of Xtext validation, which also works fine so far.

The only thing currently missing is that the error markers are always positioned at line 1 of the XML file. (We want to keep the source editor and do not use the EMF structural editor...)

The reason for the error marker at line 1 is that the Issues do not have line number information associated. This is to expect, because we don't have an Xtext node model attached and EMF itself also cannot derive the source location of an EObject or EStructuralFeature per default.

The question: Is there a Resource loadOption or another mechanism I might have missed to make EMF able to remember (or derive) the line/column for EObjects/EStructuralFeatures (e.g., while loading the resource and parsing the XML)?

Or would I have to implement such a mechanism myself by customizing the XML handler?

Thanks,
Stefan
Re: Remember/derive source location when loading model from xml [message #1766736 is a reply to message #1766728] Mon, 26 June 2017 15:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5586
Registered: July 2009
Senior Member
Hi

I suspect that the problem is that the EObject has got lost when the IMarker gets created, consequently no EObject => line 1.

I had a similar problem; sorry forgot the solution. I contrasted the attributes on sensible Ecore markers with those created by my tooling. EMF's MarkerHelper may give you some clues. Editing an Ecore file to have an ill-formed name should show you how it should be done.

Regards

Ed Willink
Re: Remember/derive source location when loading model from xml [message #1766745 is a reply to message #1766736] Mon, 26 June 2017 16:59 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 294
Registered: July 2009
Location: Germany
Senior Member
Hi Ed,

thank you for your reply. I have spent quite some time searching the EMF code, but haven't found any clue on my particular problem.

The difference with error handling in e.g., Ecore files is that in Ecore, the (structural) validation is performed by the XMLParser as part of the resource loading. The parser creates Exceptions with location information. The EMF Resource part translates those Exceptions to Resource.Diagnostic objects which contain line/column information. This is how "Open Text Editor" in the Ecore Editor error page shows the markers at the correct locations. (MarkerHelper only relies on the location data in the Diagnostic, if there is any).

But: When performing semantic validations (using EValidators), only BasicDiagnostic instances are created which don't carry line information. (The EObject tree does not have any additional information about its source anymore at this point).

I guess I need some way to attach line/column information to EObjects during loading similar to what Xtext does with the node model...

Best,
Stefan
Re: Remember/derive source location when loading model from xml [message #1766753 is a reply to message #1766745] Mon, 26 June 2017 18:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5586
Registered: July 2009
Senior Member
Hi

When I write EObject, I sort of mean the URI, since it is the EcoreUtil.getURI(eObject) that is persisted in the Marker so that when the marker is activated the appropriate editor for the URI is opened and the appropriate EObject for the fragment is located, thereby ensuring that it is displayed nicely. The editor discovers the line numbers.

If you use explicit line numbers you get the stupidites whereby the line numbers from an Xtext editor are re-used when viewing the XML as text.

Regards

Ed Willink
Re: Remember/derive source location when loading model from xml [message #1766801 is a reply to message #1766753] Tue, 27 June 2017 11:42 Go to previous messageGo to next message
L B is currently offline L BFriend
Messages: 1
Registered: June 2017
Junior Member
Hi guys,

I am interested about this topic.

Are there any more information regarding how the line can be retrieved?

Thanks.
Re: Remember/derive source location when loading model from xml [message #1766958 is a reply to message #1766801] Thu, 29 June 2017 06:25 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 29135
Registered: July 2009
Senior Member
No, it's a long standing request, but I've never investigated how best to implement something like that. https://bugs.eclipse.org/bugs/show_bug.cgi?id=196618
Previous Topic:Synchronizing containment and cross reference lists
Next Topic:Remove dangling references
Goto Forum:
  


Current Time: Wed Jan 24 06:04:24 GMT 2018

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

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