text block newline formatter settings#2936
Merged
jjohnstn merged 4 commits intoeclipse-jdt:masterfrom May 1, 2026
Merged
Conversation
3 tasks
jjohnstn
requested changes
Apr 14, 2026
jjohnstn
reviewed
Apr 17, 2026
Contributor
There was a problem hiding this comment.
Some problems exist. When I format the following code with the new option set in the UI (via your other patch):
package tests
public class TestTextBlockFormatter {
public static void foo() {
final String x = """
abc
def
ghi""";
System.out.println("<" + x + ">");
}
public static void foo2() {
final String str3 = "asd" + """
subd3
ospl
test""" + "osd\n";
System.out.println("<" + str3 + ">");
}
public static void main(String[] args) {
TestTextBlockFormatter.foo();
TestTextBlockFormatter.foo2();
}
}
I sometimes get:
package tests;
public class TestTextBlockFormatter {
public static void foo() {
final String x =
"""
abc
def
ghi\
"""
;
System.out.println("<" + x + ">");
}
public static void foo2() {
final String str3 = "asd" +
"""
subd3
ospl
test\
"""
+ "osd\n";
System.out.println("<" + str3 + ">");
}
public static void main(String[] args) {
TestTextBlockFormatter.foo();
TestTextBlockFormatter.foo2();
}
}
This is wrong for foo2() and matches your test. The closing triple quote where it is means that all the text is indented by 2 tabs when you print it. The foo() case is correct and puts the tripe quote where it should go (matching the start of each text line).
The weird part is that sometimes I get the following without changing any preferences after undoing and re-running format:
package tests;
public class TestTextBlockFormatter {
public static void foo() {
final String x = """
abc
def
ghi\
""";
System.out.println("<" + x + ">");
}
public static void foo2() {
final String str3 = "asd" + """
subd3
ospl
test\
"""
+ "osd\n";
System.out.println("<" + str3 + ">");
}
public static void main(String[] args) {
TestTextBlockFormatter.foo();
TestTextBlockFormatter.foo2();
}
}
As you can see, the foo2() is wrong on the 3rd text block line that got modified. The triple end-quote is correct but it didn't add the newline for the opening triple quotes.
5ff2ac0 to
b7ebd61
Compare
b7ebd61 to
a83eac8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Implement UI part of issue #2731
How to test
Just add some textblock like:
Make sure to enable the new formatter option: `After and before opening and closing a text block"

Author checklist