Community
Participate
Working Groups
When using new line and whitespace in SEPARATORS, whitespace is swallowed inside string template. Seems like <pre>org.eclipse.xtend2.lib.StringConcatenation.getSignificantContent()</pre> trims whitespace, unfortunately in some cases that is unexpected by the user. Code snippets below should explain this. - CASE1 and RESULT1 chow xtend code and output it generates. (4 spaces in SEPARATOR after line break) - CASE2 has modifies SEPARATOR, but one would expect same output as RESULT1, but it is different -> indentation from SEPARATOR is swallowed (see RESULT2) - CASE3 adds one non-whitespace character at the end of SEPARATOR, output indentation is fixed (see RESULT3) - CASE4 and CASE5 are the same as CASE2 and CASE3 but they use tab instead of spaces in the SEPARATOR, results are as in RESULT2 and RESULT3 appropriately. CASE1 <code> def CharSequence generateMainLevel(){ val s = "1234"; ''' var mainLevel = {«FOR ch : s.toCharArray SEPARATOR ',\n '»«generateSubLevel(ch)»«ENDFOR»} ''' } def CharSequence generateSubLevel(char data){ '''sublevel_«data»: {value : «data»}''' } </code> RESULT1 <code> var mainLevel = {sublevel_1: {value : 1}, sublevel_2: {value : 2}, sublevel_3: {value : 3}, sublevel_4: {value : 4}} </code> CASE2 <code> def CharSequence generateMainLevel(){ val s = "1234"; ''' var mainLevel = {«FOR ch : s.toCharArray SEPARATOR ''',«"\n"» '''»«generateSubLevel(ch)»«ENDFOR»} ''' } def CharSequence generateSubLevel(char data){ '''sublevel_«data»: {value : «data»}''' } </code> RESULT2 <code> var mainLevel = {sublevel_1: {value : 1}, sublevel_2: {value : 2}, sublevel_3: {value : 3}, sublevel_4: {value : 4}} </code> CASE3 <code> def CharSequence generateMainLevel(){ val s = "1234"; ''' var mainLevel = {«FOR ch : s.toCharArray SEPARATOR ''',«"\n"» _'''»«generateSubLevel(ch)»«ENDFOR»} ''' } def CharSequence generateSubLevel(char data){ '''sublevel_«data»: {value : «data»}''' } </code> RESULT3 <code> var mainLevel = {sublevel_1: {value : 1}, _sublevel_2: {value : 2}, _sublevel_3: {value : 3}, _sublevel_4: {value : 4}} </code> CASE4 <code> def CharSequence generateMainLevel(){ val s = "1234"; ''' var mainLevel = {«FOR ch : s.toCharArray SEPARATOR ''',«"\n"» '''»«generateSubLevel(ch)»«ENDFOR»} ''' } def CharSequence generateSubLevel(char data){ '''sublevel_«data»: {value : «data»}''' } </code> RESULT4 <code> var mainLevel = {sublevel_1: {value : 1}, sublevel_2: {value : 2}, sublevel_3: {value : 3}, sublevel_4: {value : 4}} </code> CASE5 <code> def CharSequence generateMainLevel(){ val s = "1234"; ''' var mainLevel = {«FOR ch : s.toCharArray SEPARATOR ''',«"\n"» _'''»«generateSubLevel(ch)»«ENDFOR»} ''' } def CharSequence generateSubLevel(char data){ '''sublevel_«data»: {value : «data»}''' } </code> RESULT5 <code> var mainLevel = {sublevel_1: {value : 1}, _sublevel_2: {value : 2}, _sublevel_3: {value : 3}, _sublevel_4: {value : 4}} </code>
Created attachment 255650 [details] Code snippets Added attachment with code snippets, things are more clear in editor with no line wrapping and with whitespace displayed.
see also https://github.com/eclipse/xtext-xtend/issues/1092