Community
Participate
Working Groups
Formatting the following: switch (key.intValue()) { case BUTTON: return SketchFactory.eINSTANCE.createButton(); case HYPERLINK: return SketchFactory.eINSTANCE.createHyperlink(); default: break; } results in: switch (key.intValue()) { case BUTTON: return SketchFactory.eINSTANCE.createButton(); case HYPERLINK: return SketchFactory.eINSTANCE.createHyperlink(); default: break; }
This works for me using 3.2 RC6.
I'm not on M6 yet, but unless a bug was fixed since M4 this should still be reproducible. I'll attach my formatter prefs.
Created attachment 42976 [details] format prefs
Can reproduce using 3.2 RC6 with your preferences.
I'll investigate for 3.2.1 or 3.3. Too late for 3.2 anyway.
When you say it is a regression, a regression compare to what version ?
What is your indentation level when you format?
I tried it and it worked fine. What did you select to format? I tried using the formatter directly using the K_STATEMENTS kind. So please attach your test case. I also tried from the java editor and I could not reproduce.
It is one more than I posted. I removed a tab from each line. I'm inside a method whose signature has a single TAB in front of it.
No idea how you got it. Please attach the compilation unit you formatted. This could help to reproduce the problem.
(In reply to comment #6) > When you say it is a regression, a regression compare to what version ? This is a regression because every release I have indentation issues, probably different bugs, but usually related to switch or simple if statements. I'm sure your do some testing, so it must be specific to my settings. I would guess that the class members not being indented is causing the problem. See bug 75488, and bug 74958.
>I tried it and it worked fine. Did you really use the attached formatter preferences? Out of the box I couldn't reproduce either but with the attached prefs I was able to reproduce by simply copying the code from comment 0 into an existing method.
Yes, I imported the attached prefs. I'll keep trying to reproduce it.
Can you reproduce on 3.2? I tried again by creating a new project and importing the preferences you attached without better luck. Closing as REMIND. Please reopen with a complete unit as the test case if you can still reproduce it.
reproduced on R3.2. public class Main { public static void main(String[] args) { System.out.println("foo"); switch ((int) System.currentTimeMillis()) { case 10: return; case 20: return; default: break; } } } Notice that the member (method main) is indented, although my preferences are to not indent methods.
In order to reproduce it, I have to select only the switch statements. Daniel, this is related to the indentation of the first line when selecting a statement. Nothing has changed from the code formatter stand point for more than a year. This is not related to your settings. This is a known issue and I really don't see how this can be fixed. If you format the unit, the indentation is right.
The selected code can be anything and doesn't have to be a switch statement. the first line is left alone, while the other lines are formatted as if the entire file had been formatted. So, it does not respect the context's indentation level, and it leaves the first line alone. Both of these seem like problems, probably reported previously.
Daniel, I get the identation level from the UI. Do you see a way to improve this? Randy, Beside the first line not being indented, I believe the other lines are formatted as expected.
I disagree. The code should be indented relative to the indentation level of the parent element's indentation. In comment 15, the user chose to indent the main method even though the formatter preferences specify to not indent class members. If I indent the method 5 TABs, the method's body should be relative to that (+5). This occurs in code because formatting prefs don't support all indentation styles (such as top level classes should not have members indented. Nested classes should have members indented). Isn't the whole purpose of selective formatting to support cases where formatting the entire document would not satisfy the user?
>I disagree. The code should be indented relative to the indentation level of >the parent element's indentation. Agreed. There are two bugs here: 1. when fully (i.e. full line selections) selecting the switch statement (or an 'if' or...) the first line is currently not correctly formatted (i.e. indented) but it should. JDT Text gives JDT Core the correct selection i.e. all lines starting at the beginning of the line and the full source code. JDT Core should correctly format that block in respect to the surrounding code. 2. JDT Text should expand the start and end selection if there are just whitespaces before and afterwards and pass this to the formatter. This of course depends on 1. being fixed in JDT Core land.
Ownership has changed for the formatter, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5. Please provide a patch if you definitely need the bug to be fixed in this version and I'll have a look at it... TIA
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.