|
|
|
|
Unused classes/packages tool
Posted:
Sep 14, 2005 7:01 AM
|
|
|
I'm working in a company which code evoluted too fast and among a lot of different developers. There are hundreds of packages and thousands of classes. We are migranting to subversion (from source safe, urghh ), and as a part of the migration plan, we want to get rid of any unused class or package. I'm looking for kind of tool that, giving a start point (a class or a method of a class), this tool could list the classes and/or packages in the included source path(s) that are not reached by the initial class(es), directly or indirectly.
Thanks a lot for the help Emerson Cargnin UK
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 14, 2005 10:48 AM
in response to: echofloripa
|
|
|
Hi Emerson,
I think any modern IDE can do the trick for you. In eclipse, which I'm more familiar with, you just have to right click in a java file and choose (references -> workspace). Not automatic at all, but it works.
Eclipse can also be configured to generate warnings for unused variables, fields and methods. Perhaps tools like PMD or Checkstyle can help you to find unused classes, but I'm not sure.
There's also JDepend, which analyses class files (already compiled) and generates coupling reports, but I think it only works at the package level, not sure if it could be used to list class by class dependencies.
Anyway, I foresee a lot of coffee in your future, and I'm not talking about Java Good luck!
[]'s Gatto
|
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 15, 2005 4:16 AM
in response to: echofloripa
|
|
|
You can use ProGuard (proguard.sourceforge.net) to do this, it's really an obfuscator but the -printusage option can list all of the unused files in an application. You can even give it multiple entry points to scan from which may help if you code base is particularly gnarly.
|
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 16, 2005 2:36 AM
in response to: iphillips
|
|
|
In my search for such tool I've seem proguard, just didn't tried when i saw that it was a code obfuscator, but I'll definitely try that out.
I also know that in eclipse I can find all the callers for a given method or the references for a given class, the problem is that I would have to do this by hand, and with more than 1300 classes, just in one project would take some years 
thanks a lot for the help Emerson
|
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 16, 2005 2:41 AM
in response to: iphillips
|
|
|
Hi gatto
Thanks for the help, I'm alsoa eclipse user, although it really can find references for a given class, it would take ages to scan all the 1300 classes by hand. Jdepend and checkstyle do not verify unused classes or packages.
thanks for the help anyway. PS: como vai o brasil, tudo certinho por ai? :P
Emerson Reading/UK
|
|
|
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 16, 2005 2:39 AM
in response to: echofloripa
|
|
|
Proposal:
1. Check out everything from SS. 2. Use Ant or Javac to compile your starting point classes. You might want to do a free text search for Class.forName( , remember to also include those classes. Remember to set up the source paths. 3. Write a script that runs through the source folders. Any .java file with no corresponding .class file can be deleted. 4. Build the system and run it (with the pruned source tree) to verify that you did not tear out too much. 5. Better not delete the original SS, just in case you make a mistake.
Martin Skarsaune
|
|
|
|
|
|
|
|
Re: Unused classes/packages tool
Posted:
Sep 14, 2008 3:25 PM
in response to: echofloripa
|
|
|
Try UCDetector. It finds unused classes, methods, fields:
UCDetector (Unecessary Code Detector) is a Open Source eclipse PlugIn Tool to find unecessary (dead) java code. It also tries to make code final, protected or private. UCDetector also finds cyclic dependencies between classes.
|
|
|
|
|