Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Easy way to get cross references?
Easy way to get cross references? [message #894484] Mon, 09 July 2012 11:58 Go to next message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Hi everyone,

I am working on the validation of my xtext model. Right now I want to check if "I am an original entity" and if so: I want to check if there are cross references in my actually model which reuse "me" (and check those cross references for identical feature values ...). For better understanding: This could e.g. happen in rules like the following:
Recalculate:
userStates += [SupportedUserState] ...
;

Do I have to iterate through all parts of the model which could contain those cross references and check for identical pointer adresses? Or is their a more easy approach?

I just tried out the method eCrossReferences() because of the name but it seems not to be the right method (the docu isn't that big for this method though)...

I would be greateful for any answer
Hannes

[Updated on: Mon, 09 July 2012 12:11]

Report message to a moderator

Re: Easy way to get cross references? [message #894495 is a reply to message #894484] Mon, 09 July 2012 12:37 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can get all references from the index maintained by the Xtext "all
state" / builder. This is preferred over getting the references as
pointers as this requires a resolution of the resources (you may end up
with all your resources being in memory).

The index tracks all exported and imported elements.

Regards
- henrik

On 2012-09-07 13:58, Hannes Müller wrote:
> Hi everyone,
>
> I am working on the validation of my xtext model. Right now I want to
> check if "I am an original entity" and if so: I want to check if there
> are cross references in my actually model which reuse "me" (and check
> those cross references for identical feature values ...). For better
> understanding: This could e.g. happen in rules like the following:
> Recalculate:
> userStates += [SupportedUserState] ...
> ;
>
> Do I have to iterate through all parts of the model which could contain
> those cross references and check for identical pointer adressses? Or is
> their a more easy approach?
>
> I just tried out the method eCrossReferences() because of the name but
> it seems not to be the right method (the docu isn't that big for this
> method)...
>
> I would be greateful for any answer
> Hannes
Re: Easy way to get cross references? [message #894510 is a reply to message #894484] Mon, 09 July 2012 13:44 Go to previous messageGo to next message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Thx Hendrik for the answer Smile,

Where can I find an example how to use this "all state" / builder? If I google this key words or search in the forum or in the xtext documentation - there are no good hits.

Thx for any answer
Hannes
Re: Easy way to get cross references? [message #894557 is a reply to message #894510] Mon, 09 July 2012 15:14 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-09-07 15:44, Hannes Müller wrote:
> Thx Hendrik for the answer :),
>
> Where can I find an example how to use this "all state" / builder? If I
> google this key words or search in the forum or in the xtext
> documentation - there are no good hits.
>
> Thx for any answer Hannes

It goes something like:

/**
* Access to the global index maintained by Xtext, is made via a
* special (non guice) provider
* that is aware of the context (builder, dirty editors, etc.). It is
* used to obtain the
* index for a particular resource. This special provider is obtained
* here.
*/
@Inject
private org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider
indexProvider;

IResourceDescriptions descriptionIndex =
indexProvider.getResourceDescriptions(scopeDetermeningResource);
IResourceDescription descr =
descriptionIndex.getResourceDescription(scopeDetermeningResource.getURI());

i.e. you will get an instance of IResourceDescriptions that can answer
all sorts of index/resource related questions.

The actual implementation is naturally bound using guice and may be the
"all state" one inside the IDE, or some other provider when using Xtet
stand alone. The logic above stays the same.

The snippet is from the class
org.cloudsmith.geppetto.pp.dsl.linking.PPFinder found in cloudsmith /
geppetto @ github. You may want to look at it to get some inspiration
for how to search for things in the index.

Hope that helps.

- henrik
Re: Easy way to get cross references? [message #894744 is a reply to message #894557] Tue, 10 July 2012 10:48 Go to previous messageGo to next message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Hi Hendrik,

Thanks for the hints Smile. I looked into the file and try to understand what happens their.

Than I copy and pasted the result and tried to debug through it. It is a little bit hard to get to know what to deliver those methods without tutorial. But ok - right now I collect the things which I need by going through the model with eContainer() calls, but I keep this option in mind if I get performance problems.

So thanks again, the thread can be closed
Hannes
Re: Easy way to get cross references? [message #896227 is a reply to message #894744] Tue, 17 July 2012 16:06 Go to previous message
Hannes Müller is currently offline Hannes MüllerFriend
Messages: 24
Registered: June 2012
Junior Member
Hi,

only as update: here is another example how to solve the problem.
http://www.eclipse.org/forums/index.php/mv/msg/261440/754503/#msg_75450

Hannes
Previous Topic:Getting model elements of other file for validation
Next Topic:TMF Generator does not do anything
Goto Forum:
  


Current Time: Fri Apr 19 06:12:56 GMT 2024

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

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

Back to the top