[Acceleo] OO-semantics of templates [message #823543] |
Sun, 18 March 2012 13:31  |
Gregor Bonifer Messages: 7 Registered: May 2011 |
Junior Member |
|
|
Hi,
I stumbled upon the following behavior:
My idea was to seperate the traversal of a model from the creation of textual artifacts. The intention behind this is that a general strategy for walking a model may be used to create different kinds of textual representation that have a common structure.
First, I created a module walkInheritanceHierarchie with public templates walkPackage(pack : EPackage), walkRootClass(eClass : EClass, pack : EPackage) and walkSubClass(eClass : EClass, pack : EPackage):
- walkPackage calls walkRootClass for every EClass that doesn't have a superClass inside the package.
- walkRootClass calls walkSubClass for every direct subClass of the given class.
- walkSubClass calls itself for every direct subClass of the given class.
Now I wanted to create a simple xml-document reflecting the inheritance structure. So, I created a module renderHierarchieXML that extends walkInheritanceHierarchie.
I defined overriding templates for all three templates. Each template generates some text and calls [super/].
Now it seems that [super/]-call just delegates to the superTemplate which is then executed as if it was executed standalone. I would have expected that the template walkPackage calls the overriding version of walkRootClass, but instead it calls the overridden version from its own module. This means that the namespace used for the execution of super-calls does not respect the calling context. walkPackage seems to be unaware that it should not call walkRootClass from its own module, but the overriding template from the extending module.
Therefore the behavior does not resemble OO inheritance semantics.
What am I doing wrong? Did I misunderstand the concept behind the extending- and overriding-mechanism?
Regards,
Gregor Bonifer
|
|
|
Re: [Acceleo] OO-semantics of templates [message #824071 is a reply to message #823543] |
Mon, 19 March 2012 08:11   |
Ed Willink Messages: 7637 Registered: July 2009 |
Senior Member |
|
|
Hi Gregor
Acceleo is an implementation of most of the OMG MOFM2T 1.0
specification, which is a bit vague as to which module/template/query
concepts have namespace and which have class semantics. You are in good
company in observing a lack of reasonable polymorphism.
It is not entirely surprising that a 1.0 specification can be improved.
I hope that Obeo will start moving towards a 1.1 or 2.0 specifcation.
Regards
Ed Willink
On 18/03/2012 13:31, Gregor Bonifer wrote:
> Hi,
>
> I stumbled upon the following behavior: My idea was to seperate the
> traversal of a model from the creation of textual artifacts. The
> intention behind this is that a general strategy for walking a model
> may be used to create different kinds of textual representation that
> have a common structure.
> First, I created a module walkInheritanceHierarchie with public
> templates walkPackage(pack : EPackage), walkRootClass(eClass : EClass,
> pack : EPackage) and walkSubClass(eClass : EClass, pack : EPackage):
> - walkPackage calls walkRootClass for every EClass that doesn't have a
> superClass inside the package. - walkRootClass calls walkSubClass for
> every direct subClass of the given class.
> - walkSubClass calls itself for every direct subClass of the given class.
>
> Now I wanted to create a simple xml-document reflecting the
> inheritance structure. So, I created a module renderHierarchieXML that
> extends walkInheritanceHierarchie.
> I defined overriding templates for all three templates. Each template
> generates some text and calls [super/].
>
> Now it seems that [super/]-call just delegates to the superTemplate
> which is then executed as if it was executed standalone. I would have
> expected that the template walkPackage calls the overriding version of
> walkRootClass, but instead it calls the overridden version from its
> own module. This means that the namespace used for the execution of
> super-calls does not respect the calling context. walkPackage seems to
> be unaware that it should not call walkRootClass from its own module,
> but the overriding template from the extending module.
> Therefore the behavior does not resemble OO inheritance semantics.
> What am I doing wrong? Did I misunderstand the concept behind the
> extending- and overriding-mechanism?
>
> Regards,
> Gregor Bonifer
|
|
|
|
Powered by
FUDForum. Page generated in 0.02069 seconds