[xtend2] Implicit Rich String Concatenation for Code Generation [message #758236] |
Tue, 22 November 2011 12:10 |
Christian Motika Messages: 11 Registered: July 2009 |
Junior Member |
|
|
Is there a better way to use Xtend2 for code generation and have something like the implicit string concatenation to reduce the 'noise' of appending everything together?
More specifically, is there a more elegant way to code the following:
def dispatch outputFunctions(Output it, String moduleName) {
var gen = '''''';
gen.newLine();
for (signal : signals) {
gen.append('''«moduleName»_O_«signal.name»(''');
if (signal.type == "int") {
gen.append('''int i''');
}
gen.append('''){
value = cJSON_CreateObject();
cJSON_AddTrueToObject(value, "present");''')
if (signal.type == "int") {
gen.newLine();
gen.append('''cJSON_AddNumberToObject(value, "value", i);''')
}
gen.append('''cJSON_AddItemToObject(output, "«signal.name»", value);}''')
gen.newLine();
}
gen;
}
It would be really more readable if Strings can be concatenated implicitly like this :
def dispatch outputFunctionsWithImplicitStringConcatenation(Output it, String moduleName) {
for (signal : signals) {
'''«moduleName»_O_«signal.name»(''';
if (signal.type == "int") {
'''int i''';
}
'''){
value = cJSON_CreateObject();
cJSON_AddTrueToObject(value, "present");'''
if (signal.type == "int") {
'''cJSON_AddNumberToObject(value, "value", i);'''
}
'''cJSON_AddItemToObject(output, "«signal.name»", value);}'''
}
}
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04126 seconds