Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 471854 - Eclipse Mars/4.5 formatter broken with tab 2 indent
Summary: Eclipse Mars/4.5 formatter broken with tab 2 indent
Status: VERIFIED DUPLICATE of bug 467229
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 major with 3 votes (vote)
Target Milestone: 4.5.1   Edit
Assignee: Mateusz Matela CLA
QA Contact: Manoj N Palat CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-04 13:02 EDT by Garret Wilson CLA
Modified: 2015-08-21 12:45 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson CLA 2015-07-04 13:02:15 EDT
The new Eclipse Mars/4.5 formatter is broken. With a tab size of 2, no lines within the body of methods are indented. (Oddly it works with a tab size of 3 or 4, but not 2.)

Go to Preferences|Java|Code Style|Formatter and edit a profile. Under Indentation|General Settings, set Tab Policy to "Tabs only" and set the tab size to 2. Notice the preview on the right:

	void foo(int a, int b, int c, int d, int e, int f) {
	switch(a) {

If you change the tab size to 4, the code is indented:

	void foo(int a, int b, int c, int d, int e, int f) {
		switch(a) {

But I don't want a tab size of 4! I want a tab size of 2! This worked just fine in Eclipse 4.4 and for many versions before it.

This is a bigger issue than it might seem! We use code formatting on all our code before commits, and I'll basically have to turn it off now until it is fixed. We can't have the body of methods unindented!!

Oddly if I set the Tab Policy to "Mixed", method bodies are indented correctly even with a tab size of 2.
Comment 1 Frank Jakop CLA 2015-07-06 04:40:49 EDT
I agree, this is more critical than it sounds at first. 
For us, we will not let Mars loose on our dev teams before this is fixed.
We use also tab size 2 and auto-formatting on save, which would destroy all of our 200+ projects.
Comment 2 Jay Arthanareeswaran CLA 2015-07-06 05:02:40 EDT
Do we already have a bug for this?

Thanks Mateusz for a taking a look.
Comment 3 Karl Huebner CLA 2015-07-06 05:58:09 EDT
The behavior is indeed very weird. If you set tab size to 2, suddenly the maximum number of indents is 2 as well; that's why it works with tab size 3 and 4. Those should be two different settings, however, I see no use case in restricting the maximum number of indents.

I found out, if you play around with the settings (switching to 'mixed mode', set 'indentation size' to 2 and 'tab size' to 4, then back to 'tabs only'), the code is formatted correctly (you even can save the profile and everything is fine then). Just in case anyone needs a workaround :)
Comment 4 Garret Wilson CLA 2015-07-06 09:52:22 EDT
Maybe when you fix this bug, you can also fix 471918 while you're at it. (And then maybe you could fix 471920, which would make me extra-happy.) Thanks!
Comment 5 Garret Wilson CLA 2015-07-06 09:54:01 EDT
For completeness I mentioned Bug 471918 and Bug 471920. (I keep forgetting this is not JIRA and I need an extra word for the auto-formatter to create a link.)
Comment 6 Karl Huebner CLA 2015-07-07 07:31:38 EDT
The mentioned workaround seems not to work allways :(
Comment 7 Mateusz Matela CLA 2015-07-08 13:34:07 EDT
Actually, the workaround is to set both 'indentation size' and 'tab size' to the same value (here: 2) while 'mixed mode' is selected, and then switch back to 'tabs only'.

This is duplicate of bug 467229.
Can you confirm?
Comment 8 Frank Jakop CLA 2015-07-20 04:11:29 EDT
Is it possible to get this fixed before SR1? This one is the blocker for our company rollout of Mars.
Comment 9 Jeen Broekstra CLA 2015-07-27 20:31:47 EDT
Seeing the same issue, though in contrast to previous reports I get this behavior with initial tab size set to 3 as well, or any tab size that I care to try (this is using code formatting settings imported from a file previously exported using Luna). Initial settings are tabs-only indentation with tab size set to 3. The suggested workaround (switching to mixed mode, setting both tab and indentation size to 3, applying, reformatting, then switching back to Tabs only mode) does seem to work.
Comment 10 Mateusz Matela CLA 2015-08-03 11:56:43 EDT

*** This bug has been marked as a duplicate of bug 467229 ***
Comment 11 Jay Arthanareeswaran CLA 2015-08-21 12:45:49 EDT
Verified for 4.5.1 with build M20150819-1000