| Summary: | [formatter] Code Formatter indents array initializer braces "incorrect" | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Nils Hammar <nils.hammar> | ||||
| Component: | Core | Assignee: | Mateusz Matela <mateusz.matela> | ||||
| Status: | RESOLVED DUPLICATE | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P5 | CC: | ladar, mateusz.matela, stephen.l.ray | ||||
| Version: | 3.1 | ||||||
| Target Milestone: | 4.5 M6 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | To be verified for 4.6 M5 | ||||||
| Attachments: |
|
||||||
Moving to JDT/Core. Deferring post 3.1 Bug is still in 3.1, and is annoying. Please consider for 3.2! Could you please provide your code formatter settings? Created attachment 26716 [details]
Current formatting rules as requested.
Thanks for the info.
To clarify your problem, you expect to get the '{' and '}' at the same
indentation level than the private, because you set that you want the braces for
an array initializer to be on the next line.
You expect the expressions within the array initializer to be align on column
relative to the positions of the brace.
Am I right?
Thanks for your feedback.
It's correct that I want the braces to be left-aligned with the private keyword and to have the data indented relative to the braces. A secondary issue is that currently the data is indented differently if there is a single value and if there are multiple values. The problems comes from a conflict between the type members alignment and the array initializer alignment. I am investigating. I have a similar problem with 3.4 rc4. Is it correct if I say no new line after brace for array initializer to get a new line after the brace. Currently in the example code I get :
static int[] fArray = {
1, 2, 3, 4, 5 };
I expect to get:
static int[] fArray = { 1, 2, 3, 4, 5 };
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 With array initializers, the formatting rules are not applied reliably to sub-structure initializers. For example:
typedef struct {
int a;
int b;
} CHILD_T;
typedef struct {
int a;
CHILD_T b;
} PARENT_T;
PARENT_T sample = {
.a = 1,
.b = {
.a = 1,
.b = 2,
}
};
If you start out with the above format, you can get it to stay that way. But if the .b initializer is already on one line, it will stay that way even if the format rules dictate a new line should be inserted.
(In reply to comment #11) The code you're showing looks like C++, doesn't it? Hence, the Java formatter couldn't be involved in the problem you're describing in this comment. Please open a bug against the right product (I guess it should be CDT...) My apologies, you are correct. It was my first Eclipse bug report and I was trying to avoid a duplicate. This problem no longer occurs after the formatter redesign. *** This bug has been marked as a duplicate of bug 303519 *** |
The code formatter seems to align the braces with the '=' sign and not the left edge of the previous line. Current formatting: private final static String[] defaultKeyStoresWindows = { "C:\\Program Files\\Java\\jre1.5.0\\lib\\security\\cacerts", "C:\\Documents and Settings\\nils\\.keystore" }; Expected Formatting: private final static String[] defaultKeyStoresWindows = { "C:\\Program Files\\Java\\jre1.5.0\\lib\\security\\cacerts", "C:\\Documents and Settings\\nils\\.keystore" }; Additionally, when an array has a single initializer the value is indented related to the braces, like the following example: private final static String[] defaultKeyStoresUnix = { "/usr/java/jdk1.5. 0/jre/lib/security/cacerts" }; It should be possible to select if the braces should be aligned with the '=' sign or to the left if '='-alignment is used.