Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.2] Question about Xtext's index
[Xtext 2.2] Question about Xtext's index [message #784644] Fri, 27 January 2012 20:31 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

I'm sorry if this question has been answered before. I've been looking everywhere for answers (including Xtext's source code) but I got completely lost Sad

In one of our Xtext-based editors, we'd like to implement a function that takes a QualifiedName (or a String representing a QualifiedName) and open the file containing the EObject associated with that QualifiedName. Something like this:

public class ModelObjectFinder {

  public void openDefinition(QualifiedName qualifiedName) {
    // implementation goes here.
  }
}


I found "org.eclipse.xtext.ui.editor.IURIEditorOpener#open(URI, boolean)" and I think it can be useful for what we are trying to achieve. If this is correct, the key here is to find the URI of the EObject whose QualifiedName matches the one passed to "openDefinition."

Would it be possible to use Xtext's index to find the URI of an EObject, given its QualifiedName? If so, I'd truly appreciate some pointers (I'm not looking for a completely solution, just where to look in Xtext's code.)

Many thanks in advance,
-Alex

[Updated on: Fri, 27 January 2012 20:32]

Report message to a moderator

Re: [Xtext 2.2] Question about Xtext's index [message #784684 is a reply to message #784644] Fri, 27 January 2012 21:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

do you know the existing Open Model Element Diaglog (Crtl + Shift + F3)
the class behind this is called OpenXtextElementHandler.

if you want to find the URI of an EObject with a certain name you can use the index.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext 2.2] Question about Xtext's index [message #784686 is a reply to message #784684] Fri, 27 January 2012 21:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.s:

how to get elements from the index ou can find here: http://www.eclipse.org/forums/index.php/mv/msg/261440/754503/#msg_754503
(using getExportedObjects) and you can ask the IEObjectDescriptions for their EObject URIs


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext 2.2] Question about Xtext's index [message #784691 is a reply to message #784644] Fri, 27 January 2012 22:00 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

normally a qualified name in an Xtext model marks the definition of the object with that name or it is already a reference in which case F3 works out of the box.

If the name is simply some string and not a reference, you might consider inject ResourceDescriptionsProvider retrieve the IResourceDescriptions (i.e. index) for the given context element (where does the qualified name come from) and traverse them in order to find a suitable element with the given name.

The "normal hook" would be to extend HyperlinkHelper#createHyperlinksByOffset. That method will be invoked if the user presses F3 in the editor. What you do is:
-check if it is a location where you want to navigate somewhere (crosslinks are handled that way automatically)
--you inspect semantic/node model if there is a qualified name, use the index to retrieve the corresponding EObjectDescription and hence the URI and create a hyperlink analogously to crosslinks (the EditorOpener is then invoked autmatically)


Another starting point for you (i.e. for inspiration) might be the open model element dialog (shift ctrl F3) which (in a way) already does what you want.
Look at IXtextEObjectSearch and related code in the xtext.ui plugin (package ui.search)

Alex
Re: [Xtext 2.2] Question about Xtext's index [message #786802 is a reply to message #784691] Mon, 30 January 2012 20:48 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Alex & Christian,

Thanks so much for the help! I got it working in no time thanks to you guys Smile

BTW, this is the first time I hear about the "open model element" dialog. Pretty cool and handy!

Cheers,
-Alex
Re: [Xtext 2.2] Question about Xtext's index [message #791980 is a reply to message #786802] Mon, 06 February 2012 13:38 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Here is what I used the Xtext index for: "Sneak preview: Navigating from C++ code to Protocol Buffer declaration in Eclipse" http://goo.gl/SIImQ

Many thanks for your help! Smile
Previous Topic:Strange Parser-Behavior
Next Topic:Xtext 2.3 break Google Protobuf Editor
Goto Forum:
  


Current Time: Tue Apr 16 22:19:11 GMT 2024

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

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

Back to the top