Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to override templates
[Acceleo] How to override templates [message #64070] Thu, 09 July 2009 14:49 Go to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,

does there exist an example how to override templates in acceleo? I'm not
that familiar with eclipse plugins, (how) do I need to use the extension
point?

<plugin>
<extension-point id="org.eclipse.acceleo.engine.dynamic.templates"
name="org.eclipse.engine.ui.dynamic.templates"
schema="schema/org.eclipse.acceleo.engine.dynamic.templates.exsd "/>
</plugin>

What I want to achieve: I have a template called "base" in a module "M1".
Now I want to define a template that overrides "base" and resides in
another module "M2".
Do I need name this new template also "base"?
There does not seem to be any runtime type which detemines which template
to be called, so how is it actually determined? I'm not sure if I
understand the News and Noteworthy side right:

"if templates overriding one of the currently evaluated module's templates
are present either in the workspace or installed bundles, they'll be taken
into account instead of said templates for the evaluation."

Does this mean that a overriden template is never executed unless an
overriding template explicitly calls it by "super" keyword?

Thanks in advance!
Robert
Re: [Acceleo] How to override templates [message #64093 is a reply to message #64070] Thu, 09 July 2009 16:08 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1638
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000509050008020809090905
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Hi Robert,

The extension point should only be used if you're overriding module is
contained in a different plugin that the overriden one, and both plugins
are not working together (M1 explicitely calls M2, both plugins are
bundled together, ...). This extension point indicates that another
plugin (either in the workspace or the installed plugin) provides an
override of a given module without having the original generator call
this overriding module explicitely.

If what your trying to do is simply have a module override another, you
only need to tell M2 that it 'extends' M1, and that template
overriding_base 'overrides' base.

----------8<----------
[module M1(<metamodel>)/]

[template public base(arg : <type>)]
[/template]



[module M2(<metamodel>) extends M1/]

[template public base(arg : <type>) overrides base]
[/template]
---------->8----------

Whether this overriding module is 'dynamic' or not, the above is what's
needed. The plugin containing M2 must have a dependency on the module
containing M1. Iff your override is a dynamic override, you need to use
the extension point in addition. The only attribute of this extension
point is the path of the dynamic templates (the more precise it is, the
more efficient; but you can very well tell the overriding modules are in
"/", they'll be sought recursively).

Regards,

Laurent Goubet
Obeo

Robert Walter a
Re: [Acceleo] How to override templates [message #64160 is a reply to message #64093] Fri, 10 July 2009 09:03 Go to previous messageGo to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 11
Registered: July 2009
Junior Member
Hi Laurent,

thank you for your replay, it makes a lot of things clearer for me.
Your proposed solution works.

I have another question regarding multiple inheritance. How is the
generator supposed to handle a module M3 extends both M1 and M2, which
both contain a template called base:

----------8<----------
[module M1(<metamodel>)/]

[template public base(arg : <type>)]
M1
[/template]

[module M2(<metamodel>)/]

[template public base(arg : <type>)]
M2
[/template]


[module M3(<metamodel>) extends M1,M2/]

[template public base(arg : <type>) overrides base]
M3
[/template]
---------->8----------

I tried this and the output in my file is M3. I don't now the
implementation, so is it random which overriding template is selected or
how is the strategy?

Thank you very much!

Robert
Re: [Acceleo] How to override templates [message #64531 is a reply to message #64160] Wed, 15 July 2009 10:16 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1638
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070501080609030404030704
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Robert,

I don't really understand your issue here but with what you listed, in
any module that extends or imports M3 (that is, M3::base() is
accessible), M3.base() will be called insteads of M2::base() and
M1::base(). In any module that does not import or extend M3, the first
accessible template will be called.

----------8<----------
[module M4(<metamodel)]
[import M2]
[import M1]
....
---------->8----------
----------8<----------
[module M5(<metamodel)]
[import M1]
[import M2]
....
---------->8----------

In M4, calling "base" will call M2::base(), in M5, calling "base" will
call M1::base(). Of course if either "base()" has a more specific type
for the passed argument, it will be called instead if the runtime class
of this argument is the most specific ...

Section 8.1.3 of the specification (
http://www.omg.org/spec/MOFM2T/1.0/PDF ), though ambiguous for most
cases, describes the general idea of how we resolve template calls.

Laurent Goubet
Obeo

Robert Walter a
Re: [Acceleo] How to override templates [message #64578 is a reply to message #64531] Thu, 16 July 2009 07:31 Go to previous message
Robert Walter is currently offline Robert WalterFriend
Messages: 11
Registered: July 2009
Junior Member
Got it! Thanks!
Previous Topic:Modifying Content assist, and notifying linking service
Next Topic:[Announce] M2T XPAND 0.7.1 is available
Goto Forum:
  


Current Time: Thu Nov 27 16:22:06 GMT 2014

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

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