Is "Extract Method" more fragile than before?

Is it just me or does "Extract Method" refuse to extract more often than
it did before? If I try to extract the contents of a foreach loop that contains
a return, Resharper refuses because "Extracted block has exits to different
points. I understand what that means, but why does Resharper give up so easily?
In 2.5, I got a warning claiming the extraction will change the meaning,
but it let me proceed anyway. The CodeRush "Extract Method" returns a "shouldReturn"
boolean that is used to return from the original method.

Why can't "Extract Method" just try a little harder?


3 comments
Comment actions Permalink

Hello flipdoubt,

Could you please give us example code?

Sincerely,
Ilya Ryzhenkov

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


f> Is it just me or does "Extract Method" refuse to extract more often
f> than it did before? If I try to extract the contents of a foreach
f> loop that contains a return, Resharper refuses because "Extracted
f> block has exits to different points. I understand what that means,
f> but why does Resharper give up so easily? In 2.5, I got a warning
f> claiming the extraction will change the meaning, but it let me
f> proceed anyway. The CodeRush "Extract Method" returns a
f> "shouldReturn" boolean that is used to return from the original
f> method.
f>
f> Why can't "Extract Method" just try a little harder?
f>


0
Comment actions Permalink

Could you please give us example code?


Does this help? If I select the text called out in the comments and then
press CTRLALTM, VS spits up a dialog that reads as follows:
-


Extract Method Cannot Proceed
-


Extracted block has exits to different points
-


OK
-



Here is the code:
--
public override void Install( IDictionary stateSaver )
{
base.Install( stateSaver );

// Start seletion here.
if( string.IsNullOrEmpty( Context.Parameters["db"]))
return;
// End selection here.

System.Diagnostics.Debug.WriteLine( "// More code goes here ..." );
}
--


0
Comment actions Permalink

Hello flipdoubt,

Well... Yes, currently it's not possible to proceed with refactoring anyway
in this case. We are going to fix both things: allow you to execute refactoring
if it encounters such conflict and automatically resolve the situation you
gave as example.

Oleg Stepanov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> Could you please give us example code?
>>

Does this help? If I select the text called out in the comments and
then
press CTRLALTM, VS spits up a dialog that reads as follows:
---------------------------
Extract Method Cannot Proceed
---------------------------
Extracted block has exits to different points
---------------------------
OK
---------------------------
Here is the code:
--
public override void Install( IDictionary stateSaver )
{
base.Install( stateSaver );
// Start seletion here.
if( string.IsNullOrEmpty( Context.Parameters["db"]))
return;
// End selection here.
System.Diagnostics.Debug.WriteLine( "// More code goes here ..."
);
}
--



0

Please sign in to leave a comment.