/
ImplicitWorkbookReferenceInspectionBase.cs
46 lines (39 loc) · 1.64 KB
/
ImplicitWorkbookReferenceInspectionBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.VBA.DeclarationCaching;
namespace Rubberduck.CodeAnalysis.Inspections.Abstract
{
internal abstract class ImplicitWorkbookReferenceInspectionBase : IdentifierReferenceInspectionFromDeclarationsBase
{
internal ImplicitWorkbookReferenceInspectionBase(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider)
{ }
private static readonly string[] InterestingMembers =
{
"Worksheets", "Sheets", "Names"
};
private static readonly string[] InterestingClasses =
{
"_Global", "_Application", "Global", "Application"
};
protected override IEnumerable<Declaration> ObjectionableDeclarations(DeclarationFinder finder)
{
var excel = finder.Projects
.SingleOrDefault(project => project.IdentifierName == "Excel" && !project.IsUserDefined);
if (excel == null)
{
return Enumerable.Empty<Declaration>();
}
var relevantClasses = InterestingClasses
.Select(className => finder.FindClassModule(className, excel, true))
.OfType<ModuleDeclaration>();
var relevantProperties = relevantClasses
.SelectMany(classDeclaration => classDeclaration.Members)
.OfType<PropertyGetDeclaration>()
.Where(member => InterestingMembers.Contains(member.IdentifierName));
return relevantProperties;
}
}
}