Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Refactor extract method
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Alexis Pautrot
Junior Member

21 Posts

Posted - Mar 29 2012 :  09:03:08 AM  Show Profile  Reply with Quote
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.

Edited by - Alexis Pautrot on Mar 29 2012 09:03:40 AM

feline
Whole Tomato Software

United Kingdom
19023 Posts

Posted - Mar 30 2012 :  5:09:21 PM  Show Profile  Reply with Quote
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?

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000