Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How cross-reference is found by Xtext?(comparison of qualified names)
How cross-reference is found by Xtext? [message #714863] Thu, 11 August 2011 16:20 Go to next message
alex.ren2006 is currently offline alex.ren2006Friend
Messages: 46
Registered: June 2011
Member
I am currently building an IDE for ATS (www.ats-lang.org). I get into some trouble in dealing with cross-reference. The following is my guess of the mechanism of cross-reference in Xtext. Please correct me if I am wrong. Then I may stand a better chance to solve the problem I am facing now.

In my mwe2 file, I use the default "fragment = exporting.QualifiedNamesFragment {}". So I think Xtext actually finds the reference by comparison of names.

Once I Ctrl-Click on certain element of the source code, Xtext will
1. get the full name of the element such as scope01.scope02.obja.
2. get the scope of the element (the scope may contain nested scope).
3. compare the name of the element (scope01.scope02.obja) to the names of the objects in the scope. The comparison appears in the following steps
1) try to find the ojbect with name "scope01.scope02.obja". If it failed, then go to step 2), else that's the reference we need.
2) try to find the object with name "scope1.obja". If it failed, then go to step 3), else that's the reference we need.
3) try to find the object with name "obja". If it failed, then reports that no reference is found, else that's the reference we need.

Is my guess correct? Can anyone point to me which part of Xtext code is for looking up cross-reference? (Is there any design document which can assist me to read the Xtext source code?) Thanks a lot for your advice in advance.

[Updated on: Thu, 11 August 2011 16:20]

Report message to a moderator

Re: How cross-reference is found by Xtext? [message #714908 is a reply to message #714863] Thu, 11 August 2011 18:13 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there is the Xtext documentation, several blog entries by the Xtext developers, many threads in this forum. Also, I started working on a series of blog entries on cross referencing in Xtext. Scopes and and qualified names are related but not identical. The qualified name is composed based on the names in the containment hierarchy of the element.

If you do Ctrl-Click all the work (the linking) has already been done, i.e. the linked object is already known (URI) and can be opened. The fun part happens before. The essential part is the scoping. Basically the scope provides a lookup mechanism for visible elements mapping names (simple or qualified, with/without imports) to the corresponding object(description)s.

Step 1 is "incorrect" already. If you have a cross reference, Xtext will not restore the full name, but rather search the scope for exactly that name (possibly taking name space imports into account). An object may be contained in the nested scope under several names.

Take the standard entity example. An entity X has attributes att1, att2. Within that entity the attributes are visible via their simple names (att1, att2) and due to the outer scope via their long names (X.att1, X.att2) as well. Outside that entity, they are visible via their long names.

It is easiest to help, when you tell exactly what the problem is (here is my grammar, here is a sample of the model where linking does not work as expected, I get the following error message - I don't understand it/I understand it but do not know what to do about it).
Try out the concept in a toy project first. This will help you concentrate on the actual problem. Maybe it is a grammar problem, maybe a naming problem, maybe an import problem or you really need to adapt the scope provider.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: How cross-reference is found by Xtext? [message #715047 is a reply to message #714908] Fri, 12 August 2011 08:32 Go to previous message
alex.ren2006 is currently offline alex.ren2006Friend
Messages: 46
Registered: June 2011
Member
Thank you so much for you answer. I had a post (In the post, I want to create names for nameless containers to enable cross-reference.) previously (http://www.eclipse.org/forums/index.php/m/708526/#msg_708526), in which I provided an unsuccessful solution based on my incorrect understanding of the mechanism of cross-reference. Maybe the code I posted is a little bit too over, so I didn't get any answer at all. If possible, could you please have a look of the problem (forget about the code I posted) and shed some clue what's the appropriate way to handle it based on your experience? Thanks a lot.
Previous Topic:Re: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/ui/
Next Topic:Bug in Mwe2ExecutionEngine?
Goto Forum:
  


Current Time: Sun Apr 11 17:13:50 GMT 2021

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

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

Back to the top