-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathLibraryReferencedDeclarationsCollector.cs
44 lines (37 loc) · 1.58 KB
/
LibraryReferencedDeclarationsCollector.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
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;
namespace Rubberduck.Parsing.ComReflection
{
public class LibraryReferencedDeclarationsCollector : ReferencedDeclarationsCollectorBase
{
private readonly IComLibraryProvider _comLibraryProvider;
public LibraryReferencedDeclarationsCollector(IDeclarationsFromComProjectLoader declarationsFromComProjectLoader, IComLibraryProvider comLibraryProvider)
:base(declarationsFromComProjectLoader)
{
_comLibraryProvider = comLibraryProvider;
}
public override IReadOnlyCollection<Declaration> CollectedDeclarations(ReferenceInfo reference)
{
return LoadDeclarationsFromLibrary(reference);
}
private IReadOnlyCollection<Declaration> LoadDeclarationsFromLibrary(ReferenceInfo reference)
{
var libraryPath = reference.FullPath;
// Failure to load might mean that it's a "normal" VBProject that will get loaded through a different channel.
var typeLibrary = GetTypeLibrary(libraryPath);
if (typeLibrary == null)
{
return new List<Declaration>();
}
var type = new ComProject(typeLibrary, libraryPath);
var declarations = LoadDeclarationsFromComProject(type);
return declarations;
}
private ITypeLib GetTypeLibrary(string libraryPath)
{
return _comLibraryProvider.LoadTypeLibrary(libraryPath);
}
}
}