Get a list of referencing object [message #908979] |
Thu, 06 September 2012 06:42  |
Eclipse User |
|
|
|
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 #911773 is a reply to message #909548] |
Wed, 12 September 2012 05:42   |
Eclipse User |
|
|
|
Alexander Nittka wrote on Fri, 07 September 2012 06:05Hi,
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.25407 seconds