5

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 ?

Damir
  • 54,277
  • 94
  • 246
  • 365
  • Possible duplicate of [Find unused classes in a Java Eclipse project](https://stackoverflow.com/questions/665563/find-unused-classes-in-a-java-eclipse-project) – Anderson Green Apr 02 '18 at 22:24

4 Answers4

3

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.

rsp
  • 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
2

Looks like similar question already asked on Stackoverfow check out the following links already asked on SO

Check out the answers

Community
  • 1
  • 1
Srinivas M.V.
  • 6,508
  • 5
  • 33
  • 49
2

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)

Adam Rabung
  • 5,232
  • 2
  • 27
  • 42
1

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.

duffymo
  • 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
  • Individual classes, as far as I know. – duffymo 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
  • I'll have to see if IntelliJ has something similar. – duffymo Dec 23 '10 at 13:01
  • 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