eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[Formatter] no whitespace after block-less `else` with following non-alphanumeric tokens

Open
#3,485 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

The code formatter formats single line `else` without block and "New Lines -> In control statements -> 'if else' -> Keep 'else' statement on same line" without following white space if the next token does not need to be separated by a space.
Additional: "Compact 'if else' -> Force Split" is completely ignored with the above setting activated.

So for the follwing `else` statements the space will be removed:
```java
else ++i;
else "".toString();
else (a).toString();
else """
""".toString();
```

This also can lead to strange side effects like the save action "Use parenthesis in expressions -> Only if necessary" will transform `else(someVar).toString();` to the invalid code `elsesomeVar.toString()`, although this might be a separate bug which needs to be checked when this is fixed.

## Versions
Eclipse SDK
Version: 2024-12 (4.34)
Build id: I20241120-1800

openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode, sharing)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.