| Summary: | "Never join already wrapped lines" counterintuitive for ternary operators | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Atsushi Nakagawa <atnak> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | keinohrschlumpf2, mateusz.matela |
| Version: | 4.6 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 10 | ||
| Whiteboard: | stalebug | ||
In example 2 the formatter did not respect the existing wrap, because it was on the other side of the operator. Do you want the formatter to keep inconsistent wraps? "Wrap all elements, every element on new line" means the formatter should either keep everything in one line if possible, or wrap all elements. So "never join..." doesn't make a lot of sense with this assumption. Current interpretation of "never join.." is that if there's at least one wrap, then all elements are wrapped (as you see with example 3). It seems the behavior you want is achieved with policy "Wrap where necessary", isn't it? > Do you want the formatter to keep inconsistent wraps?
Yes is ultimately the answer to this. What it comes down to is that I was after the ability to keep two styles:
Style 1:
```
int some_variable = something_really_long_here ?
a_call_foo_method() : a_call_bar_method();
```
Style 2:
```
int some_variable = something_really_long_here
? (a_call__foo_method() ? 1000 : 2000)
: a_call_bar_method() + 30000;
```
However, I did some more testing and found that the formatter will always proactively join lines that are wrapped inconsistently to the "Wrap before operators" option. Style 1 is joined if "Wrap before operators" is checked and Style 2 if not.
This does not appear to be affected by the choice for "Line wrapping policy" nor "Never join already wrapped lines" and was/can be the cause of initial confusion.
In my current team, we normally use this style throughout:
```
String radius = System.currentTimeMillis() < 0 ?
"large".toUpperCase(Locale.ENGLISH) :
"small".toUpperCase(Locale.ENGLISH);
```
Currently there is no way to stop eclipse from collapsing this into the following:
```
String radius = System.currentTimeMillis() < 0 ? "large".toUpperCase(Locale.ENGLISH) : "small"
.toUpperCase(Locale.ENGLISH);
```
"Never join existing lines" and "Prefer wrapping outer exception" have no effect, and I can't find a "Wrap where necessary" option that corresponds to ternary operators. Is it missing? Also I can't find a "Wrap before operators" options, maybe it was added very recently? (using Neon.3 Release (4.6.3) Build id: 20170314-1500)
(In reply to Heribert Samweis from comment #3) > I can't find a "Wrap where necessary" option that corresponds to > ternary operators. Is it missing? In the Line Wrapping tab, select Exressions -> Conditionals. From your descriptions it seems you have it set to "Do not wrap". This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Regarding to ternary operators (`a ? b : c`), the Formatter option "Never join already wrapped lines" *does not appear to do anything*. My Line wrapping is configured like so: [x] Never join already wrapped lines [x] Prefer wrapping outer expressions Expressions > Conditionals: Line wrapping policy: [Wrap all elements, every element on new line] [ ] Force split, even if line shorter than maximum line width [x] Wrap before operators This results in: ``` // 1. This line shorter than maximum line width: return argument ? 100000 : 20000; // Is formatted to: (as expected) return argument ? 100000 : 20000; ``` ``` // 2. This line shorter than maximum line width: return argument ? 100000 : 20000; // Is formatted to: (Not expected!) return argument ? 100000 : 20000; ``` ``` // 3. This line shorter than maximum line width: return argument ? 100000 : 20000; // Is formatted to: return argument ? 100000 : 20000; ``` The result for 2 is unexpected because this is what "Never join already wrapped lines" was thought to counter.