| Summary: | [formatter] infix expression formatting broken without spaces before/after binary operator | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Markus Keller <markus.kell.r> | ||||||
| Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||||
| Status: | VERIFIED FIXED | QA Contact: | |||||||
| Severity: | major | ||||||||
| Priority: | P3 | CC: | jarthana, stephan.herrmann | ||||||
| Version: | 4.3 | ||||||||
| Target Milestone: | 4.3 M7 | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows 7 | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingExpressionsTest.testBug404251() has a disabled test case for this. Created attachment 229443 [details]
Proposed fix
Created attachment 229444 [details]
Regression tests
(In reply to comment #2) > Created attachment 229443 [details] > Proposed fix Thanks for the patch, Olivier. Patch looks good, will release after running the tests. Verified for 4.3 M7 using build I20130428-2000 that - formatting no longer changes the semantics. I was slightly surprised to see that these int s = b-- - --c; int t = b-- - -c; are still formatted as int s = b--- --c; int t = b--- -c; which is not wrong, but still makes for a confusing read (but then the programmer writing such code is more to blame than the formatter :) ). > (but then the
> programmer writing such code is more to blame than the formatter :) ).
I'd mainly blame the one who sets the *INSERT_SPACE* options to DO_NOT_INSERT...
|
If you set FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR and FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR to DO_NOT_INSERT, then code like this: int foo(int a, int b, int c) { return a + b + ++c; } gets mangled into: return a+b+++c; Note that the compiler parses this as: return (a)+(b++)+(c); => The ++ moved from ++c to b++ !