Skip to content

text block newline formatter settings#2936

Merged
jjohnstn merged 4 commits intoeclipse-jdt:masterfrom
inuyasha82:2731_newline_formatter
May 1, 2026
Merged

text block newline formatter settings#2936
jjohnstn merged 4 commits intoeclipse-jdt:masterfrom
inuyasha82:2731_newline_formatter

Conversation

@inuyasha82
Copy link
Copy Markdown
Contributor

What it does

Implement UI part of issue #2731

How to test

Just add some textblock like:

		String str3 = "asd" + """
				subd3
				ospl
				test""" + "osd\n";		

Make sure to enable the new formatter option: `After and before opening and closing a text block"
image

Author checklist

@inuyasha82 inuyasha82 marked this pull request as ready for review April 16, 2026 16:13
@jjohnstn jjohnstn changed the title [DRAFT] 2731 newline formatter text block newline formatter settings Apr 17, 2026
Copy link
Copy Markdown
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jjohnstn jjohnstn force-pushed the 2731_newline_formatter branch from 5ff2ac0 to b7ebd61 Compare April 23, 2026 19:07
@jjohnstn jjohnstn force-pushed the 2731_newline_formatter branch from b7ebd61 to a83eac8 Compare May 1, 2026 14:51
Copy link
Copy Markdown
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks.

@jjohnstn jjohnstn merged commit 4c04af3 into eclipse-jdt:master May 1, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants