|
|
|
|
Re: Get a list of referencing object [message #911773 is a reply to message #909548] |
Wed, 12 September 2012 09:42 |
Tu Do Messages: 21 Registered: August 2012 |
Junior Member |
|
|
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 18:24 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
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
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
|
|
|
Powered by
FUDForum. Page generated in 0.03641 seconds