Skip to content

Commit 7b66c06

Browse files
CopilotYunchuWang
andcommitted
Address code quality review comments: use LINQ Where/Any and combine nested if statements
Co-authored-by: YunchuWang <[email protected]>
1 parent 414c182 commit 7b66c06

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

src/Analyzers/Activities/FunctionNotFoundAnalyzer.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,10 @@ public override void Initialize(AnalysisContext context)
163163
}
164164

165165
// Check for TaskActivity<TInput, TOutput> derived classes
166-
if (knownSymbols.TaskActivityBase != null && taskActivityRunAsync != null)
166+
if (knownSymbols.TaskActivityBase != null && taskActivityRunAsync != null &&
167+
ClassOverridesMethod(classSymbol, taskActivityRunAsync))
167168
{
168-
if (ClassOverridesMethod(classSymbol, taskActivityRunAsync))
169-
{
170-
activityNames.Add(classSymbol.Name);
171-
}
169+
activityNames.Add(classSymbol.Name);
172170
}
173171

174172
// Check for ITaskOrchestrator implementations (class-based orchestrators)
@@ -227,25 +225,19 @@ public override void Initialize(AnalysisContext context)
227225
HashSet<string> definedOrchestrators = new(orchestratorNames);
228226

229227
// Report diagnostics for activities not found
230-
foreach (FunctionInvocation invocation in activityInvocations)
228+
foreach (FunctionInvocation invocation in activityInvocations.Where(i => !definedActivities.Contains(i.Name)))
231229
{
232-
if (!definedActivities.Contains(invocation.Name))
233-
{
234-
Diagnostic diagnostic = RoslynExtensions.BuildDiagnostic(
235-
ActivityNotFoundRule, invocation.InvocationSyntaxNode, invocation.Name);
236-
ctx.ReportDiagnostic(diagnostic);
237-
}
230+
Diagnostic diagnostic = RoslynExtensions.BuildDiagnostic(
231+
ActivityNotFoundRule, invocation.InvocationSyntaxNode, invocation.Name);
232+
ctx.ReportDiagnostic(diagnostic);
238233
}
239234

240235
// Report diagnostics for sub-orchestrators not found
241-
foreach (FunctionInvocation invocation in subOrchestrationInvocations)
236+
foreach (FunctionInvocation invocation in subOrchestrationInvocations.Where(i => !definedOrchestrators.Contains(i.Name)))
242237
{
243-
if (!definedOrchestrators.Contains(invocation.Name))
244-
{
245-
Diagnostic diagnostic = RoslynExtensions.BuildDiagnostic(
246-
SubOrchestrationNotFoundRule, invocation.InvocationSyntaxNode, invocation.Name);
247-
ctx.ReportDiagnostic(diagnostic);
248-
}
238+
Diagnostic diagnostic = RoslynExtensions.BuildDiagnostic(
239+
SubOrchestrationNotFoundRule, invocation.InvocationSyntaxNode, invocation.Name);
240+
ctx.ReportDiagnostic(diagnostic);
249241
}
250242
});
251243
});
@@ -281,12 +273,10 @@ static bool ClassOverridesMethod(INamedTypeSymbol classSymbol, IMethodSymbol met
281273
INamedTypeSymbol? baseType = classSymbol;
282274
while (baseType != null)
283275
{
284-
foreach (IMethodSymbol method in baseType.GetMembers().OfType<IMethodSymbol>())
276+
if (baseType.GetMembers().OfType<IMethodSymbol>()
277+
.Any(method => SymbolEqualityComparer.Default.Equals(method.OverriddenMethod?.OriginalDefinition, methodToFind)))
285278
{
286-
if (SymbolEqualityComparer.Default.Equals(method.OverriddenMethod?.OriginalDefinition, methodToFind))
287-
{
288-
return true;
289-
}
279+
return true;
290280
}
291281

292282
baseType = baseType.BaseType;

0 commit comments

Comments
 (0)