How to embed new line character in string in xtend? [message #915949] |
Tue, 18 September 2012 05:21  |
Eclipse User |
|
|
|
I am generating a class field in my JvmModelinferrer in xtend:
val exp = NodeModelUtils::getNode(rule.expression);
members+=rule.toField("text",rule.newTypeRef('java.lang.String'))[
^static = true
val Procedure1<ITreeAppendable> b = [
append('''"«exp.text.replace('"','').replaceAll("\n"," \\n ")»"''')
]
initializer = b
setFinal(true)
setVisibility(JvmVisibility::PUBLIC)
]
given that the initial exp.text was
'a
b'
I would like the generated field to look like this:
String text = "a \n b";
but instead it look like this:
String text = "a n b";
where as if I dont replace the newline characters at all then I get:
String text = "a
b";
which of course doesnt compile. The problem seems to be that xtend is evaluating the java string, so even though "\\n" gets compiled to "\n" in java, in xtend it evaluates to "n"
How can I get xtend to not evaluate the \n so that it is preserved in the generated java string?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03578 seconds