Can RS3.1 reformat the following?

Take the code below which I took from my main form. RS3.1 highlights 100's of redundant casts etc which is fine and I've cleaned those up. What I did notice is that RS does not offer a refactor/reformat of the code. The code is actually broken up over three lines.

*REQPPicturePanel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right;*

That is, it would be nice if I could tell it remove the unecessary brackets which the .Net IDE produced when I changed the control anchor. Further, can you tell RS to join the line breaks to produce this instead?

REQPPicturePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

Admittedly, this is just my personal coding style but I'd like to know if it's possible to do this?

Message was edited by:
Peter Hamilton-Scott

16 comments
Comment actions Permalink

For what it's worth, I'd like to see the ability to remove
unnecessary/redundant parentheses for much the same reason. I've been
working on some very legacy code bases lately by converting the original VB6
code to VB.NET, getting the VB.NET code to compile, then using Reflector to
extract the C# code from the compiled assemblies. It's the long-way around,
but it generally works well enough to allow us to refactor the code base
into something a lot more understandable. Reflector generally pulls out
decent C# code, but it uses parentheses excessively.

"Peter Hamilton-Scott" <no_reply@jetbrains.com> wrote in message
news:2952997.1200827961477.JavaMail.itn@is.intellij.net...

Take the code below which I took from my main form. RS3.1 highlights 100's
of redundant casts etc which is fine and I've cleaned those up. What I did
notice is that RS does not offer a refactor/reformat of the code. The code
is actually broken up over three lines.

>

*REQPPicturePanel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right;*

>

That is, it would be nice if I could tell it remove the unnecessary
brackets which the .Net IDE produced when I changed the control anchor.
Further, can you tell RS to join the line breaks to produce this instead?

>

*REQPPicturePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
AnchorStyles.Left | AnchorStyles.Right;*

>

Admittedly, this is just my personal coding style but I'd like to know if
it's possible to do this?


0
Comment actions Permalink

Thank you for interesting request.
But I rather doubt how can we tell redundant parentheses which do not
improve readability.....

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Lothan" <lothan@newsguy.com> wrote in message
news:fn94qi$h89$1@is.intellij.net...

For what it's worth, I'd like to see the ability to remove
unnecessary/redundant parentheses for much the same reason. I've been
working on some very legacy code bases lately by converting the original
VB6 code to VB.NET, getting the VB.NET code to compile, then using
Reflector to extract the C# code from the compiled assemblies. It's the
long-way around, but it generally works well enough to allow us to
refactor the code base into something a lot more understandable. Reflector
generally pulls out decent C# code, but it uses parentheses excessively.

>

"Peter Hamilton-Scott" <no_reply@jetbrains.com> wrote in message
news:2952997.1200827961477.JavaMail.itn@is.intellij.net...

>> Take the code below which I took from my main form. RS3.1 highlights
>> 100's of redundant casts etc which is fine and I've cleaned those up.
>> What I did notice is that RS does not offer a refactor/reformat of the
>> code. The code is actually broken up over three lines.
>>
>> *REQPPicturePanel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
>> | AnchorStyles.Left)
>> | AnchorStyles.Right;*
>>
>> That is, it would be nice if I could tell it remove the unnecessary
>> brackets which the .Net IDE produced when I changed the control anchor.
>> Further, can you tell RS to join the line breaks to produce this instead?
>>
>> *REQPPicturePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
>> AnchorStyles.Left | AnchorStyles.Right;*
>>
>> Admittedly, this is just my personal coding style but I'd like to know if
>> it's possible to do this?



0
Comment actions Permalink

Eugene,

I can understand why RS can't clean up 'redundant' parentheses.

But can RS join code that has been split over two or more lines?

0
Comment actions Permalink

Thank you for interesting request.
But I rather doubt how can we tell redundant
parentheses which do not
improve readability.....


For what it is worth, R#'s primary competition can.

0
Comment actions Permalink

Hello Jeremy,

Do you mean Visual Studio? :)

Seriously, I didn't know "they" can reformat code. Do you mean something
they call "refactoring" and we call "context action"?

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


>> Thank you for interesting request.
>> But I rather doubt how can we tell redundant
>> parentheses which do not
>> improve readability.....
IR> For what it is worth, R#'s primary competition can.
IR>


0
Comment actions Permalink

No. To be blunt, the DevExpress folks have a refactoring that can clean up unnecessarily parenthesized expressions. Not that I've really used it, as I'm an R# guy. ;)

0
Comment actions Permalink

Personally, I use lots of parentheses in my code to improve readability of
it. Accordingtothe language specs, they're redundant, but I will be very
unhappy if some tool will remove all of them

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Jeremy Gray" <no_reply@jetbrains.com> wrote in message
news:30190365.1201230401438.JavaMail.itn@is.intellij.net...

No. To be blunt, the DevExpress folks have a refactoring that can clean up
unnecessarily parenthesized expressions. Not that I've really used it, as
I'm an R# guy. ;)



0
Comment actions Permalink

Hello Eugene,

I feel there are cases when it is quite ok to remove parentheses. Like when
they are strictly doubled, i.e. ((expr)). I sometimes would like to have
context action to remove them, like we have for braces.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


EP> Personally, I use lots of parentheses in my code to improve
EP> readability of it. Accordingtothe language specs, they're redundant,
EP> but I will be very unhappy if some tool will remove all of them
EP>


0
Comment actions Permalink

And maybe a step further, some reformating feature is only available for selected text/area? when you select a area, you know what's inside and you can enable this kind of action. To be more greedy, I think a lot of "actions" should be able to be used this way, always moving cursor, pressing alt+enter, selecting an option sometimes is tedious...

0
Comment actions Permalink

Guys

Just to labour my question again. Can RS convert this multiple line statement:

X.Anchor = AnchorStyles.Top | AnchorStyles.Bottom
| AnchorStyles.Right;

into this single line statement?

X.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;

It would be nice if I could select a block of code and then apply such magic to it in one operation. Is that possible?

Message was edited by:
Peter Hamilton-Scott

0
Comment actions Permalink

This probably isn't quite what you want, but you can turn off 'keep existing line breaks' in the formatting options, and then reformat the block of code.

I don't know enough about automating R# to know if there's a way to make that more friendly in the situaton where you don't want that option cleared normally.

0
Comment actions Permalink

Oh, don't get me wrong, I'm certainly not suggesting that any tool, whether R# or not, should get into the habit of removing parentheses just because, I only felt it necessary to comment on the implication (in an earlier reply on this thread) that it couldn't be done.

0
Comment actions Permalink

Hello Jeremy,

Of course it could be done. Tools can do various transformations to the code,
and this one looks like one of the simplest transformations. I.e. (expr)
:=> expr. However, the real question is how smart the tool should be, where
it will suggest removing parentheses, and where it will remove it silently,
and where it will not bother in. We are so keen in ReSharper team about the
correctness of our operations, that we'd better think 10 times before doing
this or that.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


JG> Oh, don't get me wrong, I'm certainly not suggesting that any tool,
JG> whether R# or not, should get into the habit of removing parentheses
JG> just because, I only felt it necessary to comment on the implication
JG> (in an earlier reply on this thread) that it couldn't be done.
JG>


0
Comment actions Permalink

Will,

You wrote: "This probably isn't quite what you want, but you can turn off 'keep existing line breaks' in the formatting options, and then reformat the block of code."

You are da man! That certainly worked a treat. For sure, it's not convenient to open the options menu and drill down to change the setting but at least it is doable. When you reformat the code you get a dialog containing some checkboxes used to modify the formatting. It would be nice if you could customise that and add additional settings of your own choice. Maybe the good folks at RS could add a line break option to the dialog?

0
Comment actions Permalink

I was actually thinking more along the lines of something like surround with
and remove surround with that supports parentheses and braces somewhat like
the DevX product. I wasn't looking for an automated tool for this. That is,
position the cursor on a parenthesis or brace and tell ReSharper to remove
the pair or highlight a statement or block and tell ReSharper to insert a
pair of parentheses or braces.

In fact, just the ability to insert/remove parentheses, braces, single
quotes, double quotes could really help work around some of ReSharper's
shortcomings that aren't likely to be enhanced within the distant
future--such as ReSharper's inability to maintain balance with quotes and
inability to figure out where to insert parentheses when adding a method
call to an existing statement.

"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:fn9e2h$sbo$1@is.intellij.net...

Thank you for interesting request.
But I rather doubt how can we tell redundant parentheses which do not
improve readability.....

>

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Lothan" <lothan@newsguy.com> wrote in message
news:fn94qi$h89$1@is.intellij.net...

>> For what it's worth, I'd like to see the ability to remove
>> unnecessary/redundant parentheses for much the same reason. I've been
>> working on some very legacy code bases lately by converting the original
>> VB6 code to VB.NET, getting the VB.NET code to compile, then using
>> Reflector to extract the C# code from the compiled assemblies. It's the
>> long-way around, but it generally works well enough to allow us to
>> refactor the code base into something a lot more understandable.
>> Reflector generally pulls out decent C# code, but it uses parentheses
>> excessively.
>>
>> "Peter Hamilton-Scott" <no_reply@jetbrains.com> wrote in message
>> news:2952997.1200827961477.JavaMail.itn@is.intellij.net...
>>> Take the code below which I took from my main form. RS3.1 highlights
>>> 100's of redundant casts etc which is fine and I've cleaned those up.
>>> What I did notice is that RS does not offer a refactor/reformat of the
>>> code. The code is actually broken up over three lines.
>>>
>>> *REQPPicturePanel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
>>> | AnchorStyles.Left)
>>> | AnchorStyles.Right;*
>>>
>>> That is, it would be nice if I could tell it remove the unnecessary
>>> brackets which the .Net IDE produced when I changed the control anchor.
>>> Further, can you tell RS to join the line breaks to produce this
>>> instead?
>>>
>>> *REQPPicturePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
>>> AnchorStyles.Left | AnchorStyles.Right;*
>>>
>>> Admittedly, this is just my personal coding style but I'd like to know
>>> if it's possible to do this?
>>
>

0
Comment actions Permalink

Hello Lothan,

For surround with, there are live templates that does exactly that. I don't
think there is pre-built template for parenthesis, but I use one for braces
all the time. You can create one easily if you wish.
As for remove, we have context action to remove braces, if this won't break
any code. Do you think we need same for parenthesis?

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


L> I was actually thinking more along the lines of something like
L> surround with and remove surround with that supports parentheses and
L> braces somewhat like the DevX product. I wasn't looking for an
L> automated tool for this. That is, position the cursor on a
L> parenthesis or brace and tell ReSharper to remove the pair or
L> highlight a statement or block and tell ReSharper to insert a pair of
L> parentheses or braces.
L>
L> In fact, just the ability to insert/remove parentheses, braces,
L> single quotes, double quotes could really help work around some of
L> ReSharper's shortcomings that aren't likely to be enhanced within the
L> distant future--such as ReSharper's inability to maintain balance
L> with quotes and inability to figure out where to insert parentheses
L> when adding a method call to an existing statement.
L>
L> "Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote
L> in message news:fn9e2h$sbo$1@is.intellij.net...
L>
>> Thank you for interesting request.
>> But I rather doubt how can we tell redundant parentheses which do not
>> improve readability.....
>> --
>> Eugene Pasynkov
>> Developer
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> "Lothan" <lothan@newsguy.com> wrote in message
>> news:fn94qi$h89$1@is.intellij.net...
>>> For what it's worth, I'd like to see the ability to remove
>>> unnecessary/redundant parentheses for much the same reason. I've
>>> been working on some very legacy code bases lately by converting the
>>> original VB6 code to VB.NET, getting the VB.NET code to compile,
>>> then using Reflector to extract the C# code from the compiled
>>> assemblies. It's the long-way around, but it generally works well
>>> enough to allow us to refactor the code base into something a lot
>>> more understandable. Reflector generally pulls out decent C# code,
>>> but it uses parentheses excessively.
>>>
>>> "Peter Hamilton-Scott" <no_reply@jetbrains.com> wrote in message
>>> news:2952997.1200827961477.JavaMail.itn@is.intellij.net...
>>>
>>>> Take the code below which I took from my main form. RS3.1
>>>> highlights 100's of redundant casts etc which is fine and I've
>>>> cleaned those up. What I did notice is that RS does not offer a
>>>> refactor/reformat of the code. The code is actually broken up over
>>>> three lines.
>>>>
>>>> *REQPPicturePanel.Anchor = ((AnchorStyles.Top |
>>>> AnchorStyles.Bottom)
>>>> | AnchorStyles.Left)
>>>> | AnchorStyles.Right;*
>>>> That is, it would be nice if I could tell it remove the unnecessary
>>>> brackets which the .Net IDE produced when I changed the control
>>>> anchor. Further, can you tell RS to join the line breaks to produce
>>>> this instead?
>>>>
>>>> *REQPPicturePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom
>>>> | AnchorStyles.Left | AnchorStyles.Right;*
>>>>
>>>> Admittedly, this is just my personal coding style but I'd like to
>>>> know if it's possible to do this?
>>>>


0

Please sign in to leave a comment.