Open cretz opened 6 years ago
Changing the generated code, so long as it is semantically the same, isn't backwards incompatible. That said, can you use $L instead of $S here?
On Sun, Jan 21, 2018 at 5:32 PM Chad Retz notifications@github.com wrote:
What would be expected when the following is run?
MethodSpec.builder().addComment("Test: $S", "foo\nbar");
Unfortunately this outputs something like:
// Test: "foo\n" "bar"
A bit disappointed and surprising that string literals are always wrapped at newline chars no matter what. Can this change at all? I know that a backwards incompatible break probably won't happen, so another placeholder type?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/javapoet/issues/604, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEcB4vRbHysWufyrGuK5q_wm415yRks5tM7rpgaJpZM4Rl_5k .
@JakeWharton - No, $L
wraps on embedded newline too. I need "normal-string-literal". I hacked this up in Kotlin to solve my temporary needs:
fun doubleQuotedString(string: String?) = CodeBlock.of("\$S", string).let {
// https://github.com/square/javapoet/issues/604 :-(
var str = it.toString()
while (true) {
val endQuoteIndex = str.indexOf("\"\n")
if (endQuoteIndex == -1) break
str = str.substring(0, endQuoteIndex) + str.substring(str.indexOf('+', endQuoteIndex) + 3)
}
str
}
I want to try to sovle this bug
What would be expected when the following is run?
Unfortunately this outputs something like:
A bit disappointed and surprising that string literals are always wrapped at newline chars no matter what. Can this change at all? I know that a backwards incompatible break probably won't happen, so another placeholder type?