eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

Cleanup with enabled Formatting produces Code which does not adhere to the configured Formatting rules

Open
#2,427 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
1d 8h
Merged PRs (30d)
37

Description

Steps to Reproduce:

1. Create Foo.java with the following content. Note the empty lines.
```java
package dummy;

public class Foo {
public boolean bar(Foo f1, Foo f2) {
if (f1.someSuperSuperSuperLongMethodName()) {
return true;
}




if (f2.someSuperSuperSuperLongMethodName()) {
return true;
}
if (f2.someSuperSuperSuperLongMethodName()) {
return true;
}
return false;
}

private boolean someSuperSuperSuperLongMethodName() {
return true;
}
}

```
2. Open Preferences > Code Style > Clean Up
3. Edit the built-in Profile and enable Code Organizing > Formatter > Format source code
4. Choose a different name for the Profile to save it
5. Right click on Foo.java > Source > Clean up...
6. Make sure the modified Profile is selected
7. Click Finish
8. Foo.java now looks like the following. Note that the empty lines have been removed, presumably by the formatter, but the joined if clause is longer than the permitted default 120 char line length.
```java
package dummy;

public class Foo {
public boolean bar(Foo f1, Foo f2) {
if (f1.someSuperSuperSuperLongMethodName() || f2.someSuperSuperSuperLongMethodName() || f2.someSuperSuperSuperLongMethodName()) {
return true;
}
return false;
}

private boolean someSuperSuperSuperLongMethodName() {
return true;
}
}
```
9. Right click on Foo.java and select Source > Format
10. Foo.java now correctly looks like this:
```java
package dummy;

public class Foo {
public boolean bar(Foo f1, Foo f2) {
if (f1.someSuperSuperSuperLongMethodName() || f2.someSuperSuperSuperLongMethodName()
|| f2.someSuperSuperSuperLongMethodName()) {
return true;
}
return false;
}

private boolean someSuperSuperSuperLongMethodName() {
return true;
}
}
```

Unless I'm missing something, I would expect that the Clean Up operation already produces correctly formatted code, when the "Format source code" option is activated.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the difference between Clean Up with the enabled Formatter option and Source > Format using the Foo.java example. Compare the cleanup formatter path with the standalone formatting result, and consider the issue complete when Clean Up respects the configured 120-character line length and produces the same correctly wrapped code.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.