Smarter and Faster Introduce Parameter in Java
March 24th, 2011 by Anna KozlovaAs a logical next step after inplace introduce variable refactoring we did in IntelliJ IDEA 10, version 10.5 will offer inplace introduce parameter.
Here is a brief overview of what we’re working on.
Once called, it will gently ask you to choose a method you want to add parameter to

Note, that you can introduce parameter in hierarchy by selecting the “Use super method of” option.
Then you’ll get a familiar template-like editor with a possibility to change parameter type and name. The refactoring settings you’ve got used to have in the dialog, are now available during template editing. You can make the parameter final, and generate method delegate, to remove unused parameters and replace field usages with getters. When multiple occurrences found you will be able to replace all of them or decide to replace only one right in place. No need to rerun the refactoring to see the results — they are already in the editor.

All method usages are already processed once you finish typing.

Just make sure you have inplace refactoring enabled in ‘IDE Settings | Editor | Enable in place refactorings‘.
The feature will be available in IntelliJ IDEA 10.5 EAP.
Watch our progress on inplace refactorings and let us know what you think!
Tags: Java, Refactoring, Xena

March 24th, 2011 at 10:56 am
Will be cool, if you’ll introduce Code Snippets Library integration with code completion, like Apple did in his last version of XCode 4.
May 17th, 2011 at 8:14 am
Is there a way to make the popup go away without using the mouse?
May 25th, 2011 at 5:27 am
Have you seriously introduced this feature without making sure you can navigate the dialog without using a mouse? Can you not even make it go away? In that case my productivity just dropped significantly!
May 26th, 2011 at 4:28 am
It must be a bug as we checked that it works without mouse at least on Windows and Linux. Could you please be more specific and file a bug report?
Thank you
May 26th, 2011 at 9:21 am
Hi Anna,
I figured out after a while that the ’stuck dialog’ indeed is a bug, which occurs only during the ‘introduce parameter’ refactoring. For me it’s 100% reproducable, I will check with some colleagues and get back to you via a bug report.
I still haven’t figured out how to change the in-place settings with the keyboard, but it was easy enough to disable the in-place refactoring (Settings->Editor->Enable in place refactorings), so I am happy chappy again
Regards
May 27th, 2011 at 4:02 am
Here’s example:
/**
* @author Volodymyr Melymuka
* @since 27/05/11 11:44
*/
public class Bug {
Object o;
void doPrint(Object o) {
System.out.println(”o = ” + o.toString());
}
void printObject() {
doPrint(new Object());
}
}
/* end of Bug.java*/
# then in method doPrint(Object o) select o.toString()
# press Ctrl+Alt+P (introduce/extract Parameter)
# tooltip window pops up
# signature of doPrint() changes from original doPrint(Object o) to doPrint(Object o, String s)
# in tooltip check ‘Remove parameter ‘o’ no longer used’ -> the signature does not change
# in previous versions of IDEA (or with ‘inplace refactorings -> disabled’ a change happens for method printObject() from
void printObject() {
doPrint(new Object());
}
to
void printObject() {
final Object o1 = new Object();
doPrint(o1.toString());
}
# in IDEA 10.5UE with ‘inplace refactorings -> enabled’ above change does not happen having left code in non compilable state.
# The tooltip window never goes away.
##—————-
So for now ‘introduce parameter’ works 100% wrong and is unusable forcing me to disable ‘inplace refactorings’ for a time when I need to do parameter extracting.
p.s. All other inplace refactorings (variable/method renamings) work perfectly.
June 1st, 2011 at 4:48 am
Volodymyr, I’ve checked the example and it works for me here. Actually parameter would be deleted only on template close (on tab or enter). If it doesn’t occur, most probably that that is a bug which was already fixed in the latest IDEA 10.5.1 EAP. Could you please try it and if it would be still reproducible, file a bug? Thank you
June 2nd, 2011 at 7:27 am
Anna, thanks for your feedback! I’ll definitely try it and will reply here.
BTW later I’ve found issue that seems similar in http://youtrack.jetbrains.net/issue/IDEA-67927 being fixed in rev.108.258 . And current latest 10.5.1 EAP build rev. is 107.148 (taken from here: http://confluence.jetbrains.net/display/IDEADEV/IDEA+10.5+EAP ) - so maybe I won’t get mentioned bug fixed in 10.5.1 EAP. I’ll try anyway.
June 2nd, 2011 at 7:49 am
Volodymyr, fix for IDEA-67927 was backported in 10.5.1 branch and is available in build 107.148. Thanks
June 3rd, 2011 at 7:08 am
Anna, I tried 107.148 and can say that now behavior is as follows:
IDEA 10.5.1 EAP XENA 107.148
Action - introduce new parameter with removing not used one:
void doPrint(Object o) {
System.out.println(”o = ” + o.toString());
}
———-
I select o.toString() and hit Ctrl+Alt+P
———-
Problem happens with these prerequisites:
1)’inplace reactorings’ are enabled
2)Spring Support plugin is turned on
3)At least one Spring facet is registered in project.
! Please note that without point number 3 everything works perfectly !
So if I register at least one Spring facet - inplace parameter refactoring fails in 10.5 or causes modal window in 10.5.1 (107.148)
If I then delete all Spring facets from project - inplace parameter refactoring starts working as it should (described in first post)
–
Should I reopen the bug or file a new one?
Thank you for your answer.
June 3rd, 2011 at 7:33 am
No, actually it is by design that modal dialog is opened in 10.5.1. I hope that IDEA 11 would have better solution for the problem (we are going to redesign inplace introduces anyway). Thank you
June 7th, 2011 at 6:43 am
Anna, is it really by design that when you have at least one Spring facet configured - in-place refactoring fails and is being replaced by modal window? And in case of no Spring facets in-place refactoring works plain and smooth?
Thank you for your answer.
June 7th, 2011 at 6:57 am
Yes, that is the correct behaviour for now. We already have nearly the same situation with inplace rename: you are able to rename variable inplace but that is not possible with field or method - dialog is shown instead. I hope that it would be changed in IDEA 11. Thanks
June 7th, 2011 at 7:42 pm
I am using
#IU107.105 May16th Build , MAC
This refactoring doesnt work as described for me anymore
void function() {
System.out.println(”constant”);
}
when i highlight the “constant” and hit command alt p, I a var defined in the function but it doesn’t replace the “constant” with the variable.
anyone else facing this?
Thanks,
Suresh
June 8th, 2011 at 2:38 am
Suresh, that is most probably the bug http://youtrack.jetbrains.net/issue/IDEA-67927. It is already fixed in the latest 10.5.1 EAP. As workaround (before 10.5.1 is out) you may disable inplace refactorings in File|Settings|Editor. There are other options to workaround, please see corresponding bug comments and comments here. Sorry for the inconvenience.
June 8th, 2011 at 2:08 pm
thanks,
http://blogs.jetbrains.com/idea/2011/06/intellij-idea-1051-eap-build-107199-is-available/
does this have it?
Suresh
June 8th, 2011 at 2:10 pm
Yes, it contains the fix.
Anna
June 8th, 2011 at 2:23 pm
yeah just downloaded it and tested it, the refactoring isnt inplace anymore, was it more of a revert than fix?. neways that works for me for now
thanks,
Suresh
June 9th, 2011 at 1:31 am
The inplace refactoring was disabled for some configurations, e.g. when there is a Spring Facet with configured aop pointcuts. That should be changed in the upcoming IDEA 11 release. Thank you