Community
Participate
Working Groups
When there is a newline in the condition of an 'else if' statement, the indentation below is wrong until the closing brace. Example: if (false || true) { // good case } else if (false || true) { // bad case } // fails to align The "bad case" comment and the closing braces should be 4 tabs further left. Tested with Eclipse Version: 2019-06 (4.12.0) Build id: 20190614-1200
I just upgraded to latest Eclipse: Version: 2019-09 R (4.13.0) Build id: 20190917-1200 The bug is still active.
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. If you have further information on the current state of the bug, please add it. 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.
Bug is still active in Eclipse 2021-06
I have not been able to reproduce this issue. Can you please check with the latest release and update.
I tested with Version: 2021-12 (4.22.0) Build id: 20211202-1639 Automatic indentation is still wrong (using any formatter profile, e.g. "Eclipse [built-in]") if (false || true) { // good case } else if (false || true) { // bad case } // fails to align Did you copy/paste above code and applied automatic formatting? What was the outcome?
(In reply to Bernhard Seebass from comment #5) > I tested with > > Version: 2021-12 (4.22.0) > Build id: 20211202-1639 > > Automatic indentation is still wrong (using any formatter profile, e.g. > "Eclipse [built-in]") > > > if (false > || true) { > // good case > } else if (false > || true) { > // bad case > } // fails to align > > > Did you copy/paste above code and applied automatic formatting? What was the > outcome? Steps that I followed : '|' - indicates cursor position. Copied the below code into java editor if (false || true) { // good case } else if (false || true) {| Now press enter at the cursor position , the code changes to if (false || true) { // good case } else if (false || true) { | } Here the indentation, cursor position is correct for the new line as well as the closing brace. If the above use case is not the case you are referring to, please provide detailed steps to reproduce the issue that you are facing.
Thanks for replying and sorry for me having been unclear about what I meant with "automatic formatting". Indentation is correct while typing. However, as soon as I save, the source is automatically formatted (due to my "Save Actions" settings) and then the indentation is wrong. Of course, for testing, you can just apply automatic formatting manually by pressing CTRL+SHIFT+F
(In reply to Bernhard Seebass from comment #7) > Thanks for replying and sorry for me having been unclear about what I meant > with "automatic formatting". > > Indentation is correct while typing. However, as soon as I save, the source > is automatically formatted (due to my "Save Actions" settings) and then the > indentation is wrong. > > Of course, for testing, you can just apply automatic formatting manually by > pressing CTRL+SHIFT+F When I select the code and press CTRL+SHIFT+F , the allignment is as below if (false || true) { // good case } else if (false || true) { // bad case } // fails to align Can you please provide the details of your "Save Actions" settings, that is what changes have you made different from the default settings.
It seems I did something wrong, when I tested with the built in Formatter profile as the problem is in fact not reproducible using the built-in profile. To reproduce the misalignment I copied "Eclipse [built-in]" Profile and then changed the following: - New Lines / 'if else' X Keep 'else' statement on same line - Line Wrapping X Never join already wrapped lines After I have disabled the option "Keep 'else' statement on same line" in my formatter settings, formatting works as desired (with "Keep 'else if' on one line" enabled).
The key part is the "newline in condition". Do not let the formatter remove the newlines from the if condition. Here is a longer example: if (someconditon()) { // do stuff } else if (testLongCallOne() && testLongCallTwo() && testLongCallThree()) { // do another thing } else { // something else } Clearly the last four lines should not be indented using the continuation-indent settings.