Skip to content

Commit

Permalink
Make InterceptableLocation implement `IEquatable<InterceptableLocat…
Browse files Browse the repository at this point in the history
…ion>` (#77137)

* Make `InterceptableLocation` implement `IEquatable<InterceptableLocation>`

* Update src/Compilers/CSharp/Portable/Utilities/InterceptableLocation.cs

Co-authored-by: Jan Jones <[email protected]>

* Update src/Compilers/CSharp/Portable/Utilities/InterceptableLocation.cs

Co-authored-by: Jan Jones <[email protected]>

* Record public API change

---------

Co-authored-by: Jan Jones <[email protected]>
  • Loading branch information
aradalvand and jjonescz authored Feb 17, 2025
1 parent d862b94 commit 80ccf3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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
21 changes: 14 additions & 7 deletions src/Compilers/CSharp/Portable/Utilities/InterceptableLocation.cs
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;
}
}

0 comments on commit 80ccf3f

Please sign in to comment.