Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Find References in Xtext 2 problem
Find References in Xtext 2 problem [message #690993] Thu, 30 June 2011 14:14 Go to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hello everyone,

I am currently working with Xtext 2 and Eclipse Indigo and I'm implementing an Xtext editor, which has a special functionality - the user can make an OCL query on the content of the Xtext editor. OCL is not important right now, just imagine you have a content, make a query and get a result back.

Example:

The content of the .mydsl file is

myElement elem1 ()

myElement elem2 (
    uses elem1
)


and an OCL query, which returns the name of the currently selected (TextSelection!) myElement would be something like

self.name()


The result of this OCL query is displayed in the OCL Console like

Evaluating:
self.name
Results:
'A1'


if the user previously selects the element A1 in the Xtext editor.

OCL queries are made in the "Interactive Xtext OCL" console. Okay, I already implemented this part, where I determine which EObject in the AST is currently selected in the Xtext editor. When the user hits Enter, the OCL query is evaluated and I get a Collection<EObject> back. So far, everything works properly.

And here comes my first problem. I want to take this collection with the results and display these results in the Search View, like I would do a regular search (although I don't want to search anything). My problem is theoretically easier, since I don't have to search anything - I already have the results which I simply want to display in the Search View of Eclipse.

Now, the problem is I cannot simply fill the Search View with the contents of the collection I have, since I have to follow a strict pattern if I want to customize the Search View. I need to create several different objects, like: XXXQuery, XXXSearchResult, XXXSearchResultPage and many more. I do not need some of these, since I don't want to make any search query. I want to jump over all the standard steps of making a query, running the query, collecting the results and then display them. Having the collection of EObjects, I just want to display them in the Search View. That's all!

Well, I tried using the mentioned classes, but it did not work. So I thought to myself I take a look in the Xtext source code, to see how the "Find References" functionality of Xtext 2 is implemented. There, I found the class FindReferencesHandler and tried to overwrite it, in order to adapt it's behaviour to meet my needs. That did not work, because I constantly got NullPointerExceptions. After debugging I learned that the FindReferencesHandler class maybe should not be even overwritten. Or it is not intended to be used like I'm trying. I don't know.

Or, maybe I'm wrong. It would be really helpful if anyone could give me a hint how to achieve my goal. Simply iterate through an existing collection and display each EObject element in the Search View of Eclipse.

If I try instantiatig the FindReferencesHandler and then call the execute() method, I get a lot of NullPointerExceptions. I managed to isolate some of them, but the more deeper I dig in the structure of the Find References mechanism, the more objects I find, which are null - which cause the NullPointerException to be thrown.

Any hints/ideas?

I'm using Xtext 2.0.0.v201106070531 and Eclipse Indigo Release build id: 20110615-0604.

Thanks in advance.
Re: Find References in Xtext 2 problem [message #691033 is a reply to message #690993] Thu, 30 June 2011 15:18 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Darie,

each of Xtext default implementations should be instantiated by means of
google guice. The dependencies are injected by the framework if you do
it properly so you won't see these NPEs.
Please note that the find references displays not the actual EObjects
but descriptions which are sort of a snapshot. The Xtext editor will
constantly unload objects and recreate them as you type. You may not
refer to any instance from outside of an IUnitOfWork.

I strongly recommend to have a look at the Xtext documentation to get
familiar with the different patterns and approaches.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 30.06.11 16:14, Darie wrote:
> Hello everyone,
>
> I am currently working with Xtext 2 and Eclipse Indigo and I'm
> implementing an Xtext editor, which has a special functionality - the
> user can make an OCL query on the content of the Xtext editor. OCL is
> not important right now, just imagine you have a content, make a query
> and get a result back.
>
> Example:
>
> The content of the .mydsl file is
>
> myElement elem1 ()
>
> myElement elem2 (
> uses elem1
> )
>
> and an OCL query, which returns the name of the currently selected
> (TextSelection!) myElement would be something like
>
> self.name()
>
> The result of this OCL query is displayed in the OCL Console like
>
> Evaluating:
> self.name
> Results:
> 'A1'
>
> if the user previously selects the element A1 in the Xtext editor.
>
> OCL queries are made in the "Interactive Xtext OCL" console. Okay, I
> already implemented this part, where I determine which EObject in the
> AST is currently selected in the Xtext editor. When the user hits Enter,
> the OCL query is evaluated and I get a Collection<EObject> back. So far,
> everything works properly.
>
> And here comes my first problem. I want to take this collection with the
> results and display these results in the Search View, like I would do a
> regular search (although I don't want to search anything). My problem is
> theoretically easier, since I don't have to search anything - I already
> have the results which I simply want to display in the Search View of
> Eclipse.
>
> Now, the problem is I cannot simply fill the Search View with the
> contents of the collection I have, since I have to follow a strict
> pattern if I want to customize the Search View. I need to create several
> different objects, like: XXXQuery, XXXSearchResult, XXXSearchResultPage
> and many more. I do not need some of these, since I don't want to make
> any search query. I want to jump over all the standard steps of making a
> query, running the query, collecting the results and then display them.
> Having the collection of EObjects, I just want to display them in the
> Search View. That's all!
>
> Well, I tried using the mentioned classes, but it did not work. So I
> thought to myself I take a look in the Xtext source code, to see how the
> "Find References" functionality of Xtext 2 is implemented. There, I
> found the class FindReferencesHandler and tried to overwrite it, in
> order to adapt it's behaviour to meet my needs. That did not work,
> because I constantly got NullPointerExceptions. After debugging I
> learned that the FindReferencesHandler class maybe should not be even
> overwritten. Or it is not intended to be used like I'm trying. I don't
> know.
>
> Or, maybe I'm wrong. It would be really helpful if anyone could give me
> a hint how to achieve my goal. Simply iterate through an existing
> collection and display each EObject element in the Search View of Eclipse.
>
> If I try instantiatig the FindReferencesHandler and then call the
> execute() method, I get a lot of NullPointerExceptions. I managed to
> isolate some of them, but the more deeper I dig in the structure of the
> Find References mechanism, the more objects I find, which are null -
> which cause the NullPointerException to be thrown.
>
> Any hints/ideas?
>
> I'm using Xtext 2.0.0.v201106070531 and Eclipse Indigo Release build id:
> 20110615-0604.
>
> Thanks in advance.
>
Previous Topic:XtextReconcilerJob
Next Topic:UNTIL token question
Goto Forum:
  


Current Time: Sat Sep 19 13:33:23 GMT 2020

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

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

Back to the top