Bug 561813 - [2020-03 regression] Strange line-wrap when selection-formatting
Summary: [2020-03 regression] Strange line-wrap when selection-formatting
Status: CLOSED DUPLICATE of bug 560889
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.15   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.16 M1   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-06 07:20 EDT by Atsushi Nakagawa CLA
Modified: 2020-04-13 06:48 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Atsushi Nakagawa CLA 2020-04-06 07:20:47 EDT
Update to version 2020-03 (4.15.0) came down and I've noticed "selection formatting" (Source > Format, with a line selected in the editor) now adds strange line breaks.  This makes Propertes > "Java Editor" > "Save Actions" > "Format source code" > "Format edited lines" mostly unusable.

To demonstrate, here's a bit of formatted code:

```
import java.util.Arrays;
import java.util.Collection;

public class Test {

	public static void main(String[] args) {
		boolean y = Arrays.asList(1, 2).stream()
				.map(Arrays::asList)
				.flatMap(Collection::stream)
				.map(Arrays::asList)
				.filter(x -> true)
				.map(Arrays::asList)
				.anyMatch(x -> true);
	}

}
```

Again, this is already formatted and formatting again does not change anything.  As such, it's expected formatting lines individually should also not change anything.  (And this was the case in version 2019-09.)

However, if I select the 7th line and format, it changes to this:

```
		boolean y = Arrays.asList(1, 2)
				.stream()
```

If I select the top line of this new code and format, it changes further to this:

```
		boolean y = Arrays.asList(1,
				2)
```


If I select the 9th line of the original code and format, it changes to this:

```
				.flatMap(
						Collection::stream)
```

For all other lines, selecting and formatting does not change anything.


# Steps to reproduce

1. Download "Eclipse IDE for Java Developers" (2020-03 R) from https://www.eclipse.org/downloads/packages/
2. Unzip the package and run eclipse
3. Create a new Java Project (I selected JavaSE-1.8)
4. Create Text.java and paste the above code.
5. Open Preferences > Java > Code Style > Formatter > Edit... and enable "Line Wrapping" > "Never join already wrapped lines" then save to a new profile. (This should produce formatting based on "Eclipse [built-in]" which is the minimum required to produce the above code formatting.)
6. Perform Source > Format without selecting any code to ensure nothing changes.
7. Select the `boolean y = Arrays.asList(1, 2).stream()` line and perform Source > Format.
Comment 1 Mateusz Matela CLA 2020-04-13 06:48:45 EDT

*** This bug has been marked as a duplicate of bug 560889 ***