0

How can I execute the same module more that once but keep the previous generated code file?

A short explanation is that I have a main module that calles other modules. generate.mtl

[comment encoding = UTF-8 /]
[module generate('http:///AndroidUI.ecore')/]
[import pje13::androidui::codegeneration::xml_generate /]
[import pje13::androidui::codegeneration::java_generate /]
[import pje13::androidui::codegeneration::xml_strings /]
[template public generate(app : Application)]
[comment @main /]
[for (page : Page | app.page)]
    [for (activity : Activity | app.activity)]
        [if (activity.name.contains(page.name.replace('activity_', '').toUpperFirst()))]
            **[genPage(page, app.name, activity)/]**
        [/if]           
    [/for]  
[/for]
[comment] match between an activity and an layout is:
          MainActivity.java == activity_main.xml [/comment]
[/template]

[template public **genPage**(element:Page, appName:String, activity : Activity)]
[GenerateJava(element,appName,activity)/]
**[GenerateStrings(element)/]**
[GenerateXML(element,activity)/]
[/template]

If I have more than one page, the template [GenerateStrings(element)/] will be called more than once. As the Console output says

!ENTRY org.eclipse.acceleo.engine 2 0 2013-12-24 13:20:09.000
!MESSAGE Some files were generated more than once during this generation.

/res/values/strings.xml : 3 times

So the file will contain only the last modification not all the code from file1 & file2.

When I was searching for a solution I only found Incremental generation using

<%startUserCode>

<%endtUserCode>

or

* @generate NOT

But this is not a solution for an XML file.

The code that I'm ussing to write the xml row is this:

[template public setStrings(button : Button)]
    [if (button.text <> null)]<string name="strings_[button.text.toString()/]">[button.text.toString()/]</string>[else]<string name="const_default">button_text</string>[/if]
[/template] 
4

1 回答 1

1

I guess your GenerateSrings template contains a [file] tag.

If I understand correctly what you're trying to do, you'll have to refactor your acceleo template just a bit, like follows:

[template public generate(app : Application)]
[comment @main /]
[for (page : Page | app.page)]
    [for (activity : Activity | app.activity)]
        [if (activity.name.contains(page.name.replace('activity_', '').toUpperFirst()))]
            [genPage(page, app.name, activity)/]
        [/if]           
    [/for]
[/for]
[app.genStrings()/]
[/template]

[template public **genPage**(element:Page, appName:String, activity : Activity)]
[GenerateJava(element,appName,activity)/]
[comment GenerateStrings(element)/][comment don't do it here/]
[GenerateXML(element,activity)/]
[/template]

[template protected genString(app : Application)]
[file ('...strings.xml', ...)][comment that way, only one file will be generated for the application/]
    [for (page : Page | app.page)]
        [for (activity : Activity | app.activity)]
            [if (activity.name.contains(page.name.replace('activity_', '').toUpperFirst()))]
                [GenerateStrings(element)/]
            [/if]           
        [/for]
    [/for]
[/file]
[/template]
于 2013-12-26T18:38:49.967 回答