Search code examples
switch-statementxtend

How to insert variable in a switch statement return with Xtend?


With this Xtend code :

«switch l.name {
case 'java': 'mvn compile..../«d.name»/src/.........'
default: 'bash..../«d.name»/src/......'
}»
and d.name = "Joe"

I want to return this formated String with the inserted variable :

mvn compile..../Joe/src/.........
bash..../Joe/src/.....

and not :

mvn compile..../«d.name»/src/.........
bash..../«d.name»/src/......
PS : case 'java': 'mvn compile..../'«d.name»'/src/.........'
doesn't work

I can't / I don't know how to insert anything into the returned String. Any ideas?


Solution

  • I found the solution :

    «switch l.name {
    case 'java': 'mvn compile..../'+d.name+'/src/.........'
    default: 'bash..../'+d.name+'/src/......'
    }»
    and d.name = Joe
    

    will return as expected :

    mvn compile..../Joe/src/.........
    bash..../Joe/src/.....
    

    So add + to concatenate the different parts of the returned String and as we are inside of «...» don't add «»