Here is a Quick Way to Eliminate Dead Code
If plug-ins were tools the Eclipse Core Tools plug-in would be a Swiss army knife. One of it's most useful tools is finding unused methods and fields in your code. I used it recently to remove obsolete code from my plug-ins.
To start removing unused code, follow these steps:
- Download version 1.4.0 (for Eclipse 3.2) of the Eclipse Core Tools from this update site:
http://www.eclipse.org/eclipse/platform-core/updates/ - In a workspace that contains all related code, select the project / package / file you want to work on.
(When I did this, I actually closed my unit-test projects because I didn't want to keep code around that is used nowhere but in tests. I refactored or removed the broken tests afterwards.) - In the context menu select Find Unreferenced Members. The results will be shown in the Search view.
- Remove unreferenced code, but use your judgment!
Some code may appear unreferenced, that in fact isn't. Common examples:
- code that is contributed through extension-points
- code that is invoked through reflection
- unreferenced code that is API
- unreferenced fields in Serializable classes
- private constructors (if you use them to enforce non-instantiability or the singleton property - Effective Java, Items 2 and 3)
- Repeat steps 2 - 4 as often as necessary.
Knife Image: (c) 2004, brokenarts/stock.xchng
