Search code examples
javafiletagsacceleo

Acceleo file tags


I'm new to Acceleo and I'm trying to figure out some things about the file tags I can use. The format I see most commonly is something like that:

[file (someElement.anotherElement.concat('SomeText.java'), false, 'UTF-8')]

1st Question: How can I write some text first and then the text from some element? e.g. Create a file named "SomeTextElement1.java". Where Element1 is a property(or something) from an .ecore file)

2nd Question: How can I take values from 2 different elements? e.g. Create a file named "Element1-Element2.java". Where Element1 and Element2 taken from an .ecore file.

and 3rd Question: How can I put a file statement inside an [if] statement??? e.g.

[if (condition) /]
[file (Element1.concat('.java'),false, 'UTF-8')]
[else if (condition)]
[file (Element1.concat('.java'),false, 'UTF-8')]
[if/]

I get an error saying file tag is not terminated. But i don't want to terminate it inside the if statement because then i would have to write the same code twice... all i want is to change the filename if a condition is true.. is that possible or not?

Thanks in advance.


Solution

  • You generally don't want to have external "if"s for this. The file name itself is an expression, not a simple string, so you can achieve what you're trying to get with the following:

    [file (if (condition) then 'somename.java' else 'someothername.java' endif, false, 'UTF-8')]
    

    Note that in this case, the "if" structure you'll be using is the OCL "if", so you have to properly use the "if then else endif" structure. if you want multiple conditions, this will then become

    if (condition) then 'somename' else
        if (otherCondition) then 'someothername' else 'yetanothername' endif
    endif