One of my pet missions is to remove unused code from any application I work on. The trick is determining which code is actually unused. Recently, I explored a number of different tools, as detailed below. In the end, I settled on the Eclipse Core Tools plugin, available from the following update site: http://eclipse.org/eclipse/platform-core/updates
Eclipse by default will find unused private members and variables in methods, but that is of very limited use. Last year we tried out a tool named RefactorIT, which was very powerful. Unfortunately, RefactorIT is currently unavailable while they move to a free version. PMD can do a great deal of source code analysis, above and beyond what Eclipse is capable of by default. In particular, it is good at finding duplicated code. It’s highly configurable, with the attendant learning curve, but worth learning if you really want to clean up your code base. CheckStyle was originally designed primarily to check adherence to code layout standards, but has become much powerful and can now find many of the same design problems as PMD. Sadly, neither of these tools do any better than Eclipse at finding unused methods. ProGuard is supposed to be able to find unused code, but I was unable to determine how to use it on our deployment (the examples show how to check JAR files, not exploded WARs). I could probably get it working given more time, but time is (as always) in short supply.
Finally, I had a measure of success. There is an Eclipse plugin called CoreTools, which is actually
used by the Eclipse development team. The version available for Eclipse 3.3 includes a feature where you can right-click a class, package, etc. and select “Find Unreferenced Members”. It can find unused members of any visibility, and is smart enough to ignore references in test code. Of course, making sure the method isn’t called through reflection is up to you. I haven’t gotten hot deployment working for our project in 3.3 yet, so for now I am stuck switching back and forth. I find unreferenced methods in 3.3, then switch back to my regular workspace to actually remove the methods. It’s not a perfect situation, but it is workable.
As an aside, has anyone used the built-in hot deploy in Eclipse 3.3 (rather than installing MyEclipse)?