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
 Move implementation to source file problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eve
Tomato Guru

Belgium
101 Posts

Posted - Oct 24 2007 :  07:42:18 AM  Show Profile  Reply with Quote
Hi,

I have a problem with the 'Move implementation to source file' refactoring:

--- mytest_testclass.h ---
namespace MYTEST {
   class TestClass {
      int testFunction1();
      int testfunction2() {
         return 2;
      }
   }; 
}

--- mytest_testclass.cpp ---
#include "mytest_testclass.h"

namespace MYTEST {
   class SomeForwardDeclaration;
}
   
using namespace MYTEST;

int TestClass::testFunction1() {
   return 1;
}

If I now apply 'move implementation' on testFunction2, then this is the result:

--- mytest_testclass.cpp ---
#include "mytest_testclass.h"

namespace MYTEST {
   class SomeForwardDeclaration;

   int TestClass::testfunction2() {
      return 2;
   }
}
   
using namespace MYTEST;

int TestClass::testFunction1() {
   return 1;
}

and not

--- mytest_testclass.cpp ---

#include "mytest_testclass.h"

namespace MYTEST {
   class SomeForwardDeclaration;
}
   
using namespace MYTEST;

int MYTEST::TestClass::testFunction1() {
   return 1;
}

I suppose this could be desired functionality, but this makes this (rather handy) refactoring unusable for me.

regards,
eli

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Oct 24 2007 :  08:17:28 AM  Show Profile  Reply with Quote
This happens because VA is designed to place the implementation into the namespace block, if one exists. In this case there are two valid locations to place the implementation, and VA has no way of knowing which one you want to use.

Here the solution will be to "hide" the code:

namespace MYTEST {
   class SomeForwardDeclaration;
}


from VA. This should work, but it is slightly messy. Change the cpp file to read:

#define START_HIDDEN_NAMESPACE(x) namespace x {
#define END_HIDDEN_NAMESPACE }

START_HIDDEN_NAMESPACE(MYTEST)
   class SomeForwardDeclaration;
END_HIDDEN_NAMESPACE


And add the following code to VA's stdafx.h file:

#define START_HIDDEN_NAMESPACE(x)
#define END_HIDDEN_NAMESPACE


as explained here:

http://docs.wholetomato.com?W302

I have not actually tested this exact case, but I have used this approach before quite successfully. The idea is that VA does not see the namespace block, so it never uses it. Hopefully this makes sense.

zen is the art of being at one with the two'ness
Go to Top of Page

eve
Tomato Guru

Belgium
101 Posts

Posted - Oct 24 2007 :  08:33:23 AM  Show Profile  Reply with Quote
It makes sense, but I don't intent to mutilate my code like that ;-)

Wouldn't it be possible to make that configurable? Maybe when you guys are working on the 'create implementation' order (case=2161), you could have a look at this at the same time...

thanks for the workaround though,
eli
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Oct 24 2007 :  08:45:51 AM  Show Profile  Reply with Quote
Are you using VA Outline? If so you can use VA Outline to drag (or use cut and paste) the new implementation to the required spot in the cpp file. You can also move several functions at one time.

zen is the art of being at one with the two'ness
Go to Top of Page

eve
Tomato Guru

Belgium
101 Posts

Posted - Oct 24 2007 :  08:51:39 AM  Show Profile  Reply with Quote
Nice, I did not know about that. Thanks!
It's still not perfect because my indentation is wrong:

before move:

namespace
   {
   void test {}
   }

someFunction()
   {
   }

after move:

namespace
   {
   }

   void test {}

someFunction()
   {
   }


Or maybe I should log that as a bug?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Oct 24 2007 :  1:47:20 PM  Show Profile  Reply with Quote
Try right click inside VA Outline -> Format

I am not sure if this is a bug or a feature, code formatting is a "tricky" area, so doing nothing is sometimes the best answer.

Did you drag and drop or cut and paste?
Do you have VA's format after paste turned on or off?

zen is the art of being at one with the two'ness
Go to Top of Page

eve
Tomato Guru

Belgium
101 Posts

Posted - Oct 25 2007 :  01:33:50 AM  Show Profile  Reply with Quote
It's a feature...
Enabling format after paste indeed solves the formatting problem, even when using drag and drop.

thanks for your help feline,
eli
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