Fix text block indentation when the text block has no prefix
The simplest example is this:
public class A {
public void foo() {
String a = """
lorem
ipsum
""";
String b = """
lorem
ipsum
""";
}
}
Both text blocks should be aligned after the formatter pass but a isn't:
public class A {
public void foo() {
String a =
"""
lorem
ipsum
""";
String b =
"""
lorem
ipsum
""";
}
}
I think the StringWrapper used to apply some more logic to actually "deindent" text block strings but that logic isn't needed and is in fact wrong - I added a comment in the patch.
This is currently intentional, although there's some ongoing internal discussion about what the Google Java Style Guide should say about text blocks, and the 'outdenting' behaviour may change.
I think this is the same issue as https://github.com/google/google-java-format/issues/1087#issuecomment-2016582504
Yes, it seems to be the same underlying issue (code condition). I find it hard to understand why text blocks without an indent prefix would have to left without any formatting - this is inconsistent and strange to me. I also think it can lead to destructive formatting changes when used with intellij's plugin (which doesn't apply text block formatting). A subsequent run of the preformatter leaves the code in a different state compared to one run through the formatter. I'd have to come up with an example of this but I'm sure it's possible because I seem to indent those text blocks manually all the time...
I am going to close this out for now. The 'automatic deindent' behaviour is being revisited, and I will update #1087 when that happens.