Smarter and Faster Introduce Parameter in Java

As 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!

This entry was posted in New Features and tagged , , . Bookmark the permalink.

19 Responses to Smarter and Faster Introduce Parameter in Java

  1. Alexander says:

    Will be cool, if you’ll introduce Code Snippets Library integration with code completion, like Apple did in his last version of XCode 4.

  2. Cesar says:

    Is there a way to make the popup go away without using the mouse?

  3. Alexander T says:

    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!

  4. Anna Kozlova says:

    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

  5. Alexander T says:

    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

  6. 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.

  7. Anna Kozlova says:

    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

  8. 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.

  9. Anna Kozlova says:

    Volodymyr, fix for IDEA-67927 was backported in 10.5.1 branch and is available in build 107.148. Thanks

  10. 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.

  11. Anna Kozlova says:

    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

  12. 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.

  13. Anna Kozlova says:

    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

  14. Suresh says:

    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

  15. Anna Kozlova says:

    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.

  16. Anna Kozlova says:

    Yes, it contains the fix.
    Anna

  17. Suresh says:

    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

  18. Anna Kozlova says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>