Bug 108087 - Java conventions default formatter settings confused
Summary: Java conventions default formatter settings confused
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-26 04:54 EDT by Tom Hofmann CLA
Modified: 2006-04-13 10:38 EDT (History)
2 users (show)

See Also:


Attachments
DefaultCodeFormatterOptions.java.diff (1.16 KB, patch)
2005-08-26 04:54 EDT, Tom Hofmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2005-08-26 04:54:09 EDT
I20050823 (perhaps a 3.1.1 issue?)

The Java conventions formatter settings have been changed to fix bug XXX. They
now specify

  tab_char=SPACE
  tab_size=8
  indent_size=4

This looks correct, but isn't: the formatter will not interpret the indent_size
setting when tab_char is SPACE, but rather take the tab_size setting as
indentation length. Therefore, the correct setting should read:

  tab_char=SPACE
  tab_size=4
  (indent_size=8) // this is not interpreted by the formatter, but the editor
uses it as the visual tab length setting, so please set it to 8

or 

  tab_char=MIXED
  tab_size=8
  indent_size=4

I will attach a patch that implements the former.
Comment 1 Tom Hofmann CLA 2005-08-26 04:54:40 EDT
Created attachment 26521 [details]
DefaultCodeFormatterOptions.java.diff
Comment 2 Olivier Thomann CLA 2005-08-26 14:48:08 EDT
The previous bug fix where we changed this value is bug 104765.
The change has not been backported to 3.1.1.

According to your comment, the right solution would be:
  tab_char=MIXED
  tab_size=8
  indent_size=4

  tab_char=SPACE
  tab_size=4
  (indent_size=8) // this is not interpreted by the formatter, but the editor
uses it as the visual tab length setting, so please set it to 8

doesn't solve anything because the tab is till four characters. So it might look
good in Eclipse, but it would be wrong outside of Eclipse in a simple text editor.
Comment 3 Olivier Thomann CLA 2005-08-26 15:05:02 EDT
I checked some code from code librairies and it doesn't seem to follow the Java
conventions.
Using MIXED as the tab char will end up having tabs and spaces. But it appears
that only spaces are using. The conventions themselves don't appear to specify
what should be used.
From the conventions:
"Four spaces should be used as the unit of indentation. The exact construction
of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly
every 8 spaces (not 4)."
So the MIXED mode might not be wrong.
What do you think?
Comment 4 Tom Hofmann CLA 2005-08-27 12:55:49 EDT
(In reply to comment #2)
>   tab_char=SPACE
>   tab_size=4
>   (indent_size=8)
> 
> doesn't solve anything because the tab is till four characters. So it might look
> good in Eclipse, but it would be wrong outside of Eclipse in a simple text 
> editor.

I don't see how this could be the case - if tab_char is SPACE, it will look good
everywhere since the formatter will not insert any tabs! So, code formatted with
these settings will look correct in any editor.

Of course, to display mixed indents correctly (e.g. rt.jar code), the *editor*
still needs to know how to display tabs, but not the *formatter*!

What the Java editor does in this case: it uses the indentation_size setting
(which is not used by the formatter) to store the visual tab length setting.
This is why I asked to set it to 8.

(In reply to comment #3)
> So the MIXED mode might not be wrong.
> What do you think?

I agree. The conventions do not specify either mode, so either of the
combinations correctly implements the Java conventions.
Comment 5 Olivier Thomann CLA 2006-01-25 13:22:56 EST
  tab_char=MIXED
  tab_size=8
  indent_size=4

This seems to be the best solution for me. Unfortunately this is not backward compatible with the existing Java conventions. But sine we have an Eclipse profile that is the default profile, we might want to change it in the Java conventions.
The indent_size to 8 seems to be wrong even if this is what the editor is using.
Comment 6 Olivier Thomann CLA 2006-02-07 11:27:21 EST
Do you want this to be fixed for 3.2?
Comment 7 Tom Hofmann CLA 2006-02-24 09:28:25 EST
(In reply to comment #6)
> Do you want this to be fixed for 3.2?

(sorry for the late answer)

Yes please - the settings from your comment 5 are fine for me.
Comment 8 Tom Hofmann CLA 2006-04-05 10:14:40 EDT
would be nice for 3.2!
Comment 9 Olivier Thomann CLA 2006-04-05 11:40:11 EDT
So compare to existing settings. This simply means to change the tab char from SPACE to MIXED.
Comment 10 Olivier Thomann CLA 2006-04-05 11:45:19 EDT
Tom,

Do you have any tests that rely on the old settings?
I am running all our tests.
Comment 11 Tom Hofmann CLA 2006-04-05 12:11:26 EDT
(In reply to comment #10)
> Tom,
> 
> Do you have any tests that rely on the old settings?

I don't expect any problems as we normally use eclipse settings or custom ones with INDENT_CHAR=SPACE. I am running the tests with the modifications right now, though.
Comment 12 Olivier Thomann CLA 2006-04-05 14:09:54 EDT
Fixed and released in HEAD.
Comment 13 Philipe Mulet CLA 2006-04-09 07:24:39 EDT
+1 for 3.2RC1
Comment 14 David Audel CLA 2006-04-13 10:38:32 EDT
Verified for 3.2 RC1 using build I20060413-0010