Java: strip trailing whitespace from text-block string template end correctly (IDEA-354777)

GitOrigin-RevId: fa0266faeeaf63b04451b4f068550e22e2cdf8ee
This commit is contained in:
Bas Leijdekkers
2024-06-18 13:01:23 +02:00
committed by intellij-monorepo-bot
parent 19bcdae73f
commit b0b4e53ad2
2 changed files with 22 additions and 0 deletions

View File

@@ -144,6 +144,10 @@ public final class PsiFragmentImpl extends LeafPsiElement implements PsiFragment
}
result.append(c);
}
if (strip == indent) {
int end = result.length();
result.delete(end - indent, end);
}
return result.toString();
}

View File

@@ -27,6 +27,24 @@ public class StringTemplateReverseMigrationInspectionTest extends LightJavaCodeI
}
}""");
}
public void testTrailingWhitespace() {
doTest("""
class TrailingWhitespace {
void foo(String name) {
String s = STR.""\"<caret>
Hello \\{name}
""\";
}
}
""", """
class TrailingWhitespace {
void foo(String name) {
String s = "Hello " + name + "\\n";
}
}
""");
}
public void testOverrideStringProcessor() {
doTest("""