Browse Source

Code Coverage: more refactoring,

Refactoring methods to less responsibility
pull/67/head
Dragan 12 years ago
parent
commit
a8dec47e2f
  1. 44
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

44
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

@ -86,6 +86,9 @@ namespace ICSharpCode.CodeCoverage @@ -86,6 +86,9 @@ namespace ICSharpCode.CodeCoverage
this.IsStatic = this.GetBooleanAttributeValue("isStatic");
if ( !String.IsNullOrEmpty( this.FileID ) ) {
this.SequencePoints = this.GetSequencePoints();
this.BodyStartSP = getBodyStartSP(this.SequencePoints);
this.BodyFinalSP = getBodyFinalSP(this.SequencePoints);
this.SequencePoints = this.FilterSequencePoints(this.SequencePoints);
this.BranchPoints = this.GetBranchPoints();
this.BranchCoverageRatio = this.GetBranchRatio();
this.BranchCoverage = this.GetBranchCoverage();
@ -123,23 +126,27 @@ namespace ICSharpCode.CodeCoverage @@ -123,23 +126,27 @@ namespace ICSharpCode.CodeCoverage
sps.Add(sp);
}
return sps;
}
List<CodeCoverageSequencePoint> FilterSequencePoints(List<CodeCoverageSequencePoint> sps) {
if (sps.Count > 2) {
List<CodeCoverageSequencePoint> returnList = sps;
if (sps.Count > 2 &&
this.BodyStartSP != null &&
this.BodyFinalSP != null ) {
// After ccrewrite ContractClass/ContractClassFor
// sequence point(s) from another file/class/method
// is inserted into this method sequence points
//
// To remove alien sequence points, all points
// To remove alien sequence points, all sequence points on lines
// before method signature and after end-brackets xxx{} are removed
this.BodyStartSP = getBodyStartSP(sps);
if (this.BodyStartSP == null) { return sps; }
this.BodyFinalSP = getBodyFinalSP(sps);
if (this.BodyFinalSP == null) { return sps; }
// If ContractClassFor is in another file but matches this method lines
// then, afaik, not much can be done to remove inserted alien SP's
List<CodeCoverageSequencePoint> selected = new List<CodeCoverageSequencePoint>();
foreach (var point in sps) {
if (
(point.Line > BodyStartSP.Line || (point.Line == BodyStartSP.Line && point.Column >= BodyStartSP.Column)) &&
@ -150,20 +157,25 @@ namespace ICSharpCode.CodeCoverage @@ -150,20 +157,25 @@ namespace ICSharpCode.CodeCoverage
// After ccrewrite ContractClass/ContractClassFor
// duplicate method end-sequence-point (}) is added
//
// Add (point) on first finalSP (duplicate)
// Add first finalSP (can be a duplicate)
// Note: IL.Offset of second duplicate finalSP will
// extend branch coverage outside method-end "}",
// and that can lead to wrong branch coverage report!
// and that can lead to wrong branch coverage display!
if (object.ReferenceEquals (point, this.BodyFinalSP)) {
selected.Add (point);
}
}
// SP's are originaly ordered by CIL offset
// but ccrewrite can move offset of
// Contract.Requires before method signature SP (xxx{) and
// Contract.Ensures after method closing SP (})
// So sort SP's back by line/column
selected.OrderBy(item => item.Line).OrderBy(item => item.Column);
sps = selected;
returnList = selected;
}
return sps;
return returnList;
}
int GetSequencePointsCount() {
@ -245,10 +257,10 @@ namespace ICSharpCode.CodeCoverage @@ -245,10 +257,10 @@ namespace ICSharpCode.CodeCoverage
// This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Requires)
// and '{' branches at static methods
if (this.BodyStartSP == null) { return null; }
if (this.BodyStartSP == null) { return null; } // empty body
// This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Ensures)
if (this.BodyFinalSP == null) { return null; }
if (this.BodyFinalSP == null) { return null; } // empty body
// Connect Sequence & Branches
IEnumerator<CodeCoverageSequencePoint> SPEnumerator = this.SequencePoints.GetEnumerator();

Loading…
Cancel
Save