eclipseacceleomdaemf

ACCELEO: creating file in path depending on the model structure


In an Acceleo Model to Text transformation I would like to create a file for a UML class coherent with the packages of containing the class (the class namespace in the UML model). The problem I am facing is that I have to do that in line as the [file] command requires it so I am trying something like this

[file ((c.allOwningPackages().name.->sep('/')).concat(c.name.concat('.hpp')),false,'UTF-8')]

but I am getting this error on the concat:

 Cannot find operation (concat(String)) for the type (OclAny)

What is the right way of doing this?


Solution

  • It is not mandatory to do it on the same line as the file block. The two usual ways to accomplish what you are trying to do are to

    For your example, b) would give something of the sort :

    [template public myMainTemplate(c : uml::Class)]
        [file (getpackage(c), false, 'UTF-8')]
            ...
        [/file]
    [/template]
    
    [template private getPackage(c : uml::Class) post(trim())]
        [c.ancestors()->reverse()->sep('/')->including(c.name.concat('.hpp'))/]
    [/template]
    

    Note the use of "->including" instead of ".concat" for collections which is the reason why you had your error message. Of course, this was only to have all inside one single expression. It might be more readable as :

    [template private getPackage(c : uml::Class) post(trim())]
        [c.ancestors()->reverse()->sep('/')/]/[c.name/].hpp
    [/template]