Question

I am using Visual Assist X in Visual Studio 2008. I am defining a bunch of forward declaration files, all of which have basically the same format:

namespace ns1 { namespace ns2 {
    class SampleClassName;
    boost::shared_ptr<SampleClassName> SampleClassNamePtr;
}}

Obviously, I'm also putting in a header guard, a generated file comment, and other things as required by our coding standard (and the namespaces aren't placeholders).

Here's the issue: we name these files SampleClassNameForward.h so using the $FILE_BASE$ placeholder won't exactly work. Is there a way for me to apply a regex and remove the "Forward" from $FILE_BASE$ after it has been expanded, but prior to the snippet being pasted into my file? If I could do that, then I could fully automate generating these forward declarations and save myself (and my colleagues) a ton of time.

Was it helpful?

Solution

No, Visual Assist does not have any tools that would support regex modification of the file name as you are looking to do.

An alternative approach would be to create a VA Snippet that you use to create the block of code in a temporary file.

  • Create a VA Snippet that has all the boilerplate code.
  • add $SymbolName$Forward.h to the top of the code.
  • Invoke the snippet in the empty temporary file.
  • Cut the generated FooForward.h text at the top of the editor.
  • Select all (ctrl+a).
  • Invoke VAssistX | Refactoring | Move Selection to New File
  • At that point you would be prompted for the name of the new file and can paste the previously cut text (FooForward.h).

Move Selection To New File will create the new file in the same directory as the current file and add it to the same projects it is in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top