software development – Visual Studio Plugin for multi-replacement and un-replacement


I find AI helpful when it comes to source code refactoring. My company allows such tools only if I anonymize the code, i.e. I rename classes, function names, member variables and local variables if they are specific for our area of business. This restriction makes the use of AI almost impossible, if I need to do those changes manually. However, with the help of a replacement tool, that could become feasible.

Therefore, I am looking for

  • a Visual Studio (not Code) plugin
  • which lets me do a series of searches and replacements
  • and can later undo the replacements in opposite order
  • checks for overlaps in the searches and warns me about it or fixes the order
  • ideally: can generate replacements based on identifier rules

For sure the tool should

  • let me choose to ignore case or not (actually, that won’t work, if you think about it)
  • let me choose to match whole words or not

Let me give an example…

The original C# code may look like this:

class SuperSecret
{
    BusinessStuff _b;
    int n;
    static string launchCode = "0000"; // TODO: ask the president
    
    SuperSecret(BusinessStuff b)
    {
         _b = b;
    }
    
    void NobodyMayKnow()
    {
        for (int i=0; i<100; i++)
        {
            _b.HarmlessStuff();
        }
        _b.LaunchRocket(launchCode[0], launchCode[1], launchCode[2], launchCode[3]);
    }
}

Before I put this code into an AI, I need to replace the secret parts, e.g. I want to replace

  • SuperSecret
  • Stuff
  • launch
  • BusinessStuff
  • Rocket

Now, I should not replace Stuff by something else before I replaced BusinessStuff. Otherwise it won’t find BusinessStuff any more and the word Business might remain in the code. So the order should be sorted by length:

  • BusinessStuff (I want to replace this by i)
  • SuperSecret (I will replace this by XX02)
  • launch (I will replace this by ll03)
  • Rocket (I will replace this by R004)
  • Stuff (I will replace this by S555)

The tool now notices that i is not a safe replacement, because it can’t be undone without replacing other parts of the software. It suggests or let’s me enter BS001 instead.

Once everything is setup correctly, I press the “Do it now” button.

After the replacement, the code looks like

class XX02
{
    BS001 _b;
    int n;
    static string ll03Code = "0000"; // TODO: ask the president
    
    XX02(BS001 b)
    {
         _b = b;
    }
    
    void NobodyMayKnow()
    {
        for (int i=0; i<100; i++)
        {
            _b.HarmlessS555();
        }
        _b.LaunchR004(ll03Code[0], ll03Code[1], ll03Code[2], ll03Code[3]);
    }
}

With the help of AI, I refactor the last line to pass the launchCode string directly, instead of using individual characters

_b.LaunchR004(ll03Code);

In order to get my code back, the replacements are now reversed.

  • S555 becomes Stuff again
  • R004 becomes Rocket
  • ll03 is launch
  • XX02 returns to SuperSecret
  • BS001 is reversed to BusinessStuff

And this reversal should be as simple as clicking an “Undo it now” button.

I’m not working on rockets or missiles, this is just an example, because such things are obviously secret.



Source link

Related Posts

About The Author

Add Comment