Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get all EObjects of a Type
Get all EObjects of a Type [message #1100681] Tue, 03 September 2013 12:43 Go to next message
kamo cuvao is currently offline kamo cuvaoFriend
Messages: 11
Registered: July 2013
Junior Member
Hello!

In my grammar I have global variables:

VariableDefinition: (isGlobal?="GLOBAL")? name=ID ':' type=VarType ';';


and a reference:

VariableRef: { VariableRef }
    reference=[VariableDefinition]
;



Now I want to write a (declarative) Scope for my reference:

def scope_ VariableRef _reference(Model m, EReference ref){
	<...do local scoping stuff...>
	return Scopes::scopeFor(<???allGlobalVariables???>)
}


I just can't figure out, how I can get all (global) objects and not just the ones from my resource. (It should also run fast because I have a project with ~500.000 lines of code.)

Thanks for your answers,
Martin
Re: Get all EObjects of a Type [message #1100691 is a reply to message #1100681] Tue, 03 September 2013 12:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the easiest is ( i think so) to store the gobality intoformation in the xtext index
(therefore customize DefaultResourceDescriptionStrategy and add a token to the userdata of the IEObjectDescription)
then filter delegateGetScope(ctx,ref) on EObjectDescriptions that have this flag.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get all EObjects of a Type [message #1101277 is a reply to message #1100681] Wed, 04 September 2013 08:41 Go to previous messageGo to next message
kamo cuvao is currently offline kamo cuvaoFriend
Messages: 11
Registered: July 2013
Junior Member
Thank you Christian for your quick response and the direction you gave me. My Program now works wonderful.

For all the ones who are interested how I made it:

This really helped me out: www.eclipse.org/forums/index.php/mv/msg/361362/885861/#msg_885861

I used the whole inherit code, because first of all I needed it and secondly it provides this nice SimpleName --> QualifiedName mechanism.

For my global variables I just added a Flag in the createEObjectDescriptions of MyDslDefaultResourceDescriptionStrategy

if(eObject instanceof VariableDefinition){
	Map<String, String> userData = Maps.newHashMap();
	Model model = EcoreUtil2.getContainerOfType(eObject, Model.class);
	userData.put("model", model.getName());
	if(((VariableBlock)(eObject)).isIsGlobal()){   //flag is here
		userData.put("isGlobal", "true");
	}
	return createEOD(eObject, acceptor, userData);
}


and in my Scope provider I grabbed all Variables with the flag (and the inherited ones):

def scope_AssignRef_reference(Model m, EReference ref){
	val allModels = getAllModels(m);
	return new FilteringScope(delegateGetScope(m, ref), [ieod | 
		(ieod.getUserData("model") != null && allModels.contains(ieod.getUserData("model"))) ||
		(ieod.getUserData("isGlobal") != null && ieod.getUserData("isGlobal").equals("true"))
	]);
}

[Updated on: Wed, 04 September 2013 08:45]

Report message to a moderator

Re: Get all EObjects of a Type [message #1101394 is a reply to message #1101277] Wed, 04 September 2013 12:00 Go to previous messageGo to next message
kamo cuvao is currently offline kamo cuvaoFriend
Messages: 11
Registered: July 2013
Junior Member
Do you have an idea, how tho speed the "Updating resource description for..." up? With my big project the build needs about 10 minutes to complete, which is unacceptable.

[Updated on: Wed, 04 September 2013 12:02]

Report message to a moderator

Re: Get all EObjects of a Type [message #1102128 is a reply to message #1100681] Thu, 05 September 2013 11:59 Go to previous messageGo to next message
kamo cuvao is currently offline kamo cuvaoFriend
Messages: 11
Registered: July 2013
Junior Member
Hello again,

I think your example in
www.eclipse.org/forums/index.php/mv/msg/361362/885861/
has a performance problem.

When I'm using the
Set<String> getAllModels(Content context)
function I get a performance problem:

http://i40.tinypic.com/10pttew.png
http://i40.tinypic.com/300r6ev.jpg

Over 400MB of Iterators are created and deleted the whole time. (I think each time a reference is checked.)

Maybe it's not the best idea to go through the whole node list to find inherited variables each time a reference is resolved?

Maybe it is possible to write a GlobalScopeProvider which supports inheritance? I searched for one but I didn't find one.

So to recap, I need a ScopeProvider which can handle inheritance and global variables.

Thx for answers,
Martin
Re: Get all EObjects of a Type [message #1102135 is a reply to message #1102128] Thu, 05 September 2013 12:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

hi i am not sure what you are talking about/what you are actually doing.
it is your choice on how you solve that.

using the filteirng scope you should not collect that may iterators/stuff since all is done lazy.
adding all to a set (uniqueness problem) may be much more expensive
but this depends on your usecase.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:View Toolbar
Next Topic:Disable Builder/Generator
Goto Forum:
  


Current Time: Thu Apr 18 18:13:55 GMT 2024

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

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

Back to the top