net.sourceforge.cobertura.reporting
Class ComplexityCalculator
java.lang.Object
net.sourceforge.cobertura.reporting.ComplexityCalculator
Allows complexity computing for source files, packages and a whole project. Average
McCabe's number for methods contained in the specified entity is returned. This class
depends on FileFinder which is used to map source file names to existing files.
One instance of this class should be used for the same set of source files - an
object of this class can cache computed results.
finder
private final FileFinder finder
logger
private static final Logger logger
ComplexityCalculator
public ComplexityCalculator(FileFinder finder)
Creates new calculator. Passed FileFinder
will be used to
map source file names to existing files when needed.
finder
- FileFinder
that allows to find source files
getAccumlatedCCNForSingleFile
private ComplexityCalculator.Complexity getAccumlatedCCNForSingleFile(File file)
Calculates the code complexity number for single source file.
"CCN" stands for "code complexity number." This is
sometimes referred to as McCabe's number. This method
calculates the average cyclomatic code complexity of all
methods of all classes in a given directory.
file
- The source file for which you want to calculate
the complexity
- average complexity for the specified source file
getCCNForClass
public double getCCNForClass(ClassData classData)
Computes CCN for source file the specified class belongs to.
classData
- package to compute CCN for
- CCN for source file the specified class belongs to
getCCNForPackage
public double getCCNForPackage(PackageData packageData)
Computes CCN for all sources contained in the specified package.
All source files that cannot be mapped to existing files are ignored.
packageData
- package to compute CCN for
- CCN for the specified package or 0 if no source files were found
getCCNForProject
public double getCCNForProject(ProjectData projectData)
Computes CCN for all sources contained in the project.
CCN for whole project is an average CCN for source files.
All source files for which CCN cannot be computed are ignored.
projectData
- project to compute CCN for
- CCN for project or 0 if no source files were found
getCCNForSourceFile
public double getCCNForSourceFile(SourceFileData sourceFile)
Computes CCN for single source file.
sourceFile
- source file to compute CCN for
- CCN for the specified source file, 0 if cannot map
sourceFile
to existing file