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 all commits
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
44 changes: 43 additions & 1 deletion main/OpenCover.Framework/Model/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//
// This source code is released under the MIT License; see the accompanying license file.
//

using System;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace OpenCover.Framework.Model
Expand Down Expand Up @@ -107,5 +108,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 @@ -66,5 +67,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 @@ -149,6 +149,7 @@
<Compile Include="Utility\IPerfCounters.cs" />
<Compile Include="Utility\PerfCounters.cs" />
<Compile Include="Utility\ThreadHelper.cs" />
<Compile Include="Utility\SourceRepository.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="log4net.config">
Expand Down
Loading