Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to find which Object references another Object?
How to find which Object references another Object? [message #753783] Fri, 28 October 2011 17:42 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

In my grammar I have an object which can references one or more objects of another type. For example

MainObject:
        name=ID
	'List:' '{' member+=Member (',' member+=Member)* '}'
;

Member:
       name=ID


I can create many Member objects in different files, then reference them from a MainObject.

When I do the code generation, I receive a Member object and I need to know which of the MainObjects rerefence it.

I could just simply load all MainObjects and check what I want, but I guess it would be very bad to the memory since I have many, many resources.

How can I do this?

Thanks!
Re: How to find which Object references another Object? [message #753790 is a reply to message #753783] Fri, 28 October 2011 18:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14394
Registered: July 2009
Senior Member
Hi,

guess you can use the index for this.
have a look at IResourceDescription.getReferenceDescriptions()

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to find which Object references another Object? [message #753791 is a reply to message #753783] Fri, 28 October 2011 18:25 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
1) I think you mean to use cross-references here.
2) The strategy to load all MainObjects/resources is already implemented by Xtext's Index infrastructure. It does cost a lot of memory but by using that Index infrastructure you're not wasting more money on it and it's much easier to use that way. The infrastructure is an IDE thing, though, so it might not fit with your current code generation strategy.


Re: How to find which Object references another Object? [message #753797 is a reply to message #753791] Fri, 28 October 2011 19:30 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Yes, I mean cross-references.

I'm not sure if I understood you well. I'm trying to load resource descriptions this way:


		URI uri = URI.createPlatformResourceURI(path, true);
		ResourceSet rs = resourceSetProvider.get(project);
		
		Resource r = rs.getResource(uri, true);
	
		IResourceDescriptions iRD = resourceDescriptionsProvider.getResourceDescriptions(r);
		
		for(IResourceDescription resourceDescription : iRD.getAllResourceDescriptions()) {
			System.out.println(resourceDescription.getReferenceDescriptions()); //Prints an empty set
			Iterable<IReferenceDescription> iRefD = resourceDescription.getReferenceDescriptions();
			for(IReferenceDescription ref:iRefD) {
				System.out.println(ref); //never enters here
			}
		}


It seems that getAllResourceDescriptions() is returning an empty set. I thought I had to load the ReferenceDescription of MainObjects this way.


I'm sorry if I'm doing something silly, this Xtext indexes area is still very unknown for me.

Thanks!
Re: How to find which Object references another Object? [message #753798 is a reply to message #753797] Fri, 28 October 2011 19:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14394
Registered: July 2009
Senior Member
Hi,

in standalone mode the index is built by all resources in the resourceset but you load only one
into the resourceset. maybe you will have to call ecoreutil.resolveall too.

in eclipse mode this should work if you make a clean build before you trigger the stuff.

btw did you change the grammar as meinte suggested?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 28 October 2011 19:42]

Report message to a moderator

Re: How to find which Object references another Object? [message #753799 is a reply to message #753798] Fri, 28 October 2011 19:43 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
I'm executing that code from a Context Menu. I think I have no idea what "standalone" in this xtext context means.

The grammar now uses cross-references.

[Updated on: Fri, 28 October 2011 19:43]

Report message to a moderator

Re: How to find which Object references another Object? [message #753800 is a reply to message #753799] Fri, 28 October 2011 19:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14394
Registered: July 2009
Senior Member
I updated my post. so what is the actual grammar you are using?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to find which Object references another Object? [message #753801 is a reply to message #753800] Fri, 28 October 2011 19:46 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
It would be something like

MainObject:
        name=ID
	'List:' '{' member+=[Member] (',' member+=[Member])* '}'
;

Member:
       name=ID

Re: How to find which Object references another Object? [message #753802 is a reply to message #753801] Fri, 28 October 2011 19:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14394
Registered: July 2009
Senior Member
your grammar wont work. you have no place where you define the members

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to find which Object references another Object? [message #753803 is a reply to message #753802] Fri, 28 October 2011 19:56 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
You are right, I'm sorry. Let's say that at the beginning it has a rule like:

MyObject:
      MainObject | Member
;
.
.
.


My grammar works well with the cross-references, this is just an example I wrote. I'm very sorry for writing it this badly.

I'm generating code from a Context Menu and from a Builder Participant, and either way I have to find the MainObjects referencing a certain Member.

Thank you for your patience.
Re: How to find which Object references another Object? [message #753804 is a reply to message #753802] Fri, 28 October 2011 19:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14394
Registered: July 2009
Senior Member
Btw using the grammar

Model:
	greetings+=Greeting*;

Greeting:
	'Hello' name=ID ('from' from=[Greeting])?'!';


and models

Hello you from me!


Hello me!


works nice for me

please note: this will not work for local refs


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 28 October 2011 19:57]

Report message to a moderator

Re: How to find which Object references another Object? [message #753806 is a reply to message #753804] Fri, 28 October 2011 20:05 Go to previous message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Got it! I didn't know I had to do a "clean" before using the Context Menu for the cross-references to work. T_T

Thank you so much, guys!
Previous Topic:Storage2UriMapper confuses non-jar plugins with external folders
Next Topic:scope problem
Goto Forum:
  


Current Time: Fri Dec 02 01:03:32 GMT 2022

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

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

Back to the top