Is there any tool to detect code/functionality which is no longer used?

感情迁移 提交于 2019-12-06 07:48:17

There are at least two tools you can deploy along your application and collect some statistics, even in production:

  1. AspectJ - weave all classes and somehow log every method execution.

  2. JaCoCo - essentially does the same thing but automatically with a help of a Java agent. Executed methods/branches (in fact, this is a code coverage tool) are saved in a file for future processing. Should solve your problem pretty easy.

Both approaches should work with any JVM language (I see in your question) as they work on bytecode level. I once used JaCoCo to measure code coverage (think: which methods/branches were execured) during Selenium test run.

For example, Intellij IDEA has static analysis which greys out names of Types/Methods which aren't called. If you want automatic tool for that, try Sonar. I guess, both of these methods can give a few false results if you use reflection in some form.

There is also PMD

btw it could be installed as a plugin for different IDEs

I'm also using the following static analysis tools:

  • UCDetector (open source eclipse plugin) - can be quite helpful.

  • Structure101 (commercial software)- can be used for that purpose (e.g. finding unused classes), too.

You can use JArchitect tool to analyse your code and detect the unused code and functionnalities, there are some of it's functionnalities :

  • Code Query language (CQLinq),
  • more than 80 Metrics,
  • and display analysis results in different types of Diagrams
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!