Vincent Rischmann
Vincent Rischmann

Reputation: 122

Is it possible to automatically create a local variable from a method with IDEA

Suppose I have an object of class RandomClass with a method doStuff() which returns an int.

I'd like to do something like this:

Right now I do that by first typing myObject.doStuff(), use Alt+enter to popup the "Introduce local variable" menu and then use that.

Can I do that faster ?

Thanks.

Upvotes: 2

Views: 340

Answers (2)

maba
maba

Reputation: 48045

You can type myObject.doStuff() and then press Ctrl+Alt+V to immediately create the local variable. You will directly bypass the pop-up and that is really all you gain.

You can simplify the key mapping to reduce the number of keys to press for the Extract Variable if it is really necessary.

Upvotes: 2

vikingsteve
vikingsteve

Reputation: 40378

Generally, no, that's the quickest way to do it.

Given that the doStuff method already exists, I could do what you described with 6 keypresses in about a second and a half. That's pretty quick, I would think...

On the other hand, if it's boilerplate code that you'll be typing over and over, you could consider making a custom Live Template - hit ctrl-j and type something like sout or psvm to see some examples...

Good luck!

Upvotes: 1

Related Questions