| [Acceleo] How to override templates [message #64070] | 
Thu, 09 July 2009 10:49   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 12:08    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #64531 is a reply to message #64160] | 
Wed, 15 July 2009 06:16    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 
 |  
 |  
  | 
 | 
Powered by 
FUDForum. Page generated in 0.11290 seconds