Author |
Topic |
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Aug 23 2006 : 09:45:18 AM
|
I tried Extract Method on a piece of code containing some local variables. The variables were STL strings: string strMyString1 = "Some funny stuff.";
string strMyString2 = "More funny stuff.";
string strMyString3 = "Most funny stuff."; The result was that I got a function containing the parameter const string& string. Just try Extract Method on the lines above an you will get: void MyMethod(const string& string) I'm not sure if this behavior is intended, but for the example above I await either zero or three parameters. The variable name "string" doesn't look correct to me as well.
Regards, Marcus. |
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Aug 24 2006 : 12:51:16 AM
|
Strange. Using VC6 and VAX 1532 and the following code:
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
string strMyString1 = "Some funny stuff.";
string strMyString2 = "More funny stuff.";
string strMyString3 = "Most funny stuff.";
cout << strMyString1 << endl;
cout << strMyString2 << endl;
cout << strMyString3 << endl;
return 0;
}
I get void MyMethod() for the extracted function. Still not right, but different as can be. I added the cout statements to use the strings after the extracted method, since without them, there is no reason for the method to return the values in any means.
What other code (close, relevant) do you have around this code? |
Joe Pizzi |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Aug 24 2006 : 03:48:23 AM
|
Ok, that's another hard one. I'm poking around for an hour now and I'm not able to reproduce it on a new project. I can't spend more time on it at the moment. However, I found a pattern in my current "real" project. I pasted the lines above into several functions and I only get the const string& string argument extracted when the signature of a function contains a const string& argument. For example: bool MyClass::bBlah(const string& strBlub)
{
string strMyString1 = "Some funny stuff.";
string strMyString2 = "More funny stuff.";
string strMyString3 = "Most funny stuff.";
...
return false;
} It doesn't matter if the function has additional arguments, but if I remove the const everything works fine (i.e., Extract Method creates a function with no arguments at all).
I don't know if this is of any help...
Regards, Marcus.
|
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Aug 25 2006 : 6:14:21 PM
|
OK. Added a case for my revelation.
case=2246
Even placing the code into the method you give, gives me the same results (mine, not yours). Wonder what is going on? |
Joe Pizzi |
Edited by - jpizzi on Aug 25 2006 6:17:08 PM |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Aug 28 2006 : 02:47:31 AM
|
I'm glad that you can reproduce it. Thank you for testing it, Joe!
Regards, Marcus. |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Aug 29 2006 : 01:33:46 AM
|
I was not able to reproduce the behavior that you saw. What I entered as a bug was the void function with an empty parameter list, which is what I get no matter the context of where I try it.
I am still looking to see if and how I can see what you are getting (unless you believe that the fix for my seemingly different behavior will fix the behavior that you are seeing). |
Joe Pizzi |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Aug 29 2006 : 02:42:30 AM
|
I'm sorry for misunderstanding you. I just did some more tests on: void F(const string& str1, string str2)
{
const string str3 = str2;
const string str4 = str1;
} Not all of the tests make sense, but maybe it helps you to find a pattern:Extract: const string str3 = str2;
Result: void MyMethod(const string& string, string str2)
Extract: string str3 = str2;
Result: void MyMethod(const string& string, string str2)
Extract: str3 = str2;
Result: void MyMethod(string str2)
Extract: const string str4 = str1;
Result: void MyMethod(const string& string, const string& str1)
Extract: string str4 = str1;
Result: void MyMethod(const string& string, const string& str1)
Extract: str4 = str1;
Result: void MyMethod(const string& str1) Regards, Marcus. |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Aug 29 2006 : 11:46:52 PM
|
Still not very much in common. Here is my entire file:
// testva.cpp : Defines the entry point for the console application.
//
// #include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
return 0;
}
void F(const string& str1, string str2)
{
const string str3 = str2;
const string str4 = str1;
}
Here are my results:
Extract: const string str3 = str2;
Result: void MyMethod(string str2)
Extract: string str3 = str2;
Result: void MyMethod(string str2)
Extract: str3 = str2;
Result: void MyMethod(string str2)
Extract: const string str4 = str1;
Result: void MyMethod(const string& str1)
Extract: string str4 = str1;
Result: void MyMethod(const string& str1)
Extract: str4 = str1;
Result: void MyMethod(const string& str1)
Is it possible that you changed the autotext entry for Refactor Extract Method and don't remember? Here is my entry:
$end$$SymbolType$ $SymbolContext$( $ParameterList$ )
{
$MethodBody$
}
If not, lets get the dump from Visual Assist X, Options, About. We'll try to track down what is different between our setups. |
Joe Pizzi |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Aug 30 2006 : 02:21:21 AM
|
Yes, I changed the autotext entry, but I don't think that it matters:
$end$$SymbolType$ $SymbolContext$($ParameterList$)
{
$MethodBody$
} As I already mentioned, I can't reproduce it on a new/small project. It happens only in my "real" project. Anyway, here's my dump:
VA_X.dll file version 10.3.1533.0 built 2006.08.23 Licensed to: VA X: [email protected] (8-user license) Support ends 2007.02.23 VAOpsWin.dll version 1.3.3.6 VATE.dll version 1.0.5.8 MSDev.exe version 6.0.9782.2 Devshl.dll version 6.0.9782.0 Devedit.pkg version 6.0.9782.0 Font: Courier -13(Pixels) Comctl32.dll version 5.82.2900.2180 Windows XP 5.1 Build 2600 Service Pack 2 2 processors
Platform: Win32 (x86) Stable Includes: C:\\Program Files\\directX8.1SDK\\include; C:\\Program Files\\Microsoft SDK\\Include; C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE; C:\\Program Files\\Microsoft Visual Studio\\VC98\\MFC\\INCLUDE; C:\\Program Files\\Microsoft Visual Studio\\VC98\\ATL\\INCLUDE; C:\\Program Files\\Mercury\\OIV5.0\\include;
Library Includes: C:\\Program Files\\Microsoft Visual Studio\\VC98\\MFC\\SRC; C:\\Program Files\\Microsoft Visual Studio\\VC98\\MFC\\INCLUDE; C:\\Program Files\\Microsoft Visual Studio\\VC98\\ATL\\INCLUDE; C:\\Program Files\\Microsoft Visual Studio\\VC98\\CRT\\SRC;
Other Includes:
Regards, Marcus. |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Oct 09 2006 : 6:42:10 PM
|
have you had chance to try 1538 yet? have you had this problem with the last couple of builds of VA? |
zen is the art of being at one with the two'ness |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Oct 09 2006 : 11:46:09 PM
|
My apologies. I appear to have dropped the ball on this one. Is this still happening for you, Marcus? |
Joe Pizzi |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Oct 10 2006 : 02:15:56 AM
|
This problem still appears in 1538. I just tried the function again I posted before. Still same result.
Regards, Marcus. |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Oct 10 2006 : 08:24:18 AM
|
if you place the caret in "string" in your real project what do you see in the VA wizard bar? using a very simple test project, VC6, VA 1538, i am getting:
context field = std.string definition field = typedef basic_string<char, char_traits<char>, allocator<char> > string
and alt-g on "string" offers me two entries:
xstring:612 visual assist x\\misc\\stdafx.h:277
i am wondering if there is something in your real project that VA thinks is redefining "string". this might explain why you are seeing such different results. |
zen is the art of being at one with the two'ness |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Oct 13 2006 : 01:27:37 AM
|
If I have stdafx.h included, the results are quite different. Does your project use stdafx.h, and if so, what are its contents?
My stdafx.h is the boiler-plate one created by the wizard:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__C6341DFD_4789_4FBD_ABD1_0A01AA680CB6__INCLUDED_)
#define AFX_STDAFX_H__C6341DFD_4789_4FBD_ABD1_0A01AA680CB6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__C6341DFD_4789_4FBD_ABD1_0A01AA680CB6__INCLUDED_)
I don't see how this should change things, but it does. |
Joe Pizzi |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Oct 13 2006 : 05:26:53 AM
|
@feline: Sorry for my late reply. I somehow missed your message. However, I get exactly what you see.
@joe: Yes, I have a stdafx.h file included. And it also includes only the wizard generated stuff:#if !defined(AFX_STDAFX_H__D8CECEFD_BCB1_4BD4_9528_1ABE0064394B__INCLUDED_)
#define AFX_STDAFX_H__D8CECEFD_BCB1_4BD4_9528_1ABE0064394B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN
#include <afxwin.h>
#include <afxext.h>
#include <afxdtctl.h>
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
#endif // !defined(AFX_STDAFX_H__D8CECEFD_BCB1_4BD4_9528_1ABE0064394B__INCLUDED_) I just left out some comments for the sake of clarity.
By the way, it happens in 1539, too.
Regards, Marcus. |
Edited by - khb on Oct 13 2006 05:32:41 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Oct 13 2006 : 08:32:01 AM
|
khb do you have time to try a fairly quick experiment?
if you add a new, blank cpp file to your main project and then copy / paste jpizzi's source code, from his "Aug 29 2006" post into it, what happens?
clearly something in your main project is important, but what? If extract method works as expected here then this suggests it is one of your #includes. |
zen is the art of being at one with the two'ness |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Oct 13 2006 : 10:11:11 AM
|
Ok, I created an empty cpp file and added it to my project. I added the code from Joe's post. I marked the line: const string str3 = str2; and selected "Extract Method". The suggestion is still: void MyMethod(const string& string, string str2) So, it doesn't seem to result from an #include.
Regards, Marcus. |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Oct 13 2006 : 11:36:25 AM
|
do you have:
VA Options -> Environment -> Fonts and Colors -> Local symbols in Bold
turned on? I do and for me all 4 strX variables are shown in bold. when the definition of a variable Extract Method is supposed to assume this definition is being moved into the new function. it is almost as if Extract Method does not know that str3 is being defined on this line.
I have just done the same test here, and I get:
void MyMethod( string str2 )
as expected. using the original code, before you extracted the method, if you place the caret in "str3" and press alt-g what happens? I am taken to the first column on the same line.
I will ask around, and see if anyone has any ideas. |
zen is the art of being at one with the two'ness |
Edited by - feline on Oct 13 2006 11:37:14 AM |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Oct 13 2006 : 11:05:31 PM
|
Looking at your stdafx.h file, I see that you have an MFC project. I was trying a Console application.
Pasting the code from Aug 29, 2006 into a cpp file in an (existing) MFC application, once I get:
Extract: const string str3 = str2;
Result: bool MyMethod(const string &str3, string str2 )
I accidently accepted that refactoring. I then did undo to get back to the original code, and if I repeat that refactoring, I am back to my original behavior. *sigh*
I am completely at a loss on this one. Time to get a developer to peer at this one and see if they have any clues. |
Joe Pizzi |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Oct 13 2006 : 11:10:49 PM
|
I just reverted all changes, closed and reopened VC6. Using VAX 1538, if I try the first refactoring WITHOUT selecting the ending semicolon, I am back to the bool method with two parameters. Once I try to do a refactoring (same line) WITH selecting the semicolon, it changes the behavior back to a void method with one parameter. AND, I can no longer get the bool method to display again.
|
Joe Pizzi |
|
|
jpizzi
Tomato Guru
USA
642 Posts |
Posted - Oct 14 2006 : 12:41:00 AM
|
OK. After getting a fresh IDE start (but, using the existing project), here is what I get:
Extract: string str3 = str2
Result: bool MyMethod(const string &str3, string str2)
Extract: str3 = str2
Result: bool MyMethod(const string &str3, string str2)
Extract: const string str4 = str1
Result: bool MyMethod(const string &str4, const string& str1)
Extract: string str4 = str1
Result: bool MyMethod(const string &str4, const string& str1)
Extract: str4 = str1
Result: bool MyMethod(const string &str4, const string& str1) And, if I select the semicolon along with any of the str4 selections, I get:
void MyMethod(const string& str1)
case=3016 |
Joe Pizzi |
Edited by - jpizzi on Oct 14 2006 12:43:29 AM |
|
|
khb
Tomato Guru
Germany
337 Posts |
Posted - Oct 16 2006 : 02:35:25 AM
|
@feline: Normally, I don't have "Local symbols in Bold" activated, but if I do, then all four string variables are shown in bold. And if I press alt-g when the caret is on "str3", then I'm also taken to the first column on the same line.
@joe: I'm very sorry that I forgot to mention that I'm having an MFC project. Stupid me!
Regards, Marcus. |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Oct 16 2006 : 11:19:38 AM
|
don't worry about forgetting it is MFC, sometimes finding the correct tiny detail to reproduce a bug just takes an age |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|