Tips & Tricks

Analyzing Code Dependencies (part I)

If you have a large project with several modules using a set of libraries, any operation that requires an essential structural change can be a disaster. For example, you may decide to stop using one of the libraries, or extract API, or simply extract a new module. In any of these cases, you need to analyze dependencies within your project. Well, it’s easy to say.
Let’s consider the case when you need to extract a new module and make it dependant only on API. It means that first you need to search through code and find references to resources not included into API. It may take hours of dull work.
IntelliJ IDEA’s solution is the dependency analyzer that can show you all the module dependencies in one convenient window. Furthermore, this analyzer can find not only dependencies between modules, but also between packages. It can even find dependencies of a certain class.
On the screenshot below, you can see how IntelliJ IDEA shows dependencies of a package.
dependencies
On the left panel you can see the classes of the analyzed package (com.intellij.sisyphus.ea.util), while the right panel shows all the libraries and classes on which this package depends.
But that’s only half of the way. You need not only the information about dependencies, but also the exact code that actually “establishes” this dependency (references to the class from the package, usages of the library classes, etc.)
To find all the usages of a certain package, class, or library within the analyzed code, just click the item in the right panel. For example, the following screenshot shows all the usages of the com.intellij.sisyphus.ea.lexer classes within the com.intellij.sisyphus.ea.util package.
dependencies and usages
Now having all the information about dependencies, you can process them according to your needs.

Note   This tip&trick was originally posted at www.javalobby.org.

Technorati tags: IDE, Java
image description

Discover more