Geertjan's Blog

  • May 13, 2012

"Extract Method" Functionality in NetBeans?

Geertjan Wielenga
Product Manager

Why does NetBeans IDE not have "extract method" functionality?

Well, as Ralph from the NetBeans Team points out, it's as simple as using Alt-Shift-M. For example, here's a big chunk of code in the constructor of the Anagram Game (which is one of the samples in NetBeans IDE):

That big chunk of code deserves its own separate method. So, as you can see, I select it all with my mouse and then I press Alt-Shift-M (or Refactor | Introduce Method), which causes the "Introduce Method" dialog to be displayed, as shown below, where I type "postInitializeGUI", as you can see below:

I click OK in the dialog above. And now the constructor contains a new reference to a method...

...which is defined elsewhere in the code:

Hurray, again, for NetBeans IDE!

Join the discussion

Comments ( 7 )
  • guest Sunday, May 13, 2012

    I've been using Netbeans for years and never knew about this. Another excellent feature in the best Java IDE out there. Thanks for the tip!

  • guest Monday, May 14, 2012

    I blogged about the cool "extract method" functionality in NetBeans IDE sometime back as well :)


  • guest Monday, May 14, 2012

    It could be more useful if it made me set up the argument list.

  • guest Monday, May 14, 2012

    It actually is available in the "lightbulb menu" when you highlight block of code - usually as the last position. Feature is there from as long as I remember.

    It will also replace other occurences (but not very well ;] - only simplest cases) and will introduce necesary variables when used.

    The only problem is that it will not try to look up for object containing all necesary information in scope - it will always produce method with most basic possible parameters (and high amount of those in consequence).

  • guest Monday, May 21, 2012

    I'm writing C++ using netbeans 7.1.2. If I select a chunk of code and right-click Refactor->Introduce Method all the fields are greyed out: Introduce Variable, Introduce Constant, Introduce Field, Introduce Method.

    Surely this feature isn't used only in the context of Java?!

    Can someone help me figure out how to make use of this feature?

    Thanks much!

  • guest Thursday, March 5, 2015

    how to extract features from a given url in netbeans.

    eg: if i give http://www.some@url_name.com means it should extract the features from the domain name some@url_name. it contain _ and @ symbol in it. it should check like more features of url and implement using c4.5 classifier algorithm.

  • guest Saturday, January 21, 2017

    There is no extract for PHP

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