Introduce Parameter Quick Fix Doesn't Adjust Callers

1) Inside of Method A, reference a non-existent variable
2) Click the resulting red squiggly line. From the quick fix menu, choose
"Introduce Parameter"
3) The non-existent variable is introduced as a parameter into method A, but
the callers are not adjusted

Instead, what I have always had to do is choose "Introduce variable", click
the squiggly and choose "Initialize variable", and then use the
Refactor->Introduce Parameter command.

Why not do this for me? And at any rate, is the Introduce parameter quick
fix meant only to be useful if nobody calls the method you're introducing
the parameter into?

--
John

3 comments

"And at any rate, is the Introduce parameter quick fix meant only to be useful if nobody calls the method you're introducing the parameter into?"

It works when the method has caller(s). Quite well, in fact. I find it to be a very handy tool for
- taking two (or more) similar blocks of code
- performing extract method refactorings on them, introducing parameters, renaming things, addressing inconsistencies with conditional behaviour, etc. until the extracted methods are completely identical
- taking all but one of the methods and changing them to simply delegate to the one
- inlining all of those delegating methods into their callers.

Sounds like a lot of steps but once you get into the swing of it it can be really quite quick to tear through and the results are really nice.

0

"Jeremy Gray" <no_reply@jetbrains.com> wrote in message
news:23589854.27331218675816554.JavaMail.jive@app4.labs.intellij.net...

"And at any rate, is the Introduce parameter quick fix meant only to be
useful if nobody calls the method you're introducing the parameter into?"

>

It works when the method has caller(s). Quite well, in fact. I find it to
be a very handy tool for
- taking two (or more) similar blocks of code
- performing extract method refactorings on them, introducing parameters,
renaming things, addressing inconsistencies with conditional behaviour,
etc. until the extracted methods are completely identical
- taking all but one of the methods and changing them to simply delegate
to the one
- inlining all of those delegating methods into their callers.

>

Sounds like a lot of steps but once you get into the swing of it it can be
really quite quick to tear through and the results are really nice.


Sorry, I guess I wasn't clear. I don't mean the Introduce Parameter command,
which I use all the time. I mean the quick fix that you get if you reference
an undefined variable.

Before:

void Foo()
{
Bar();
}

void Bar()
{
int dummy = Zap(undefined);
}

void Zap(int defineIt)
{
}

"undefined" will appear with a red squiggly line. Click on "undefined" and a
lightbulb will appear. One choice in the list is "introduce parameter".
Doing that creates:

void Foo()
{
Bar();
}

void Bar(int undefined)
{
int dummy = Zap(undefined);
}

void Zap(int defineIt)
{
}

--
John Saunders | MVP - Connected System Developer

P.S. At least I hope this is accurate. I just shut down Visual Studio and I
am not trying to do more work tonight, so I just hope I remember
correctly.


0

That is the behavior I figured you meant, and yeah that does look like a R# bug to me. At the very least you should get prompted for a type and a default value to place at the call sites and then it should, well, work. ;)

0

Please sign in to leave a comment.