Is there a way to extract a class with methods in eclipse?
In Eclipse 3.7.1 there is an option to move methods and fields out of a class. To do so:
- Make sure the destination class exists (empty class is fine, just as long as it exists in the project).
- In the source class, select the methods that you want to remove (the outline view works great for this), right click on the selection, and choose Move
- Select the destination class in the drop down/Browse
Your members are now extracted. Fix any visibility issues (Source > Generate Getters and Setters is very useful for this) and you are all set.
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.