Skip to main content



      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 11:08 Go to next message
Eclipse UserFriend
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 12:46 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Wed, 06 May 2015 12:47] by Moderator

Re: Cheapest way to traverse a model [message #1694617 is a reply to message #1694602] Wed, 06 May 2015 12:58 Go to previous messageGo to next message
Eclipse UserFriend
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 13:33] by Moderator

Re: Cheapest way to traverse a model [message #1694623 is a reply to message #1694617] Wed, 06 May 2015 13:39 Go to previous messageGo to next message
Eclipse UserFriend
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 13:44 Go to previous message
Eclipse UserFriend
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
Previous Topic:Error with xtext (ui editor)
Next Topic:Multiple possible way to reference
Goto Forum:
  


Current Time: Mon Jul 28 16:40:17 EDT 2025

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

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

Back to the top