|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjdepend.framework.JDepend
public class JDepend
The JDepend
class analyzes directories
of Java class and source files and generates the following
metrics for each Java package:
The number of packages that depend upon the classes within the analyzed package.
The number of packages that the classes in the analyzed package depend upon.
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.
The ratio of efferent coupling (Ce) to total coupling (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.
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 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("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.
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 |
---|
public JDepend()
JDepend
instance.
Method Detail |
---|
public java.util.Collection analyze()
public void addDirectory(java.lang.String name) throws java.io.IOException
name
- Directory name.
java.io.IOException
- If the directory does not exist.public java.util.Collection getPackages()
public JavaPackage getPackage(java.lang.String name)
name
- Package name.
null
if the
package was not analyzed.public int countJavaPackages()
public int countJavaClasses()
public boolean containsCycles()
true
if one or more dependency
cycles exist.public boolean dependencyMatch(DependencyConstraint constraint)
true
if the packages
match the dependency constraintpublic void addParseListener(ParserListener listener)
listener
- Parser listener.protected JavaClass parseClass(java.io.File file) throws java.io.IOException
JavaClass
from the specified file.
file
- File to parse.
JavaClass
java.io.IOException
- If a parse error occurs.protected void setPackages(java.util.Collection packages)
packages
- Collection of analyzed packages.protected JavaPackage addPackage(java.lang.String packageName)
JavaPackage
instance, if necessary.
packageName
- Java package name.
protected void addPackage(JavaPackage jPackage)
jPackage
- Java package.protected PackageFilter getFilter()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |