Skip to content

Commit

Permalink
Rename extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jul 11, 2024
1 parent 6ea30bf commit 6f75804
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static bool HasThisReceiver(this IInvocationOperationWrapper invocation,
&& !invocation.Arguments.IsEmpty
&& state.ResolveCaptureAndUnwrapConversion(invocation.Arguments[0].ToArgument().Value).Kind == OperationKindEx.InstanceReference);

public static IOperation EffectiveInstance(this IInvocationOperationWrapper invocation, ProgramState state) =>
public static IOperation Target(this IInvocationOperationWrapper invocation, ProgramState state) =>
invocation.Instance
?? (invocation.TargetMethod.IsExtensionMethod
? state.ResolveCaptureAndUnwrapConversion(invocation.Arguments[0].ToArgument().Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static ProgramState LearnFrom(ProgramState state, IInvocationOperationWra
{
return state.SetOperationConstraint(invocation, constraint);
}
if (invocation.EffectiveInstance(state) is { } instance && instance.Type.DerivesOrImplementsAny(CollectionTypes))
if (invocation.Target(state) is { } instance && instance.Type.DerivesOrImplementsAny(CollectionTypes))
{
var targetMethod = invocation.TargetMethod;
var symbolValue = state[instance] ?? SymbolicValue.Empty;
Expand Down Expand Up @@ -182,7 +182,7 @@ private static NumberConstraint EnumerableCountConstraint(ProgramState state, II
{
if (invocation.TargetMethod.Is(KnownType.System_Linq_Enumerable, nameof(Enumerable.Count)))
{
if (invocation.EffectiveInstance(state).TrackedSymbol(state) is { } symbol
if (invocation.Target(state).TrackedSymbol(state) is { } symbol
&& state[symbol]?.Constraint<CollectionConstraint>() is { } collection)
{
if (collection == CollectionConstraint.Empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static ProgramState[] ProcessLinqEnumerableAndQueryable(ProgramState sta

static IEnumerable<ProgramState> ProcessElementOrDefaultMethods(ProgramState state, IInvocationOperationWrapper invocation)
{
var constraint = invocation.EffectiveInstance(state).TrackedSymbol(state) is { } instanceSymbol
var constraint = invocation.Target(state).TrackedSymbol(state) is { } instanceSymbol
&& GetElementType(instanceSymbol) is { } elementType
&& (elementType.IsReferenceType || elementType.IsNullableValueType())
? state[instanceSymbol]?.Constraint<CollectionConstraint>()
Expand All @@ -119,7 +119,7 @@ static IEnumerable<ProgramState> ProcessElementOrDefaultMethods(ProgramState sta

private static ProgramState[] ProcessElementExistsCheckMethods(ProgramState state, IInvocationOperationWrapper invocation)
{
if (ElementExistsCheckMethods.Contains(invocation.TargetMethod.Name) && invocation.EffectiveInstance(state).TrackedSymbol(state) is { } instanceSymbol)
if (ElementExistsCheckMethods.Contains(invocation.TargetMethod.Name) && invocation.Target(state).TrackedSymbol(state) is { } instanceSymbol)
{
return state[instanceSymbol]?.Constraint<CollectionConstraint>() switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override void ExecutionCompleted()
protected override ProgramState PreProcessSimple(SymbolicContext context)
{
if (context.Operation.Instance.AsInvocation() is { } invocation
&& invocation.EffectiveInstance(context.State) is { } instance
&& invocation.Target(context.State) is { } instance
&& RaisingMethods.Contains(invocation.TargetMethod.Name))
{
if (context.State[instance]?.HasConstraint(CollectionConstraint.Empty) is true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void ExtensionMethod(this Sample sample) {}
var (tree, model) = TestHelper.CompileCS(code);
var invocationSyntax = tree.GetRoot().DescendantNodesAndSelf().OfType<SyntaxCS.InvocationExpressionSyntax>().First();
var operation = IInvocationOperationWrapper.FromOperation(model.GetOperation(invocationSyntax));
operation.EffectiveInstance(ProgramState.Empty).Should().NotBeNull().And.BeAssignableTo<IOperation>().Which.Kind.Should().Be(kind);
operation.Target(ProgramState.Empty).Should().NotBeNull().And.BeAssignableTo<IOperation>().Which.Kind.Should().Be(kind);
}

[DataTestMethod]
Expand Down Expand Up @@ -96,6 +96,6 @@ End Module
var (tree, model) = TestHelper.CompileVB(code);
var invocationSyntax = tree.GetRoot().DescendantNodesAndSelf().OfType<SyntaxVB.InvocationExpressionSyntax>().First();
var operation = IInvocationOperationWrapper.FromOperation(model.GetOperation(invocationSyntax));
operation.EffectiveInstance(ProgramState.Empty).Should().NotBeNull().And.BeAssignableTo<IOperation>().Which.Kind.Should().Be(kind);
operation.Target(ProgramState.Empty).Should().NotBeNull().And.BeAssignableTo<IOperation>().Which.Kind.Should().Be(kind);
}
}

0 comments on commit 6f75804

Please sign in to comment.