Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Refactor extract method

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Alexis Pautrot Posted - Mar 29 2012 : 09:03:08 AM
Hi,
you surely know this one, but it is really annoying and I hope you might fix it. From this code :

int result = 0;

POINT mouseCoords;
GetCursorPos ( &mouseCoords );
result = mouseCoords.x + mouseCoords.y;


When I extract the three last lines into a new method, I get this :

int MyClass::MyMethod( int result )
{
	POINT mouseCoords;
	GetCursorPos ( &mouseCoords );
	result = mouseCoords.x + mouseCoords.y;	return result;
}


Where the result variable is also passed as argument. This is annoying to correct it by hand each time I use this feature.

Also note that the "return result;" statement is not on a new line. Even if my "Refactor Extract Method" snippet seems ok :

$end$$SymbolType$ $SymbolContext$( $ParameterList$ ) $MethodQualifier$
{
	$MethodBody$
}


Thanks you for your time.
1   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Mar 30 2012 : 5:09:21 PM
When you select this code to extract it, are you selecting the end of line on the 3rd line, or not? If you don't select the end of line on the 3rd line then this formatting is the expected result.

If you just place the caret in the first column, then use Shift + Down Arrow 3 times to select the 3 full lines, and then select the code, then the return statement is placed on its own line, as you are expecting.

"result" being passed as a parameter here, in general what are you hoping for? Since this local variable is used in the extracted code, it is reasonable to pass the variable as a parameter. Here we can see that the variable is not used, but in general it is not so easy to tell if a variable is used / queried in a block of code or not. So VA is playing safe.

If we determine that the item is never being queried then creating it as a new local variable in the extracted function should be possible. Is this what you are looking for?

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000