jdepend.framework

Class JDepend

public class JDepend extends Object

The JDepend class analyzes directories of Java class files and generates the following metrics for each Java package.

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 (mike@clarkware.com) Clarkware Consulting, Inc.

Constructor Summary
JDepend()
JDepend(PackageFilter filter)
Method Summary
voidaddDirectory(String name)
Adds the specified directory name to the collection of directories to be analyzed.
JavaPackageaddPackage(String pkgName)
Adds the specified Java package name to the collection of analyzed packages.
voidaddPackage(JavaPackage pkg)
Adds the specified Java package to the collection of analyzed packages.
voidaddPackages(Collection packages)
Adds the specified collection of packages to the collection of analyzed packages.
voidaddParseListener(ParserListener listener)
Registers the specified parser listener.
Collectionanalyze()
Analyzes the registered directories and returns the collection of analyzed packages.
voidanalyzeInnerClasses(boolean b)
Determines whether inner classes are analyzed.
booleancontainsCycles()
Indicates whether the packages contain one or more dependency cycles.
intcountClasses()
Returns the number of registered Java classes to be analyzed.
intcountPackages()
Returns the number of analyzed Java packages.
booleandependencyMatch(DependencyConstraint constraint)
Indicates whether the analyzed packages match the specified dependency constraint.
PackageFiltergetFilter()
Returns the package filter.
JavaPackagegetPackage(String name)
Returns the analyzed package of the specified name.
CollectiongetPackages()
Returns the collection of analyzed packages.
voidsetFilter(PackageFilter filter)
Sets the package filter.

Constructor Detail

JDepend

public JDepend()

JDepend

public JDepend(PackageFilter filter)

Method Detail

addDirectory

public void addDirectory(String name)
Adds the specified directory name to the collection of directories to be analyzed.

Parameters: name Directory name.

Throws: IOException If the directory is invalid.

addPackage

public JavaPackage addPackage(String pkgName)
Adds the specified Java package name to the collection of analyzed packages.

Parameters: pkgName Java package name.

Returns: Added Java package.

addPackage

public void addPackage(JavaPackage pkg)
Adds the specified Java package to the collection of analyzed packages.

Parameters: pkg Java package.

addPackages

public void addPackages(Collection packages)
Adds the specified collection of packages to the collection of analyzed packages.

Parameters: packages Collection of packages.

addParseListener

public void addParseListener(ParserListener listener)
Registers the specified parser listener.

Parameters: listener Parser listener.

analyze

public Collection analyze()
Analyzes the registered directories and returns the collection of analyzed packages.

Returns: Collection of analyzed packages.

analyzeInnerClasses

public void analyzeInnerClasses(boolean b)
Determines whether inner classes are analyzed.

Parameters: b true to analyze inner classes; false otherwise.

containsCycles

public boolean containsCycles()
Indicates whether the packages contain one or more dependency cycles.

Returns: true if one or more dependency cycles exist.

countClasses

public int countClasses()
Returns the number of registered Java classes to be analyzed.

Returns: Number of classes.

countPackages

public int countPackages()
Returns the number of analyzed Java packages.

Returns: Number of Java packages.

dependencyMatch

public boolean dependencyMatch(DependencyConstraint constraint)
Indicates whether the analyzed packages match the specified dependency constraint.

Returns: true if the packages match the dependency constraint

getFilter

public PackageFilter getFilter()
Returns the package filter.

Returns: PackageFilter

getPackage

public JavaPackage getPackage(String name)
Returns the analyzed package of the specified name.

Parameters: name Package name.

Returns: Package, or null if the package was not analyzed.

getPackages

public Collection getPackages()
Returns the collection of analyzed packages.

Returns: Collection of analyzed packages.

setFilter

public void setFilter(PackageFilter filter)
Sets the package filter.

Parameters: filter Package filter.

Copyright B) 1999-2003 Clarkware Consulting, Inc.