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
 Feature Requests
 Introduce Variable for getter function
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic Next Topic  

DBlake
New Member

2 Posts

Posted - Jun 08 2025 :  02:38:33 AM  Show Profile  Reply with Quote
It happens very often, while refactoring someone else's code, when you need to simplify the expression for debugging and put the function value into the variable

 if (getParent()) {
   assert(!getParent()->findChildById(newId) ||| getParent()->findChildById(newId) == this);

Previously, a few years ago, when you selected the first getParent() statement and chose Introduce Variable, the VA offered the choice of
`Replace selection` or `Replace 3 occurencess`, and then I replaced them all to get this:

 Node* parent = getParent();
 if (parent) {
   assert(! parent->findChildById(newId) || parent->findChildById(newId) == this); 

This was very handy because I know that my getParent always returns the same value.
Now VA doesn't offer to replace them all, but only one value, and that's annoying.

As a workaround I found a way out, I select only `getParent` without brackets (), and then it replaces them all, but I have to remove extra brackets in the code manually, which is not very convenient.
I would like you to return the ability to cache the return value of functions into a variable.

feline
Whole Tomato Software

United Kingdom
19185 Posts

Posted - Jun 10 2025 :  1:10:14 PM  Show Profile  Reply with Quote
Introduce Variable offers to replace all instances in some situations, but not in this situation. But as you say, go back to an old version of VA, and it did offer.

Seems like a bug to me, so I have put in a bug report for this:

case=165858

zen is the art of being at one with the two'ness
Go to Top of Page
   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