I am new ( and only person ) on old Java project. Couple guys have developed this before me. Is there any tool ( plugin for Eclipse would be nice ) which can find in project dead classes ( classes that are declared but they don't use anymore anywhere ?
4 Answers
You could use the Emma plugin to determine code coverage and look for the classes with 0% coverage after a full run.
To make sure before you remove classes, use the eclipse function that shows all references to the class in case it is used in exception handling.

- 23,135
- 6
- 55
- 69
-
When I run this plugin, it seems to me like plugin just analyzed classes on which I used during the running application ( if I have tabs and I don't open them it seems like coverage 0% ) . Is this true I am wrong ? – Damir Dec 23 '10 at 13:18
-
@Damir, That is correct, emma gives an overview of code that ran during a session. You can use emma to check code coverage of test sets, or in your case code coverage for a "normal" run in which you try to use all functionality in one session. – rsp Dec 23 '10 at 13:23
-
I've only thought of Emma for test code coverage. This is an interesting idea, thank you for sharing it. – duffymo Dec 23 '10 at 13:53
Looks like similar question already asked on Stackoverfow check out the following links already asked on SO
Check out the answers

- 1
- 1

- 6,508
- 5
- 33
- 49
http://eclipsenuggets.blogspot.com/2007/05/here-is-quick-way-to-eliminate-dead.html
This worked for me (although I tried it several years ago)

- 5,232
- 2
- 27
- 42
IntelliJ has a "Find Usages" that you can apply to classes, methods, strings - anything. Perhaps the Eclipse help can turn up such a thing.
Or maybe you should switch to IntelliJ.
IntelliJ can also generate UML that includes dependencies. Any class or package without a dependency would be a good candidate for removal. You'd get a quick visual that way.

- 305,152
- 44
- 369
- 561
-
For "Find Usages" won't the user have to go to each individual class and check for it? Can it applied to a complete workspace to point out all unused classes? – anirvan Dec 23 '10 at 12:59
-
-
it sounds like, he is looking for a complete list of 'dead' classes. if not the default shortcut in eclipse is shift+ctrl+g – Olivier Heidemann Dec 23 '10 at 12:59
-
-
If you mean something where you select a single identifier and find references to it throughout the project, Eclipse has that (Search -> References). Sounds like the OP wants something that will do this automatically for all classes, rather than manually invoking it on each. – Dave Costa Dec 23 '10 at 13:04
-
@Dave Costa Yes, that is what I want. I am lazy programmer. I accept plugin for Netbeans, just not to work manually ! – Damir Dec 23 '10 at 13:49