Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make InterceptableLocation implement IEquatable<InterceptableLocation> #77137

Merged
merged 4 commits into from
Feb 17, 2025
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
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ override abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.Equals(obj
override abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.GetHashCode() -> int
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetInterceptableLocation(this Microsoft.CodeAnalysis.SemanticModel? semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax! node, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.CSharp.InterceptableLocation?
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetInterceptsLocationAttributeSyntax(this Microsoft.CodeAnalysis.CSharp.InterceptableLocation! location) -> string!
abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.Equals(Microsoft.CodeAnalysis.CSharp.InterceptableLocation? other) -> bool
[RSEXPERIMENTAL003]Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser
[RSEXPERIMENTAL003]Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser.Dispose() -> void
[RSEXPERIMENTAL003]Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser.ParseLeadingTrivia() -> Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser.Result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.CSharp;
/// <summary>Denotes an interceptable call. Used by source generators to generate '[InterceptsLocation]' attributes.</summary>
/// <seealso href="https://github.com/dotnet/roslyn/issues/72133" />
/// <seealso href="https://github.com/dotnet/csharplang/issues/7009" />
public abstract class InterceptableLocation
public abstract class InterceptableLocation : IEquatable<InterceptableLocation>
{
private protected InterceptableLocation() { }

Expand All @@ -40,6 +40,8 @@ private protected InterceptableLocation() { }

public abstract override bool Equals(object? obj);
public abstract override int GetHashCode();

public abstract bool Equals(InterceptableLocation? other);
}

#pragma warning disable RSEXPERIMENTAL002 // internal usage of experimental API
Expand Down Expand Up @@ -167,12 +169,7 @@ public override bool Equals(object? obj)
if ((object)this == obj)
return true;

return obj is InterceptableLocation1 other
&& _checksum.SequenceEqual(other._checksum)
&& _path == other._path
&& _position == other._position
&& _lineNumberOneIndexed == other._lineNumberOneIndexed
&& _characterNumberOneIndexed == other._characterNumberOneIndexed;
return obj is InterceptableLocation other && Equals(other);
}

public override int GetHashCode()
Expand All @@ -183,4 +180,14 @@ public override int GetHashCode()
BinaryPrimitives.ReadInt32LittleEndian(_checksum.AsSpan()),
_position);
}

public override bool Equals(InterceptableLocation? obj)
{
return obj is InterceptableLocation1 other
&& _checksum.SequenceEqual(other._checksum)
&& _path == other._path
&& _position == other._position
&& _lineNumberOneIndexed == other._lineNumberOneIndexed
&& _characterNumberOneIndexed == other._characterNumberOneIndexed;
}
}