[java-inspections] TextBlockMigration: properly escape ending space

GitOrigin-RevId: 8cbd99ecf3b4b9c068e30317e930eae150a007d9
This commit is contained in:
Tagir Valeev
2022-09-29 12:58:36 +00:00
committed by intellij-monorepo-bot
parent 29e0987c94
commit 26aea361f0
6 changed files with 52 additions and 2 deletions
@@ -142,7 +142,11 @@ public class TextBlockMigrationInspection extends AbstractBaseJavaLocalInspectio
// append \ + newline at the end of the last line, so we can use closing """ to indent
lines[lines.length - 1] += "\\\n";
}
return "\"\"\"\n" + StringUtil.join(lines) + "\"\"\"";
String content = StringUtil.join(lines);
if (content.endsWith(" ")) {
content = content.substring(0, content.length() - 1) + "\\s";
}
return "\"\"\"\n" + content + "\"\"\"";
}
private static String @Nullable [] getContentLines(PsiExpression @NotNull [] operands) {
@@ -7,7 +7,7 @@ class TextBlockMigration {
<html> \s
<body>
</body>
</html> """;
</html> \s""";
}
}
@@ -0,0 +1,12 @@
// "Replace with text block" "true-preview"
class TextBlockMigration {
void spaces() {
String foobarbaz = """
foo
bar \s
baz \s""";
}
}
@@ -0,0 +1,12 @@
// "Replace with text block" "true-preview"
class TextBlockMigration {
void spaces() {
String foobarbaz = """
foo
bar
\s""";
}
}
@@ -0,0 +1,11 @@
// "Replace with text block" "true-preview"
class TextBlockMigration {
void spaces() {
String foobarbaz = "foo<caret>\n" +
"bar \n" +
"baz ";
}
}
@@ -0,0 +1,11 @@
// "Replace with text block" "true-preview"
class TextBlockMigration {
void spaces() {
String foobarbaz = "foo<caret>\n" +
"bar\n" +
" ";
}
}