Skip to content

Commit 79a96ee

Browse files
committed
Removed direct useage of dictionary keys
1 parent 8a1d8bd commit 79a96ee

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureCanBeWrittenAsFunctionInspection.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3636
.Concat(builtinHandlers)
3737
.Concat(userDeclarations.Where(item => item.IsWithEvents)));
3838

39+
bool HasArgumentReferencesWithIsAssignmentFlagged(QualifiedContext<ParserRuleContext> context)
40+
=> contextLookup.TryGetValue(context.Context.GetChild<VBAParser.ArgContext>(), out Declaration decl)
41+
? decl.References.Any(rf => rf.IsAssignment) : false;
42+
43+
Declaration GetSubStmtParentDeclaration(QualifiedContext<ParserRuleContext> context)
44+
=> contextLookup.TryGetValue((VBAParser.SubStmtContext)context.Context.Parent, out Declaration decl)
45+
? decl : null;
46+
3947
return Listener.Contexts
4048
.Where(context => context.Context.Parent is VBAParser.SubStmtContext
41-
&& contextLookup[context.Context.GetChild<VBAParser.ArgContext>()].References
42-
.Any(reference => reference.IsAssignment))
43-
.Select(context => contextLookup[(VBAParser.SubStmtContext)context.Context.Parent])
44-
.Where(decl => !IsIgnoringInspectionResultFor(decl, AnnotationName) &&
45-
!ignored.Contains(decl) &&
46-
userDeclarations.Where(item => item.IsWithEvents)
49+
&& HasArgumentReferencesWithIsAssignmentFlagged(context))
50+
.Select(context => GetSubStmtParentDeclaration(context))
51+
.Where(decl => decl != null &&
52+
!IsIgnoringInspectionResultFor(decl, AnnotationName) &&
53+
!ignored.Contains(decl) &&
54+
userDeclarations.Where(item => item.IsWithEvents)
4755
.All(withEvents => userDeclarations.FindEventProcedures(withEvents) == null) &&
4856
!builtinHandlers.Contains(decl))
4957
.Select(result => new DeclarationInspectionResult(this,

0 commit comments

Comments
 (0)