"Cleanup Code" - Wrap object and collection initializer

I have set "Wrap object and collection initializer " to Chop Always, but my array initializer end up like below

Type[] types = new[]
{
typeof (A), typeof (E), typeof (G), typeof (B), typeof (H), typeof (L), typeof (C), typeof (I),
typeof (M), typeof (D), typeof (J), typeof (N), typeof (E), typeof (K), typeof (O)
};

Where as I expect it to be;
Type[] types = new[]
{
typeof (A),
typeof (E),
typeof (G),
typeof (B),
typeof (H),
typeof (L),
typeof (C),
typeof (I),
typeof (M),
typeof (D),
typeof (J),
typeof (N),
typeof (E),
typeof (K),
typeof (O)
};

Can anyone please suggest how to achieve this?

Thanks

7 comments

Hello,

I guess "chop" refers to chopping the line if it gets too long (beyond the
margin). There's some other setting for lining up the list like this, but
I don't remember its name.


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0

Attached is my settings.
I went through serveral times already and try different combination but can't get the array lined up like that..

It's just that hard to see the code when I have long list of items.

Any help would be appriciated.



Attachment(s):
Capture.PNG
0

Try these settings.

Braces Layout:
Array and object initializer: At next line (BSD style)

Line Breaks and Wrapping:
Wrap object and collection initializer: Chop if long or Chop always

Other:
Continuous line indent multiplier: 1
Align Multiple Constructs - Array, object and collection initializer:
unchecked
Other - Indent array, object and collection initializer block: unchecked

This is as close as I can get to the desired layout with the caveat that the
braces are indented one tab stop instead of being aligned with the left edge
of the declaration.

"jye" <no_reply@jetbrains.com> wrote in message
news:16839843.75311223514678836.JavaMail.jive@app4.labs.intellij.net...

I have set "Wrap object and collection initializer " to Chop Always, but
my array initializer end up like below

>

Type[] types = new[]
{
typeof (A), typeof (E), typeof (G), typeof (B), typeof (H),
typeof (L), typeof (C), typeof (I),
typeof (M), typeof (D), typeof (J), typeof (N), typeof (E),
typeof (K), typeof (O)
};

>

Where as I expect it to be;
Type[] types = new[]
{
typeof (A),
typeof (E),
typeof (G),
typeof (B),
typeof (H),
typeof (L),
typeof (C),
typeof (I),
typeof (M),
typeof (D),
typeof (J),
typeof (N),
typeof (E),
typeof (K),
typeof (O)
};

>

Can anyone please suggest how to achieve this?

>

Thanks


0

Thanks Greg,

I followed your suggested settings but still ended up like below.


typeof (A), typeof (E), typeof (G), typeof (B), typeof (H), typeof (L), typeof (C), typeof (I),
typeof (M), typeof (D), typeof (J), typeof (N), typeof (E), typeof (K), typeof (O)

I still cannot format each array item at a single line with below settings.

Braces Layout: Array and object initializer: At next line (BSD style)
Line Breaks and Wrapping: Wrap object and collection initializer: Chop if long or Chop always (Tested with both settings)
Other:Continuous line indent multiplier: 1
Align Multiple Constructs - Array, object and collection initializer: unchecked
Other - Indent array, object and collection initializer block: unchecked

Edited by: jye on Oct 12, 2008 7:04 AM

0

I omitted this from my initial response because I was hoping it was just me.

This seems to be a bug in the current version of ReSharper. ReSharper will
not chop array initializers in all circumstances... even if the length of
the line exceeds the right margin. To demonstrate this, I created a longish
array initializer:

string[] array = { "foo", "bar", ..., "baz" }; // up to about 140 characters
or so

Reformat code and the line remains intact. Manually insert a blank line
after the opening brace and ReSharper merely moves the closing brace to a
new line:

string[] array = {
"foo", "bar", ..., "baz"
};

The above format is just dead wrong because it should follow the BSD style.
At least the following is how it should be reformatted:

string array =
{
"foo",
"bar",
...,
"baz"
};

The only way I've managed to get ReSharper to reformat array initializers
"properly" is to place each element on its own line by hand. Once you have
the array more or less formated the way you want, ReSharper still gets it
wrong:

string array =
{
"foo",
"bar",
...,
"baz"
};

"jye" <no_reply@jetbrains.com> wrote in message
news:10817134.93351223780698976.JavaMail.jive@app4.labs.intellij.net...

Thanks Greg,

>

I followed your suggested settings but still ended up like below.

>
>

typeof (A), typeof (E), typeof (G), typeof (B), typeof (H),
typeof (L), typeof (C), typeof (I),
typeof (M), typeof (D), typeof (J), typeof (N), typeof (E),
typeof (K), typeof (O)

>

I still cannot format each array item at a single line with below
settings.

>

Braces Layout: Array and object initializer: At next line (BSD style)
Line Breaks and Wrapping: Wrap object and collection initializer: Chop if
long or Chop always (Tested with both settings)
Other:Continuous line indent multiplier: 1
Align Multiple Constructs - Array, object and collection initializer:
unchecked
Other - Indent array, object and collection initializer block: unchecked

>

Edited by: jye on Oct 12, 2008 7:04 AM


0

Hi Greg,

Thanks again for your reply.

Hopefully it is fixed in the futuer version.

0

Thank you for the report.
I've created ticket in our bug tracker for this problem:
http://www.jetbrains.net/jira/browse/RSRP-83472

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Lothan" <lothan@newsguy.com> wrote in message
news:gcubpj$da9$1@is.intellij.net...
>I omitted this from my initial response because I was hoping it was just
>me.
>

This seems to be a bug in the current version of ReSharper. ReSharper will
not chop array initializers in all circumstances... even if the length of
the line exceeds the right margin. To demonstrate this, I created a
longish array initializer:

>

string[] array = { "foo", "bar", ..., "baz" }; // up to about 140
characters or so

>

Reformat code and the line remains intact. Manually insert a blank line
after the opening brace and ReSharper merely moves the closing brace to a
new line:

>

string[] array = {
"foo", "bar", ..., "baz"
};

>

The above format is just dead wrong because it should follow the BSD
style. At least the following is how it should be reformatted:

>

string array =
{
"foo",
"bar",
...,
"baz"
};

>

The only way I've managed to get ReSharper to reformat array initializers
"properly" is to place each element on its own line by hand. Once you have
the array more or less formated the way you want, ReSharper still gets it
wrong:

>

string array =
{
"foo",
"bar",
...,
"baz"
};

>

"jye" <no_reply@jetbrains.com> wrote in message
news:10817134.93351223780698976.JavaMail.jive@app4.labs.intellij.net...

>> Thanks Greg,
>>
>> I followed your suggested settings but still ended up like below.
>>
>>
>> typeof (A), typeof (E), typeof (G), typeof (B), typeof
>> (H), typeof (L), typeof (C), typeof (I),
>> typeof (M), typeof (D), typeof (J), typeof (N), typeof
>> (E), typeof (K), typeof (O)
>>
>> I still cannot format each array item at a single line with below
>> settings.
>>
>> Braces Layout: Array and object initializer: At next line (BSD style)
>> Line Breaks and Wrapping: Wrap object and collection initializer: Chop if
>> long or Chop always (Tested with both settings)
>> Other:Continuous line indent multiplier: 1
>> Align Multiple Constructs - Array, object and collection initializer:
>> unchecked
>> Other - Indent array, object and collection initializer block: unchecked
>>
>> Edited by: jye on Oct 12, 2008 7:04 AM



0

Please sign in to leave a comment.