Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Get a list of referencing object
Get a list of referencing object [message #908979] Thu, 06 September 2012 06:42 Go to next message
Eclipse UserFriend
I can get a containing object of my current examining object using eContainer() . However, I can't get referencing objects (rules) this way. I tried eCrossReferences(), apparently the returned list has nothing.

How can I get all the referencing objects of a rule?
Re: Get a list of referencing object [message #908999 is a reply to message #908979] Thu, 06 September 2012 07:29 Go to previous messageGo to next message
Eclipse UserFriend
EObject.eCrossReferences gives the outgoing references from the object
to other objects. To find the incoming references you have to visit all
objects in general like what
org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer does.

On 06/09/2012 12:42 PM, Tu Do wrote:
> I can get a containing object of my current examining object using
> eContainer() . However, I can't get referencing objects (rules) this
> way. I tried eCrossReferences(), apparently the returned list has
> nothing.
> How can I get all the referencing objects of a rule?
Re: Get a list of referencing object [message #909474 is a reply to message #908999] Fri, 07 September 2012 03:50 Go to previous messageGo to next message
Eclipse UserFriend
Ed Merks wrote on Thu, 06 September 2012 07:29
EObject.eCrossReferences gives the outgoing references from the object
to other objects. To find the incoming references you have to visit all
objects in general like what
org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer does.

On 06/09/2012 12:42 PM, Tu Do wrote:
> I can get a containing object of my current examining object using
> eContainer() . However, I can't get referencing objects (rules) this
> way. I tried eCrossReferences(), apparently the returned list has
> nothing.
> How can I get all the referencing objects of a rule?

Hi Ed,

How do I use that method? Can you give me an example how the find() and findAll() methods are used? Suppose I'm having rules like this:

VARIABLE:
     'var' name = ID ';'

STRUCT:
      'struct' name = [VARIABLE] ';'


From the access to a VARIABLE object, I want to get access to all STRUCT objects pointing to the VARIABLE object. Note that I only have access to VARIABLE object in my Java code (i.e. in validation method for VARIABLE).
Re: Get a list of referencing object [message #909548 is a reply to message #909474] Fri, 07 September 2012 06:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

do you have cross references only within the same file or do you have cross references to other files as well.
In the first case it is simple. You would navigate through the entire model and check whether "struct" points to the given variable.
The second case is more complicated. The default approach is via the index Xtext creates for all resources. It contains information about objects that can be referred to, but also about actual references in a resource (source and target URI). Basically, you would iterate over the index and check whether those target URIs correspond to the variable's URI.

Could you elaborate on what you are actually trying to achieve (not that you want the referencing objects but why).

Alex
Re: Get a list of referencing object [message #911773 is a reply to message #909548] Wed, 12 September 2012 05:42 Go to previous messageGo to next message
Eclipse UserFriend
Alexander Nittka wrote on Fri, 07 September 2012 06:05
Hi,

do you have cross references only within the same file or do you have cross references to other files as well.
In the first case it is simple. You would navigate through the entire model and check whether "struct" points to the given variable.
The second case is more complicated. The default approach is via the index Xtext creates for all resources. It contains information about objects that can be referred to, but also about actual references in a resource (source and target URI). Basically, you would iterate over the index and check whether those target URIs correspond to the variable's URI.

Could you elaborate on what you are actually trying to achieve (not that you want the referencing objects but why).

Alex

Hi Alex,

Can you give me an example how to iterate through the entire model?

I want the referencing objects to the current object, because I want to collect all relevant information when user hovers on a variable name. i.e. in my example, if the variable is not referenced by any particular "struct", it won't display related information. But if it is being referred, I want to collect all information in "struct", so when a user hovers on a variable name, they can see everything related to a particular variable.

My example is not really perspicuous. In my real use case, the "struct" rule is gonna segmented the referred variable into different sections, each with a specific number of bits for a different purpose based on the predefined length of the currently referred variable.
Re: Get a list of referencing object [message #912537 is a reply to message #911773] Thu, 13 September 2012 14:24 Go to previous message
Eclipse UserFriend
Hi,

from your answer I assume that references are possible only within the same file. In this case you can use Ed's proposed method:

Collection<Setting> references = EcoreUtil.UsageCrossReferencer.find(target, target.eResource());
for (Setting setting : references) {
  EObject source = setting.getEObject();
  //do something with source
}


There are many of ways for iterating over a model. You know the model structure best. Navigate to children (directly following a containment reference), navigate to parents via object.eContainer(), use the utility classes. EcoreUtil and EcoreUtil2 are particularly helpful.

Alex
Previous Topic:Accessing other models during validation
Next Topic:How to hide a root node in outline tree without hiding its children?
Goto Forum:
  


Current Time: Wed Jul 23 18:17:32 EDT 2025

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

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

Back to the top