I am trying to refactor a class that I have into 2 classes. Unfortunately eclipse's extract class function seems to only support the variables which really isn't all that helpful. Is there a way to extract the methods or is there a plugin that does it?
To extract method: Select a code fragment you want to extract to a method. Press Ctrl+Alt+M or from the main menu, select Refactor | Extract | Method. In the dialog that opens, configure a method options, such as visibility, parameters, and so on. You can also change a name of the method if you need.
-Or- press Ctrl+Shift+T (for a type) or Ctrl+Shift+M (for a method). The "Open Type/Method" dialog will appear. If a type/method was previously selected in the editor or outline views, it will be displayed.
Highlight a class name and select Refactor→ Extract Interface, or right-click the class name and select Refactor→ Extract Interface. Enter the name of the interface you want to extract, select the members to declare in the interface, and click OK.
Refactoring refers to the reshuffling of code to improve its style, design, etc. The outcome of running the code generally doesn't change as far as the user is concerned, but the guts under the hood do. I'm not going to deal with refactoring so much as particular refactoring tools in Eclipse.
One other solution is to CTRL C-CTRL V your class into another one, and start removing what you do not want...
You can select multiple elements in the outline view of the new class and select delete.
Crude but effective.
(source: eclipse.org)
The "Extract Superclass" refactoring is much more useful for this. It will allow you to pick the members and the methods you want, and then use "Add Required" to add any members of the class that are required to make the methods you chose work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With