jdepend.framework
Class JDepend

java.lang.Object
  extended byjdepend.framework.JDepend

public class JDepend
extends java.lang.Object

The JDepend class analyzes directories of Java class and source 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("d:\projects\src");
    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
JDepend()
          Constructs a JDepend instance.
 
Method Summary
 void addDirectory(java.lang.String name)
          Adds the specified directory name to the collection of directories to be analyzed.
protected  void addPackage(JavaPackage jPackage)
          Adds the specified Java package to the collection of analyzed packages.
protected  JavaPackage addPackage(java.lang.String packageName)
          Adds the specified Java package name to the collection of analyzed packages, creating a new JavaPackage instance, if necessary.
 void addParseListener(ParserListener listener)
          Registers the specified parser listener.
 java.util.Collection analyze()
          Analyzes the registered directories and returns the collection of analyzed packages.
 boolean containsCycles()
          Indicates whether the packages contain one or more dependency cycles.
 int countJavaClasses()
          Returns the number of registered Java source and class files.
 int countJavaPackages()
          Returns the number of analyzed Java packages.
 boolean dependencyMatch(DependencyConstraint constraint)
          Indicates whether the analyzed packages match the specified dependency constraint.
protected  PackageFilter getFilter()
           
 JavaPackage getPackage(java.lang.String name)
          Returns the analyzed package of the specified name.
 java.util.Collection getPackages()
          Returns the collection of analyzed packages.
protected  JavaClass parseClass(java.io.File file)
          Parses the representative JavaClass from the specified file.
protected  void setPackages(java.util.Collection packages)
          Sets the collection of analyzed packages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDepend

public JDepend()
Constructs a JDepend instance.

Method Detail

analyze

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

Returns:
Collection of analyzed packages.

addDirectory

public void addDirectory(java.lang.String name)
                  throws java.io.IOException
Adds the specified directory name to the collection of directories to be analyzed.

Parameters:
name - Directory name.
Throws:
java.io.IOException - If the directory does not exist.

getPackages

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

Returns:
Collection of analyzed packages.

getPackage

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

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

countJavaPackages

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

Returns:
Number of Java packages.

countJavaClasses

public int countJavaClasses()
Returns the number of registered Java source and class files.

Returns:
Number of files.

containsCycles

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

Returns:
true if one or more dependency cycles exist.

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

addParseListener

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

Parameters:
listener - Parser listener.

parseClass

protected JavaClass parseClass(java.io.File file)
                        throws java.io.IOException
Parses the representative JavaClass from the specified file.

Parameters:
file - File to parse.
Returns:
JavaClass
Throws:
java.io.IOException - If a parse error occurs.

setPackages

protected void setPackages(java.util.Collection packages)
Sets the collection of analyzed packages.

Parameters:
packages - Collection of analyzed packages.

addPackage

protected JavaPackage addPackage(java.lang.String packageName)
Adds the specified Java package name to the collection of analyzed packages, creating a new JavaPackage instance, if necessary.

Parameters:
packageName - Java package name.
Returns:
Added Java package.

addPackage

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

Parameters:
jPackage - Java package.

getFilter

protected PackageFilter getFilter()


Copyright © 1999-2002 Clarkware Consulting, Inc. All Rights Reserved.