Inline Refactoring by Student from Amsterdam

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.

Comments:

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

Posted by Subhajit DasGupta on April 20, 2009 at 10:21 PM PDT #

Fantastic :D

Posted by Varun Nischal on April 21, 2009 at 06:11 PM PDT #

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

Posted by blah on April 22, 2009 at 07:45 AM PDT #

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.

Posted by V on April 23, 2009 at 08:29 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today