net.sourceforge.cobertura.coveragedata

Class ClassData

public class ClassData extends CoverageDataContainer implements Comparable, HasBeenInstrumented

ProjectData information is typically serialized to a file. An instance of this class records coverage information for a single class that has been instrumented.

This class implements HasBeenInstrumented so that when cobertura instruments itself, it will omit this class. It does this to avoid an infinite recursion problem because instrumented classes make use of this class.

Field Summary
Mapbranches
Each key is a line number in this class, stored as an Integer object.
booleancontainsInstrumentationInfo
SetmethodNamesAndDescriptors
Stringname
static longserialVersionUID
StringsourceFileName
Constructor Summary
ClassData(String name)
Method Summary
LineDataaddLine(int lineNumber, String methodName, String methodDescriptor)
voidaddLineJump(int lineNumber, int branchNumber)
voidaddLineSwitch(int lineNumber, int switchNumber, int[] keys)
voidaddLineSwitch(int lineNumber, int switchNumber, int min, int max)
intcompareTo(Object o)
This is required because we implement Comparable.
booleancontainsInstrumentationInfo()
booleanequals(Object obj)
Returns true if the given object is an instance of the ClassData class, and it contains the same data as this class.
StringgetBaseName()
doublegetBranchCoverageRate(String methodNameAndDescriptor)
CollectiongetBranches()
LineDatagetLineCoverage(int lineNumber)
doublegetLineCoverageRate(String methodNameAndDescriptor)
LineDatagetLineData(int lineNumber)
SortedSetgetLines()
CollectiongetLines(String methodNameAndDescriptor)
SetgetMethodNamesAndDescriptors()
StringgetName()
intgetNumberOfCoveredBranches()
intgetNumberOfValidBranches()
StringgetPackageName()
StringgetSourceFileName()
Return the name of the file containing this class.
booleanhasBranch(int lineNumber)
inthashCode()
booleanisValidSourceLineNumber(int lineNumber)
Determine if a given line number is a valid line of code.
voidmerge(CoverageData coverageData)
Merge some existing instrumentation with this instrumentation.
voidremoveLine(int lineNumber)
voidsetContainsInstrumentationInfo()
voidsetSourceFileName(String sourceFileName)
voidtouch(int lineNumber)
Increment the number of hits for a particular line of code.
voidtouchJump(int lineNumber, int branchNumber, boolean branch)
Increments the number of hits for particular hit counter of particular branch on particular line number.
voidtouchSwitch(int lineNumber, int switchNumber, int branch)
Increments the number of hits for particular hit counter of particular switch branch on particular line number.

Field Detail

branches

private Map branches
Each key is a line number in this class, stored as an Integer object. Each value is information about the line, stored as a LineData object.

containsInstrumentationInfo

private boolean containsInstrumentationInfo

methodNamesAndDescriptors

private Set methodNamesAndDescriptors

name

private String name

serialVersionUID

private static final long serialVersionUID

sourceFileName

private String sourceFileName

Constructor Detail

ClassData

public ClassData(String name)

Parameters: name In the format "net.sourceforge.cobertura.coveragedata.ClassData"

Method Detail

addLine

public LineData addLine(int lineNumber, String methodName, String methodDescriptor)

addLineJump

public void addLineJump(int lineNumber, int branchNumber)

addLineSwitch

public void addLineSwitch(int lineNumber, int switchNumber, int[] keys)

addLineSwitch

public void addLineSwitch(int lineNumber, int switchNumber, int min, int max)

compareTo

public int compareTo(Object o)
This is required because we implement Comparable.

containsInstrumentationInfo

public boolean containsInstrumentationInfo()

equals

public boolean equals(Object obj)
Returns true if the given object is an instance of the ClassData class, and it contains the same data as this class.

getBaseName

public String getBaseName()

getBranchCoverageRate

public double getBranchCoverageRate(String methodNameAndDescriptor)

Returns: The branch coverage rate for a particular method.

getBranches

public Collection getBranches()

getLineCoverage

public LineData getLineCoverage(int lineNumber)

Parameters: lineNumber The source code line number.

Returns: The coverage of the line

getLineCoverageRate

public double getLineCoverageRate(String methodNameAndDescriptor)

Returns: The line coverage rate for particular method

getLineData

private LineData getLineData(int lineNumber)

getLines

public SortedSet getLines()

getLines

public Collection getLines(String methodNameAndDescriptor)

getMethodNamesAndDescriptors

public Set getMethodNamesAndDescriptors()

Returns: The method name and descriptor of each method found in the class represented by this instrumentation.

getName

public String getName()

getNumberOfCoveredBranches

public int getNumberOfCoveredBranches()

See Also: getNumberOfCoveredBranches

getNumberOfValidBranches

public int getNumberOfValidBranches()

Returns: The number of branches in this class.

getPackageName

public String getPackageName()

getSourceFileName

public String getSourceFileName()
Return the name of the file containing this class. If this class' sourceFileName has not been set (for whatever reason) then this method will attempt to infer the name of the source file using the class name.

Returns: The name of the source file, for example net/sourceforge/cobertura/coveragedata/ClassData.java

hasBranch

public boolean hasBranch(int lineNumber)

Returns: True if the line contains at least one condition jump (branch)

hashCode

public int hashCode()

isValidSourceLineNumber

public boolean isValidSourceLineNumber(int lineNumber)
Determine if a given line number is a valid line of code.

Returns: True if the line contains executable code. False if the line is empty, or a comment, etc.

merge

public void merge(CoverageData coverageData)
Merge some existing instrumentation with this instrumentation.

Parameters: coverageData Some existing coverage data.

removeLine

public void removeLine(int lineNumber)

setContainsInstrumentationInfo

public void setContainsInstrumentationInfo()

setSourceFileName

public void setSourceFileName(String sourceFileName)

touch

public void touch(int lineNumber)
Increment the number of hits for a particular line of code.

Parameters: lineNumber the line of code to increment the number of hits.

touchJump

public void touchJump(int lineNumber, int branchNumber, boolean branch)
Increments the number of hits for particular hit counter of particular branch on particular line number.

Parameters: lineNumber The line of code where the branch is branchNumber The branch on the line to change the hit counter branch The hit counter (true or false)

touchSwitch

public void touchSwitch(int lineNumber, int switchNumber, int branch)
Increments the number of hits for particular hit counter of particular switch branch on particular line number.

Parameters: lineNumber The line of code where the branch is switchNumber The switch on the line to change the hit counter branch The hit counter