Skip to content

Commit 49226d3

Browse files
committed
Cleanup
1 parent 198e945 commit 49226d3

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

WpfAnalyzers/Analyzers/RoutedEventCallbackAnalyzer.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,59 +34,59 @@ callbackArg.Expression is IdentifierNameSyntax &&
3434
if (EventManager.RegisterClassHandler.Match(invocation, context.SemanticModel, context.CancellationToken) is { Target: { } target, EventArgument: { } eventArgument })
3535
{
3636
if (Callback.SingleInvocation(target, invocation.FirstAncestorOrSelf<TypeDeclarationSyntax>(), context) is { } &&
37-
CheckName(eventArgument, callbackArg) is var (messageArg, properties))
37+
CheckName(eventArgument, callbackArg) is var (expectedName, properties))
3838
{
3939
context.ReportDiagnostic(
4040
Diagnostic.Create(
4141
Descriptors.WPF0090RegisterClassHandlerCallbackNameShouldMatchEvent,
4242
callbackArg.GetLocation(),
4343
properties,
44-
messageArg));
44+
expectedName));
4545
}
4646
}
4747
else if ((EventManager.AddHandler.Match(invocation, context.SemanticModel, context.CancellationToken) is { } ||
4848
EventManager.RemoveHandler.Match(invocation, context.SemanticModel, context.CancellationToken) is { }) &&
4949
invocation.TryGetArgumentAtIndex(0, out eventArgument))
5050
{
51-
if (CheckName(eventArgument, callbackArg) is var (messageArg, properties))
51+
if (CheckName(eventArgument, callbackArg) is var (expectedName, properties))
5252
{
5353
context.ReportDiagnostic(
5454
Diagnostic.Create(
5555
Descriptors.WPF0091AddAndRemoveHandlerCallbackNameShouldMatchEvent,
5656
callbackArg.GetLocation(),
5757
properties,
58-
messageArg));
58+
expectedName));
5959
}
6060
}
61-
}
62-
}
6361

64-
private static (string MessageArg, ImmutableDictionary<string, string?> Properties)? CheckName(ArgumentSyntax eventArgument, ArgumentSyntax callbackArg)
65-
{
66-
if (callbackArg.Expression is IdentifierNameSyntax invokedHandler &&
67-
Identifier() is { } identifier)
68-
{
69-
if (EventManager.IsMatch(invokedHandler.Identifier.ValueText, identifier.Identifier.ValueText) == false)
62+
static (string ExpectedName, ImmutableDictionary<string, string?> Properties)? CheckName(ArgumentSyntax eventArgument, ArgumentSyntax callbackArg)
7063
{
71-
if (EventManager.TryGetExpectedCallbackName(identifier.Identifier.ValueText, out var expectedName))
64+
if (callbackArg.Expression is IdentifierNameSyntax invokedHandler &&
65+
Identifier() is { } identifier)
7266
{
73-
return (expectedName, ImmutableDictionary<string, string?>.Empty.Add("ExpectedName", expectedName));
74-
}
67+
if (EventManager.IsMatch(invokedHandler.Identifier.ValueText, identifier.Identifier.ValueText) == false)
68+
{
69+
if (EventManager.TryGetExpectedCallbackName(identifier.Identifier.ValueText, out var expectedName))
70+
{
71+
return (expectedName, ImmutableDictionary<string, string?>.Empty.Add("ExpectedName", expectedName));
72+
}
7573

76-
return ("On" + identifier.Identifier.ValueText, ImmutableDictionary<string, string?>.Empty);
77-
}
78-
}
74+
return ("On" + identifier.Identifier.ValueText, ImmutableDictionary<string, string?>.Empty);
75+
}
76+
}
7977

80-
return null;
78+
return null;
8179

82-
IdentifierNameSyntax? Identifier()
83-
{
84-
return eventArgument switch
85-
{
86-
{ Expression: IdentifierNameSyntax name } => name,
87-
{ Expression: MemberAccessExpressionSyntax { Name: IdentifierNameSyntax name } } => name,
88-
_ => null,
89-
};
80+
IdentifierNameSyntax? Identifier()
81+
{
82+
return eventArgument switch
83+
{
84+
{ Expression: IdentifierNameSyntax name } => name,
85+
{ Expression: MemberAccessExpressionSyntax { Name: IdentifierNameSyntax name } } => name,
86+
_ => null,
87+
};
88+
}
89+
}
9090
}
9191
}
9292
}

WpfAnalyzers/Helpers/EventManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal RegisterClassHandler(InvocationExpressionSyntax invocation, IMethodSymb
6262

6363
internal static RegisterClassHandler? Match(InvocationExpressionSyntax invocation, SemanticModel semanticModel, CancellationToken cancellationToken)
6464
{
65-
if (invocation is { ArgumentList.Arguments: { Count: 3 or 4 } } &&
65+
if (invocation is { ArgumentList.Arguments.Count: 3 or 4 } &&
6666
semanticModel.TryGetSymbol(invocation, KnownSymbols.EventManager.RegisterClassHandler, cancellationToken, out var method))
6767
{
6868
return new RegisterClassHandler(invocation, method);

0 commit comments

Comments
 (0)