Cheapest way to traverse a model [message #1694602] |
Wed, 06 May 2015 15:08 |
Alexander R 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 |
|
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 |
Alexander R 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04045 seconds