Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Refactoring: extract typedef

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
Rain Dog Posted - Sep 22 2008 : 5:47:45 PM
This would be good if we could extract typedef's.

Also, if we could refactor usages of certain types, say we want to search for all occurrances of the type std::vector< std::pair<mytype1, mytype2> > and replace it with a std::map<mytype1, mytype2>
12   L A T E S T    R E P L I E S    (Newest First)
andre.horst Posted - Oct 01 2008 : 02:57:13 AM
Hum...maybe we are don't talking about the same thing. I never used to change (raname or find) types, f.e. to find all occurances of "std::vector< int >" and replace it with "std::vector< double >" or replace it with a adequat typedef. That could be usefull, but hard to control, maybe a limit to current project/h+cpp may be required and therefor a search and replace will do the job.

What i want is to create a typedef of a selection, f.e. select the following line in class CTypes declaration:

void MyFunc( void ) ;

and the "Crete typedef" will result in:

typedef void (CTypes::*t_fpMyFunc)( void ) ;
void MyFunc( void ) ;


As you can see, thats not only copy and paste text. Creating typedefs of selections can be very usefull. It's always hard to create typedefs of function/methods with several arguments (especially function/method pointers). Creating simple typedefs f.e.

std::vector< int > m_vecMyInts ;

with a snippet is simple, but a direct avaiable menu-item in the refactor menu would be nice.
feline Posted - Sep 30 2008 : 2:34:30 PM
I don't understand, and I suspect we are talking about totally different things. Can you post a before and after example, including the typedef line, so I can try and work out what you are talking about? Hopefully then we can start talking about the same thing
andre.horst Posted - Sep 30 2008 : 10:19:29 AM
Refactoring is most of the time cut/copy here and paste there and modify a little bit...Such refactoring features like "Create Implementation" demonstrates that. A refactoring tool should support and optimize thees operations. The best refactoring feature in VAX is the rename-feature, that goes far beyond normal search-and-replace.

Nethertheless it would be just nice if VAX can create typedefs of selections, regardless what is selected (functions, methods, templates, aso). Otherwise I have to use "my hands"

I cannot see how i can use a snippet to create a typedef of a selected method/function!? Maybe you can post a usefull snippet for creating typedefs of a selected method (f.e. the DoSomethingWithMyFunc2-method in my example)... Creating typedefs of simple types can be done easily with the snipped u posted or just copy and paste...
feline Posted - Sep 30 2008 : 08:21:07 AM
andre.horst I am not quite sure what you are getting at here. To "simply" extract a piece of code and introduce a typedef WITHOUT making any other changes to the code should be simple. If the two types are functionally identical then this is fine. A VA Snippet should help with the extraction, or you can use the IDE's find and replace dialog.

However if you are talking about changing the type, so the code that uses variables of these types has to be changed then this is probably beyond VA's scope anyway.

After all, you could be changing int into std::string. In "general" this is something you have to do by hand, since you can replace anything with anything.
andre.horst Posted - Sep 29 2008 : 09:06:00 AM
Or a bit more complex, refactoring this

void Hardcore( void(CTypes::*p_fpHardcore)( t_fpMyFunc ) )
{
(*this.*p_fpHardcore)( &CTypes::MyFunc ) ;
}

By the way...it will be pretty hard to parse those expressions right, especially if only parts of them are selected that should be refactored to a type.
andre.horst Posted - Sep 29 2008 : 08:58:18 AM
Probably places for refactoring are marked red.

class CTypes
{
public:
typedef void (CTypes::*t_fpMyFunc)( void ) ;

void MyFunc( void )
{
}

void DoSomthingWithMyFunc( t_fpMyFunc p_fpMyFunc )
{
(*this.*p_fpMyFunc)() ;
}

void DoSomethingWithMyFunc2( void (CTypes::*p_fpMyFunc)(void) )
{
(*this.*p_fpMyFunc)() ;
}
} ;
feline Posted - Sep 29 2008 : 06:17:16 AM
You could do this with an IDE macro. Select the type to extract, then trigger a macro that:

* copies the selected text
* prompt you for the typedef name
* trigger a find and replace across all files
* insert the typedef statement

The IDE macro can then be bound to a keyboard shortcut, or you can add a menu item for it.

You can use the code:

Dim sNewType As String = InputBox("The name of the typedef", "New typedef")

in a VS2005 IDE macro to prompt for information.

This has the advantage that it can be done now. Its main problem is how accurate / useful the IDE's find and replace will be.
Rain Dog Posted - Sep 26 2008 : 2:42:46 PM
I would like the replacement to be more than just local to the file. In a lot of cases the types are just containers that happen to have really long definitions that I suppose a solution wide find/replace would be adequate, but i would like just to be able to bring up a context menu at a variable declaration and have a refactoring option of "extract typedef" as it is a little more convenient.
feline Posted - Sep 25 2008 : 08:02:38 AM
andre.horst can you post an example of what you are trying to do? I am not sure what you are talking about.

Rain Dog, if you really do want to do a simple search and replace, across an entire file, to replace one type with another type then the IDE find and replace dialog is an option. Introducing a typedef *may* be a case where this helps. Do you actually want to "just" replace the type across the entire file?

If so then what are you looking for above and beyond a "simple" find and replace?
Rain Dog Posted - Sep 24 2008 : 7:56:10 PM
oh wow, that's exactly what i need =)

And as far as search and replace goes, I could use search and replace for all refactorings... so why not just remove refactoring from the tool since it is so easily replaced...

andre.horst Posted - Sep 24 2008 : 03:45:09 AM
Refactoring typedefs sounds interesting. The snippet won't work for comlex types such as method or function typedefs even with complex arguments (f.e. functions or methods )
accord Posted - Sep 23 2008 : 1:57:11 PM
About extract typedef: did you see this thread?

http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=7954

About occurrences: are you talking about a variable with this type? If you want to replace a type to an another, a search and replace will do the job.

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