|Re: [Acceleo] In search of a clean solution for namespace/block generation [message #632229 is a reply to message #632220]
||Tue, 12 October 2010 08:26
| Laurent Goubet
Registered: July 2009
You won't be able to have a perfect indentation in both generated code and template, you'll have to make compromises .
The best way of handling this problem is if your namespaces and "baseclass" are of two different kind. For example if your namespaces are "EPackage"s and baseclass are "EClass"es, you could then use code like this :
[template public generate(element : EObject)]
[comment this will not generate anything/]
[template public generate(pack : EPackage)]
[template public generate(class : EClass)]
The three templates share the same name, so Acceleo will check the actual runtime type of the parameter in order to know which it should call. As you start your generation from the namespace (package "N1"), it will first generate the "namespace N1" part, then as it goes down the content encountering more packages or classes, generate the remainder. As soon as we find anything than a package or class, the placeholder "generate(EObject)" will be called and won't generate a thing.
There are more than a single way to do this, you could also iterate over the result of "baseClass.ancestors(EPackage)->reverse()" and generate all namespaces at once from this list ... You'll have to experiment to see which you prefer.
Powered by FUDForum
. Page generated in 0.12188 seconds