|
6 | 6 | using Rubberduck.Parsing.Inspections.Abstract;
|
7 | 7 | using Rubberduck.Resources.Inspections;
|
8 | 8 | using Rubberduck.Parsing.VBA;
|
9 |
| -using Rubberduck.Inspections.Inspections.Extensions; |
| 9 | +using Rubberduck.Parsing.Symbols; |
| 10 | +using Rubberduck.Parsing.VBA.DeclarationCaching; |
10 | 11 |
|
11 | 12 | namespace Rubberduck.Inspections.Concrete
|
12 | 13 | {
|
@@ -36,7 +37,7 @@ public sealed class UntypedFunctionUsageInspection : InspectionBase
|
36 | 37 | public UntypedFunctionUsageInspection(RubberduckParserState state)
|
37 | 38 | : base(state) { }
|
38 | 39 |
|
39 |
| - private readonly string[] _tokens = { |
| 40 | + private readonly HashSet<string> _tokens = new HashSet<string>{ |
40 | 41 | Tokens.Error,
|
41 | 42 | Tokens.Hex,
|
42 | 43 | Tokens.Oct,
|
@@ -64,17 +65,46 @@ public UntypedFunctionUsageInspection(RubberduckParserState state)
|
64 | 65 |
|
65 | 66 | protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
|
66 | 67 | {
|
67 |
| - var declarations = BuiltInDeclarations |
68 |
| - .Where(item => |
69 |
| - _tokens.Any(token => item.IdentifierName == token || item.IdentifierName == "_B_var_" + token) && |
70 |
| - item.Scope.StartsWith("VBE7.DLL;")); |
| 68 | + var finder = State.DeclarationFinder; |
71 | 69 |
|
72 |
| - return declarations.SelectMany(declaration => declaration.References |
73 |
| - .Where(item => _tokens.Contains(item.IdentifierName)) |
74 |
| - .Select(item => new IdentifierReferenceInspectionResult(this, |
75 |
| - string.Format(InspectionResults.UntypedFunctionUsageInspection, item.Declaration.IdentifierName), |
76 |
| - State, |
77 |
| - item))); |
| 70 | + var declarationsToConsider = BuiltInVariantStringFunctionsWithStringTypedVersion(finder); |
| 71 | + |
| 72 | + return declarationsToConsider |
| 73 | + .SelectMany(NonStringHintedReferences) |
| 74 | + .Select(Result); |
| 75 | + } |
| 76 | + |
| 77 | + private IEnumerable<Declaration> BuiltInVariantStringFunctionsWithStringTypedVersion(DeclarationFinder finder) |
| 78 | + { |
| 79 | + return finder |
| 80 | + .BuiltInDeclarations(DeclarationType.Member) |
| 81 | + .Where(item => (_tokens.Contains(item.IdentifierName) |
| 82 | + || item.IdentifierName.StartsWith("_B_var_") |
| 83 | + && _tokens.Contains(item.IdentifierName.Substring("_B_var_".Length))) |
| 84 | + && item.Scope.StartsWith("VBE7.DLL;")); |
| 85 | + } |
| 86 | + |
| 87 | + private IEnumerable<IdentifierReference> NonStringHintedReferences(Declaration declaration) |
| 88 | + { |
| 89 | + return declaration.References |
| 90 | + .Where(item => _tokens.Contains(item.IdentifierName)); |
| 91 | + } |
| 92 | + |
| 93 | + private IInspectionResult Result(IdentifierReference reference) |
| 94 | + { |
| 95 | + return new IdentifierReferenceInspectionResult( |
| 96 | + this, |
| 97 | + ResultDescription(reference), |
| 98 | + State, |
| 99 | + reference); |
| 100 | + } |
| 101 | + |
| 102 | + private static string ResultDescription(IdentifierReference reference) |
| 103 | + { |
| 104 | + var declarationName = reference.Declaration.IdentifierName; |
| 105 | + return string.Format( |
| 106 | + InspectionResults.UntypedFunctionUsageInspection, |
| 107 | + declarationName); |
78 | 108 | }
|
79 | 109 | }
|
80 | 110 | }
|
0 commit comments