| Summary: | [formatter] Nested expression should remain indented after preserving line break | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> | ||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P5 | CC: | LifarV, Olivier_Thomann | ||||
| Version: | 3.5 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
Created attachment 119889 [details]
Testcase
Note: line wrapping is set at 80 Currently, when allowing to join the line (i.e. 3.4 behavior), the formatter always joins the two members of the comparison, even if there's not enough room on the line => which means that it never preserves the indentation, but always set it to the specified one.
As I do not see any preferences to indent this kind of expression, I would say that this sounds more like a new requirement: preserve indentation when preserving line breaks.
So, this new preferences would allow not to change the following test case:
public class X {
void foo() {
boolean test1 = (1000000000L < 2000000000L);
boolean test2 = (3000000000L
< 4000000000L);
boolean test3 = 5000000000L
< 60000000000L;
}
}
instead of currently formatting it as follow (using Eclipse built-in profile + max line width=40 + never join lines + spaces only):
public class X {
void foo() {
boolean test1 = (1000000000L < 2000000000L);
boolean test2 = (3000000000L
< 4000000000L);
boolean test3 = 5000000000L
< 60000000000L;
}
}
Note that while joining the lines the formatter output is:
public class X {
void foo() {
boolean test1 = (1000000000L < 2000000000L);
boolean test2 = (3000000000L < 4000000000L);
boolean test3 = 5000000000L < 60000000000L;
}
}
with each line over the max line width...
I don't think you need a new preference.
The formatter knows how to indent a binary expression deeper for the 2nd fragment to deal with cases where an IF condition being split on multiple lines is not confusing with IF-THEN body.
e.g.
if (aaaaaaaaaaaa
[tab][tab]&& bbbbbbbb) {
[tab]doSomething();
}
All I am asking is that the 'never join' option is not altering this behavior.
Actually, I agree that this behavior has nothing to do with the 'join line' preference.
The formatter doesn't know how to split nested expressions properly in complex if conditions.
public class Test {
void foo(
boolean aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
boolean bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
boolean ccccccccccccccccccccccc,
boolean ddddddddddddddddddd,
int eeeeeeeeeeeeeeeeeeeeeeeee,
int gggggggggggggggggggggggggg,
int kkkkkkkkkkkkkkkkkkkkkkkkk) {
if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|| bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
&& !(ccccccccccccccccccccccc
|| ddddddddddddddddddd)
&& eeeeeeeeeeeeeeeeeeeeeeeee
< gggggggggggggggggggggggggg) {
eeeeeeeeeeeeeeeeeeeeeeeee +=
gggggggggggggggggggggggggg;
}
}
}
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. |
Version: 3.5.0 - Build id: I20081209-0100 With formatter preferences set to: org.eclipse.jdt.core.formatter.join_wrapped_lines=false org.eclipse.jdt.core.formatter.join_lines_in_comments=false The following code should remain unchanged after formatting (observe position change for "< jjjjjjjjjjjjjjjjjjjjjjjjjj)" fragment. public class X { void foo(boolean bbbbbbbbbbbbbbbbbbbbbbbb, boolean ccccccccccccccccccccccc, boolean ddddddddddddddddddd, int iiiiiiiiiiiiiiiiiiiiiiiiiiii, int jjjjjjjjjjjjjjjjjjjjjjjjjj, int kkkkkkkkkkkkkkkkkkkkkkkkk) { if (bbbbbbbbbbbbbbbbbbbbbbbb && !(ccccccccccccccccccccccc || ddddddddddddddddddd) && iiiiiiiiiiiiiiiiiiiiiiiiiiii < jjjjjjjjjjjjjjjjjjjjjjjjjj) { iiiiiiiiiiiiiiiiiiiiiiiiiiii += jjjjjjjjjjjjjjjjjjjjjjjjjj; } } }