-
Notifications
You must be signed in to change notification settings - Fork 295
/
VBProjectParseResult.cs
76 lines (64 loc) · 2.65 KB
/
VBProjectParseResult.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime.Tree;
using Microsoft.Vbe.Interop;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;
namespace Rubberduck.Parsing
{
public class VBProjectParseResult
{
public VBProjectParseResult(VBProject project, IEnumerable<VBComponentParseResult> parseResults)
{
_project = project;
_parseResults = parseResults;
_declarations = new Declarations();
var projectIdentifier = project.Name;
var memberName = new QualifiedMemberName(new QualifiedModuleName(project), projectIdentifier);
var projectDeclaration = new Declaration(memberName, null, null, projectIdentifier, false, false, Accessibility.Global, DeclarationType.Project, false);
_declarations.Add(projectDeclaration);
foreach (var declaration in VbaStandardLib.Declarations)
{
_declarations.Add(declaration);
}
foreach (var declaration in _parseResults.SelectMany(item => item.Declarations))
{
_declarations.Add(declaration);
}
}
public event EventHandler<ResolutionProgressEventArgs> Progress;
private void OnProgress(VBComponentParseResult result)
{
var handler = Progress;
if (handler != null)
{
handler(null, new ResolutionProgressEventArgs(result.Component));
}
}
public void Resolve()
{
foreach (var componentParseResult in _parseResults)
{
OnProgress(componentParseResult);
try
{
var resolver = new IdentifierReferenceResolver(componentParseResult.QualifiedName, _declarations);
var listener = new IdentifierReferenceListener(resolver);
var walker = new ParseTreeWalker();
walker.Walk(listener, componentParseResult.ParseTree);
}
catch (InvalidOperationException)
{
// could not resolve all identifier references in this module.
}
}
}
private readonly IEnumerable<VBComponentParseResult> _parseResults;
private readonly Declarations _declarations;
public Declarations Declarations { get { return _declarations; } }
public IEnumerable<VBComponentParseResult> ComponentParseResults { get { return _parseResults; } }
private readonly VBProject _project;
public VBProject Project { get { return _project; } }
}
}