|
1 | 1 | using System.Collections.Generic;
|
2 | 2 | using System.Linq;
|
| 3 | +using Antlr4.Runtime; |
| 4 | +using Rubberduck.Parsing; |
3 | 5 | using Rubberduck.Parsing.Symbols;
|
4 | 6 | using Rubberduck.Parsing.VBA;
|
5 | 7 |
|
@@ -27,10 +29,46 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
|
27 | 29 | .SelectMany(declaration => declaration.References)
|
28 | 30 | .Where(usage => !usage.IsInspectionDisabled(AnnotationName));
|
29 | 31 |
|
| 32 | + var lenFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.Len"); |
| 33 | + var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.LenB"); |
| 34 | + |
30 | 35 | foreach (var issue in usages)
|
31 | 36 | {
|
32 |
| - yield return new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName, issue.Declaration); |
| 37 | + if (DeclarationReferencesContainsReference(lenFunction, issue) || |
| 38 | + DeclarationReferencesContainsReference(lenbFunction, issue)) |
| 39 | + { |
| 40 | + continue; |
| 41 | + } |
| 42 | + |
| 43 | + yield return |
| 44 | + new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName, |
| 45 | + issue.Declaration); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private bool DeclarationReferencesContainsReference(Declaration parentDeclaration, IdentifierReference issue) |
| 50 | + { |
| 51 | + if (parentDeclaration == null) |
| 52 | + { |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + var lenUsesIssue = false; |
| 57 | + foreach (var reference in parentDeclaration.References) |
| 58 | + { |
| 59 | + var context = (ParserRuleContext) reference.Context.Parent; |
| 60 | + if (context.GetSelection().Contains(issue.Selection)) |
| 61 | + { |
| 62 | + lenUsesIssue = true; |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (lenUsesIssue) |
| 68 | + { |
| 69 | + return true; |
33 | 70 | }
|
| 71 | + return false; |
34 | 72 | }
|
35 | 73 | }
|
36 | 74 | }
|
0 commit comments