Class JDepend
JDepend
class analyzes directories of Java class files
and generates the following metrics for each Java package.
- Afferent Coupling (Ca)
The number of packages that depend upon the classes within the analyzed package.
- Efferent Coupling (Ce)
The number of packages that the classes in the analyzed package depend upon.
- Abstractness (A)
The ratio of the number of abstract classes (and interfaces) in the analyzed package to the total number of classes in the analyzed package.
The range for this metric is 0 to 1, with A=0 indicating a completely concrete package and A=1 indicating a completely abstract package.
- Instability (I)
The ratio of efferent coupling (Ce) to total coupling (Ce + Ca) such that I = Ce / (Ce + Ca).
The range for this metric is 0 to 1, with I=0 indicating a completely stable package and I=1 indicating a completely instable package.
- Distance from the Main Sequence (D)
The perpendicular distance of a package from the idealized line A + I = 1. A package coincident with the main sequence is optimally balanced with respect to its abstractness and stability. Ideal packages are either completely abstract and stable (x=0, y=1) or completely concrete and instable (x=1, y=0).
The range for this metric is 0 to 1, with D=0 indicating a package that is coincident with the main sequence and D=1 indicating a package that is as far from the main sequence as possible.
- Package Dependency Cycle
Package dependency cycles are reported along with the paths of packages participating in package dependency cycles.
These metrics are hereafter referred to as the "Martin Metrics", as they are credited to Robert Martin (Object Mentor Inc.) and referenced in the book "Designing Object Oriented C++ Applications using the Booch Method", by Robert C. Martin, Prentice Hall, 1995.
Example API use:
JDepend jdepend = new JDepend(); jdepend.addDirectory("/path/to/classes"); Collection packages = jdepend.analyze(); Iterator i = packages.iterator(); while (i.hasNext()) { JavaPackage jPackage = (JavaPackage) i.next(); String name = jPackage.getName(); int Ca = jPackage.afferentCoupling(); int Ce = jPackage.efferentCoupling(); float A = jPackage.abstractness(); float I = jPackage.instability(); float D = jPackage.distance(); boolean b = jPackage.containsCycle(); }
This class is the data model used by the jdepend.textui.JDepend
and jdepend.swingui.JDepend
views.
- Author:
- Mike Clark, Clarkware Consulting, Inc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDirectory
(String name) Adds the specified directory name to the collection of directories to be analyzed.addPackage
(String name) Adds the specified Java package name to the collection of analyzed packages.void
addPackage
(JavaPackage pkg) Adds the specified Java package to the collection of analyzed packages.void
addPackages
(Collection packages) Adds the specified collection of packages to the collection of analyzed packages.void
addParseListener
(ParserListener listener) Registers the specified parser listener.analyze()
Analyzes the registered directories and returns the collection of analyzed packages.void
analyzeInnerClasses
(boolean b) Determines whether inner classes are analyzed.boolean
Indicates whether the packages contain one or more dependency cycles.int
Returns the number of registered Java classes to be analyzed.int
Returns the number of analyzed Java packages.boolean
dependencyMatch
(DependencyConstraint constraint) Indicates whether the analyzed packages match the specified dependency constraint.getPackage
(String name) Returns the analyzed package of the specified name.Returns the collection of analyzed packages.void
setComponents
(String components) Sets the list of components.void
setFilter
(PackageFilter filter)
-
Constructor Details
-
JDepend
public JDepend() -
JDepend
-
-
Method Details
-
analyze
Analyzes the registered directories and returns the collection of analyzed packages.- Returns:
- Collection of analyzed packages.
-
addDirectory
Adds the specified directory name to the collection of directories to be analyzed.- Parameters:
name
- Directory name.- Throws:
IOException
- If the directory is invalid.
-
setComponents
Sets the list of components.- Parameters:
components
- Comma-separated list of components.
-
analyzeInnerClasses
public void analyzeInnerClasses(boolean b) Determines whether inner classes are analyzed.- Parameters:
b
-true
to analyze inner classes;false
otherwise.
-
getPackages
Returns the collection of analyzed packages.- Returns:
- Collection of analyzed packages.
-
getPackage
Returns the analyzed package of the specified name.- Parameters:
name
- Package name.- Returns:
- Package, or
null
if the package was not analyzed.
-
countPackages
public int countPackages()Returns the number of analyzed Java packages.- Returns:
- Number of Java packages.
-
countClasses
public int countClasses()Returns the number of registered Java classes to be analyzed.- Returns:
- Number of classes.
-
containsCycles
public boolean containsCycles()Indicates whether the packages contain one or more dependency cycles.- Returns:
true
if one or more dependency cycles exist.
-
dependencyMatch
Indicates whether the analyzed packages match the specified dependency constraint.- Returns:
true
if the packages match the dependency constraint
-
addParseListener
Registers the specified parser listener.- Parameters:
listener
- Parser listener.
-
addPackage
Adds the specified Java package name to the collection of analyzed packages.- Parameters:
name
- Java package name.- Returns:
- Added Java package.
-
addPackages
Adds the specified collection of packages to the collection of analyzed packages.- Parameters:
packages
- Collection of packages.
-
addPackage
Adds the specified Java package to the collection of analyzed packages.- Parameters:
pkg
- Java package.
-
getFilter
-
setFilter
-