X

Geertjan's Blog

  • April 21, 2009

Inline Refactoring by Student from Amsterdam

Geertjan Wielenga
Product Manager
One of the best things about giving NetBeans Platform Certified Trainings is that there's always someone in the class who has some experience with the NetBeans APIs already. At the recent training in Amsterdam, that person was Ralph Benjamin Ruijs, together with Ingmar and Mark, who created a very cool refactoring plugin for NetBeans IDE.

Here he is, in the pics from yesterday, demonstrating the plugin to the whole class, which is another very cool thing on these trainings, i.e., when one or two of the students show things they've already achieved with the NetBeans APIs:

By the way, together with Richard de Koning, their instructor, this group is probably the most knowledgeable refactoring gurus you're likely to find anywhere—they've read all the available information on the topic, compared all refactorings everywhere in all IDEs, etc, have written papers on the topic, and so on.

Anyway, here's a quick demo of the refactoring that Ralph made. Let's say your class looks like this:

You decide to make a constant out of the "hello" text, so that it is defined at the top of the class and you can use the constant instead. So, you select the text and you then use the "Introduce Constant" refactoring in NetBeans IDE to define a constant:

Now you have a constant at the top of the class and you can use it elsewhere in your code, so that you only need to change the text "hello" in one place, should you need to do so:

Now... this is where Ralph's refactoring comes in. What happens if you change your mind and you don't want a constant after all? You can't use "Undo" anymore, because you're much further into your coding. The "Undo" action would only undo the last done code, so would be useless in reverting to the situation where you didn't have a constant and where the text is inlined into the code itself, as it initially was.

Therefore, Ralph created the "Inline" refactoring. Below, I select the constant, I choose Refactoring | Inline (which was created by Ralph) and then the dialog tells me what will be affected (and I can also use the Preview, as with any other refactoring):

Next, when I click the "Refactor" button above, my code will look like this:

Not bad! When will you contribute this refactoring to the NetBeans sources, Ralph? In any case, this is really cool and makes you a "NetBeans Platform Certified Engineer". When I get back from my vacation, I will send you a new certificate.

Join the discussion

Comments ( 4 )
  • Subhajit DasGupta Tuesday, April 21, 2009

    Hi, I am a regular reader of your blog. Very good work.

    By the way, refactoring (by Inlining) is available in Eclipse 3.4.2 (and perhaps in earlier versions as well). Just fyi...


  • Varun Nischal Wednesday, April 22, 2009

    Fantastic :D


  • blah Wednesday, April 22, 2009

    When are format all and fix all imports going to be added? Thats really important and missing.


  • V Friday, April 24, 2009

    Inlining a often underestimated refactoring.

    It's available in Eclipse already in "2.1.2" (currently using it daily [urgh, NetWeaver Dev Studio]).

    IntelliJ IDEA has inlining too, already for a long time.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.