Inline Refactoring by Student from Amsterdam
By Geertjan-Oracle on Apr 20, 2009
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.