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 byi
)SuperSecret
(I will replace this byXX02
)launch
(I will replace this byll03
)Rocket
(I will replace this byR004
)Stuff
(I will replace this byS555
)
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
becomesStuff
againR004
becomesRocket
ll03
islaunch
XX02
returns toSuperSecret
BS001
is reversed toBusinessStuff
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.