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

6 comments:
Doesn't look like the update site is public
Hi Lhasadad,
the update site is actually public, despite getting an "Access Forbiden" message when trying to access it in a web browser.
This is because the web browser and the Update Manager access the site a bit differently. The Update Manager automatically appends "site.xml" to the URL given in the article. :)
Elias.
great tool, thanks!
Here is a similar tool: www.ucdetector.org
And here is another similar tool: http://dcd.dev.java.net (eclipse not needed)
Great tool, thanks. It would be great if I could identify unused classes or source files, too.
Post a Comment