@@ -62,6 +62,7 @@ public sealed class RubberduckParserState : IDisposable, IDeclarationFinderProvi
62
62
63
63
public DeclarationFinder DeclarationFinder { get ; private set ; }
64
64
65
+ private readonly IVBE _vbe ;
65
66
private readonly IProjectsRepository _projectRepository ;
66
67
private readonly IHostApplication _hostApp ;
67
68
private readonly IDeclarationFinderFactory _declarationFinderFactory ;
@@ -76,7 +77,13 @@ public RubberduckParserState(IVBE vbe, IProjectsRepository projectRepository, ID
76
77
{
77
78
throw new ArgumentNullException ( nameof ( declarationFinderFactory ) ) ;
78
79
}
80
+ if ( projectRepository == null )
81
+ {
82
+ throw new ArgumentException ( nameof ( projectRepository ) ) ;
83
+ }
79
84
85
+
86
+ _vbe = vbe ;
80
87
_projectRepository = projectRepository ;
81
88
_declarationFinderFactory = declarationFinderFactory ;
82
89
@@ -86,7 +93,7 @@ public RubberduckParserState(IVBE vbe, IProjectsRepository projectRepository, ID
86
93
States . Add ( ( ParserState ) value ) ;
87
94
}
88
95
89
- _hostApp = vbe . HostApplication ( ) ;
96
+ _hostApp = _vbe . HostApplication ( ) ;
90
97
AddEventHandlers ( ) ;
91
98
IsEnabled = true ;
92
99
RefreshFinder ( _hostApp ) ;
@@ -128,7 +135,7 @@ private void RemoveEventHandlers()
128
135
129
136
private void Sinks_ProjectAdded ( object sender , ProjectEventArgs e )
130
137
{
131
- if ( ! e . Project . VBE . IsInDesignMode )
138
+ if ( ! _vbe . IsInDesignMode )
132
139
{
133
140
return ;
134
141
}
@@ -139,7 +146,7 @@ private void Sinks_ProjectAdded(object sender, ProjectEventArgs e)
139
146
140
147
private void Sinks_ProjectRemoved ( object sender , ProjectEventArgs e )
141
148
{
142
- if ( ! e . Project . VBE . IsInDesignMode )
149
+ if ( ! _vbe . IsInDesignMode )
143
150
{
144
151
return ;
145
152
}
@@ -150,12 +157,7 @@ private void Sinks_ProjectRemoved(object sender, ProjectEventArgs e)
150
157
151
158
private void Sinks_ProjectRenamed ( object sender , ProjectRenamedEventArgs e )
152
159
{
153
- if ( ! e . Project . VBE . IsInDesignMode )
154
- {
155
- return ;
156
- }
157
-
158
- if ( ! ThereAreDeclarations ( ) )
160
+ if ( ! _vbe . IsInDesignMode || ! ThereAreDeclarations ( ) )
159
161
{
160
162
return ;
161
163
}
@@ -167,9 +169,7 @@ private void Sinks_ProjectRenamed(object sender, ProjectRenamedEventArgs e)
167
169
168
170
private void Sinks_ComponentAdded ( object sender , ComponentEventArgs e )
169
171
{
170
- if ( ! e . Project . VBE . IsInDesignMode ) { return ; }
171
-
172
- if ( ! ThereAreDeclarations ( ) )
172
+ if ( ! _vbe . IsInDesignMode || ! ThereAreDeclarations ( ) )
173
173
{
174
174
return ;
175
175
}
@@ -180,9 +180,7 @@ private void Sinks_ComponentAdded(object sender, ComponentEventArgs e)
180
180
181
181
private void Sinks_ComponentRemoved ( object sender , ComponentEventArgs e )
182
182
{
183
- if ( ! e . Project . VBE . IsInDesignMode ) { return ; }
184
-
185
- if ( ! ThereAreDeclarations ( ) )
183
+ if ( ! _vbe . IsInDesignMode || ! ThereAreDeclarations ( ) )
186
184
{
187
185
return ;
188
186
}
@@ -193,12 +191,7 @@ private void Sinks_ComponentRemoved(object sender, ComponentEventArgs e)
193
191
194
192
private void Sinks_ComponentRenamed ( object sender , ComponentRenamedEventArgs e )
195
193
{
196
- if ( ! e . Project . VBE . IsInDesignMode )
197
- {
198
- return ;
199
- }
200
-
201
- if ( ! ThereAreDeclarations ( ) )
194
+ if ( ! _vbe . IsInDesignMode || ! ThereAreDeclarations ( ) )
202
195
{
203
196
return ;
204
197
}
0 commit comments