Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cheapest way to traverse a model(Building inner scope)
Cheapest way to traverse a model [message #1694602] Wed, 06 May 2015 15:08 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi all,

I've calculated my local-scope inside of modelled operations with recursive dispatched methods by traversion the eContainer-reference.

This works like this:

def dispatch IScope defBefore(LocalVar var, EObject o){
val scopeList = newArrayList().add(var)
//walk upwards
Scopes::scopeFor(scopeList, var.eContainer.defBefore(o) )
    }

def dispatch IScope defBefore(EObject obj, o){
Scopes::scopeFor(scopeList, obj.eContainer.defBefore(o) )
}

def dispatch IScope defBefore(Operation op, EObject o){
val scopeList = op.params
// end of recursion
Scopes::scopeFor(scopeList)
    }


Now I recognized that I need some more elements in my scope, which are outside of operations ( for ex. Datatypes). I thought about adding an other dispatched rule, which walks until the root-element and then call the:

Scopes::scopeFor(EcoreUtil2.getAllContentsOfType(modelRoot, typeof(Datatype)))


But I'm not sure how expensive this operation will be for me, cause the scope (lokal) is build after every model-change...

Some advices would be great!

~Alex
Re: Cheapest way to traverse a model [message #1694615 is a reply to message #1694602] Wed, 06 May 2015 16:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, this depends on the structure of you model.
since EcoreUtil2.getAllContentsOfType searches all branches it may loose a lot of performance if there are any side branches that never contain Datatype.

depending on your usecase you may simply call delegateGetScope to relay on the default scoping mechanism

p.S: i'd not worry too much on performance (if you stay locally to the resource)
and generally: it always helps to actually measure



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 06 May 2015 16:47]

Report message to a moderator

Re: Cheapest way to traverse a model [message #1694617 is a reply to message #1694602] Wed, 06 May 2015 16:58 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

The structur shouldn't be too complex:

root
      ----packages
              ----Classifier (class, datatype)
                     ----props + ops


I will try out delegateGetScope as well, maybe it will do the job.

Maybe I should grab all classifiers first and then filter for datatypes:

val classifierList = EcoreUtil2.getAllContentsOfType(mod, typeof(Classifier))  
val datatypeList= classifierList.filter[el  | el  instanceof Datatype]


Thanks

Alex

[Updated on: Wed, 06 May 2015 17:33]

Report message to a moderator

Re: Cheapest way to traverse a model [message #1694623 is a reply to message #1694617] Wed, 06 May 2015 17:39 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Just found some strange behavior:
If I add the additional elements to the scope like this:

Scopes::scopeFor(EcoreUtil2.getAllContentsOfType(modelRoot, typeof(Datatype)))


And then try to import a (external) DSL-file with datatypes into my model (where these datatypes are used), these imported datatypes are still not accessible.
Why is this so? Do I have to calculate so IEObjectDescription for the Elements I'm adding to the scope?

~Alex

Re: Cheapest way to traverse a model [message #1694625 is a reply to message #1694623] Wed, 06 May 2015 17:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

if you build a scope manually, you have to include (as parent scope) delegateGetScope(ctx,ref).
otherwise you will only get these elements you explicitely put into the scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Error with xtext (ui editor)
Next Topic:Multiple possible way to reference
Goto Forum:
  


Current Time: Tue Apr 16 23:42:47 GMT 2024

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

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

Back to the top