Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove duplicate empty SequencePoint & Refactored
  • Loading branch information
ddur committed Dec 23, 2015
commit b57bdda47cd93ecf5e68da419cb856d352ec3374
47 changes: 47 additions & 0 deletions main/OpenCover.Framework/Model/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//
// This source code is released under the MIT License; see the accompanying license file.
//
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace OpenCover.Framework.Model
Expand Down Expand Up @@ -95,6 +97,10 @@ public class Method : SummarySkippedEntity
[XmlAttribute("isSetter")]
public bool IsSetter { get; set; }

/// <summary>
/// Mark As Skipped
/// </summary>
/// <param name="reason"></param>
public override void MarkAsSkipped(SkippedMethod reason)
{
SkippedDueTo = reason;
Expand All @@ -103,5 +109,46 @@ public override void MarkAsSkipped(SkippedMethod reason)
SequencePoints = null;
BranchPoints = null;
}
/// <summary>
/// method name excluding return type, namespace and arguments
/// </summary>
public string shortName {
get {
if (String.IsNullOrWhiteSpace(this.Name)) return "";
int startIndex = this.Name.IndexOf("::", StringComparison.Ordinal);
int finalIndex = this.Name.IndexOf('(', startIndex);
return this.Name
.Substring(startIndex, finalIndex - startIndex)
.Substring(2);
}
}

/* Compiler Generated Name Examples
<Name>System.Boolean DD.Collections.BitSetArray/&lt;Complement&gt;d__e::MoveNext()</Name>
<Name>System.Boolean DD.Collections.BitSetArray::&lt;_SetItems&gt;b__b(System.Int32)</Name>
<Name>System.Boolean DD.Collections.BitSetArray::BitSetArray_&lt;_SetItems&gt;b__b_0(System.Int32)</Name>

<Name>[^\s]+\s[^\s|/|:]+(/\w*)?(::(.+_)?)?(&lt;\w+&gt;[a-z]__\w(\w|_\w)?)(::.+)?(\(.*\)</Name>)$
*/
/// <summary>
/// True if method name matches isGeneratedMethodRegex pattern
/// </summary>
public bool isGenerated {
get {
return (!String.IsNullOrWhiteSpace(this.Name)
&& this.Name.Contains("__")
&& isGeneratedMethodRegex.IsMatch(this.Name)
);
}
}
private const RegexOptions regexOptions = RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
private readonly Regex isGeneratedMethodRegex = new Regex(@"(<[^\s|>]+>[a-z]__\w(\w|_\w)?)(::([^\s|\(]+))?(\([^\s|\)]*\))$", regexOptions);

/*
code sample
Match match = generatedMethodItems.Match(sample);
if (match.Success) Console.WriteLine(match.Groups["returnType"].Value);
*/
private readonly Regex generatedMethodItems = new Regex(@"(?<returnType>[^\s]+)\s(?<nameSpace>[^\s|/]+/)?(?<className>[^\s|:]+::)?(<(?<replacedName>[^\s|>]+)>[a-z]__\w(\w|_\w)?)(::(?<methodName>[^\s|\(]+))?(\([^\s|\)]*\))$", regexOptions);
}
}
52 changes: 51 additions & 1 deletion main/OpenCover.Framework/Model/SequencePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// This source code is released under the MIT License; see the accompanying license file.
//

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

Expand All @@ -12,7 +13,7 @@ namespace OpenCover.Framework.Model
/// <summary>
/// a sequence point
/// </summary>
public class SequencePoint : InstrumentationPoint, IDocumentReference
public class SequencePoint : InstrumentationPoint, IDocumentReference, IEquatable<SequencePoint>
{
/// <summary>
/// The start line of the sequence point
Expand Down Expand Up @@ -63,5 +64,54 @@ public class SequencePoint : InstrumentationPoint, IDocumentReference
public string Document { get; set; }

internal List<BranchPoint> BranchPoints { get; set; }

/// <summary>
/// Property
/// </summary>
public bool isSingleCharSequencePoint {
get {
return (this.StartLine == this.EndLine) && (this.EndColumn - this.StartColumn) == 1;
}
}

#region IEquatable implementation

/// <summary>
/// Override GetHashCode
/// </summary>
/// <returns>int</returns>
public override int GetHashCode () {
return unchecked (this.StartLine << 3) ^ unchecked (this.EndLine << 2) ^ unchecked (this.StartColumn << 1) ^ (this.EndColumn);
}

/// <summary>
/// Override Equals
/// </summary>
/// <param name="obj">Object</param>
/// <returns>bool</returns>
public override bool Equals (Object obj) {
if (ReferenceEquals(this, obj)) {
return true;
}
var that = obj as SequencePoint;
return !ReferenceEquals(that, null) && this.Equals(that);
}

/// <summary>
/// IEquatable&lt;SequencePoint&gt;.Equals implementation
/// </summary>
/// <param name="other">SequencePoint</param>
/// <returns>bool</returns>
bool IEquatable<SequencePoint>.Equals(SequencePoint other)
{
return !ReferenceEquals(other, null)
&& this.Document == other.Document
&& this.StartLine == other.StartLine
&& this.StartColumn == other.StartColumn
&& this.EndLine == other.EndLine
&& this.EndColumn == other.EndColumn;
}

#endregion
}
}
1 change: 1 addition & 0 deletions main/OpenCover.Framework/OpenCover.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Compile Include="Utility\CodeCoverageStringTextSource.cs" />
<Compile Include="Utility\IPerfCounters.cs" />
<Compile Include="Utility\PerfCounters.cs" />
<Compile Include="Utility\SourceRepository.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="log4net.config">
Expand Down
Loading