Skip to content

Commit 5da3d59

Browse files
committed
Partial rollback of refactor pending reliable unit testing.
1 parent a63f05c commit 5da3d59

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Collections.Generic;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Linq;
4+
using Antlr4.Runtime;
45
using Rubberduck.Inspections.Abstract;
56
using Rubberduck.Inspections.Results;
7+
using Rubberduck.Parsing;
68
using Rubberduck.Parsing.Inspections.Abstract;
79
using Rubberduck.Resources.Inspections;
810
using Rubberduck.Parsing.Symbols;
@@ -36,8 +38,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3638

3739
var excludedDeclarations = BuiltInDeclarations.Where(decl => IgnoredFunctions.Contains(decl.QualifiedName.ToString())).ToList();
3840

39-
return declarations.Except(excludedDeclarations)
40-
.Where(d => d.References.Any())
41+
return declarations
42+
.Where(d => d.References.Any() && !excludedDeclarations.Any(excl => DeclarationReferencesContainsReference(excl, d)))
4143
.SelectMany(d => d.References)
4244
.Distinct()
4345
.Where(r => !r.IsIgnoringInspectionResultFor(AnnotationName))
@@ -46,5 +48,22 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4648
State,
4749
r)).ToList();
4850
}
51+
52+
private static bool DeclarationReferencesContainsReference(Declaration parentDeclaration, Declaration target)
53+
{
54+
foreach (var targetReference in target.References)
55+
{
56+
foreach (var reference in parentDeclaration.References)
57+
{
58+
var context = (ParserRuleContext)reference.Context.Parent;
59+
if (context.GetSelection().Contains(targetReference.Selection))
60+
{
61+
return true;
62+
}
63+
}
64+
}
65+
66+
return false;
67+
}
4968
}
5069
}

0 commit comments

Comments
 (0)