@@ -29,7 +29,7 @@ public Declaration(QualifiedMemberName qualifiedName, Declaration parentDeclarat
29
29
{
30
30
_qualifiedName = qualifiedName ;
31
31
_parentDeclaration = parentDeclaration ;
32
- _parentScope = parentScope ;
32
+ _parentScope = parentScope ?? string . Empty ;
33
33
_identifierName = qualifiedName . MemberName ;
34
34
_asTypeName = asTypeName ;
35
35
_isSelfAssigned = isSelfAssigned ;
@@ -57,6 +57,10 @@ public Declaration(QualifiedMemberName qualifiedName, Declaration parentDeclarat
57
57
result = value ;
58
58
}
59
59
_customFolder = result ;
60
+
61
+ _isArray = IsArray ( ) ;
62
+ _hasTypeHint = HasTypeHint ( ) ;
63
+ _isTypeSpecified = IsTypeSpecified ( ) ;
60
64
}
61
65
62
66
/// <summary>
@@ -210,13 +214,33 @@ public void AddMemberCall(IdentifierReference reference)
210
214
/// </remarks>
211
215
public string AsTypeName { get { return _asTypeName ; } }
212
216
217
+ private bool ? _isArray ;
218
+
213
219
public bool IsArray ( )
214
220
{
215
- if ( Context == null )
221
+ if ( Context == null || _isArray . HasValue && ! _isArray . Value )
216
222
{
217
223
return false ;
218
224
}
219
225
226
+ if ( _isArray . HasValue )
227
+ {
228
+ return _isArray . Value ;
229
+ }
230
+
231
+ //var variableContext = Context as VBAParser.VariableSubStmtContext;
232
+ //if (variableContext != null)
233
+ //{
234
+ // return variableContext.LPAREN() != null && variableContext.RPAREN() != null;
235
+ //}
236
+
237
+ //var typeElementContext = Context as VBAParser.TypeStmt_ElementContext;
238
+ //if (typeElementContext != null)
239
+ //{
240
+ // return typeElementContext.LPAREN() != null && typeElementContext.RPAREN() != null;
241
+ //}
242
+ //return false;
243
+
220
244
try
221
245
{
222
246
var declaration = ( dynamic ) Context ;
@@ -228,16 +252,61 @@ public bool IsArray()
228
252
}
229
253
}
230
254
255
+ private bool ? _isTypeSpecified ;
256
+
231
257
public bool IsTypeSpecified ( )
232
258
{
233
- if ( Context == null )
259
+ if ( Context == null || _isTypeSpecified . HasValue && ! _isTypeSpecified . Value )
234
260
{
235
261
return false ;
236
262
}
237
263
264
+ if ( _isTypeSpecified . HasValue )
265
+ {
266
+ return _isTypeSpecified . Value ;
267
+ }
268
+
269
+ //var variableContext = Context as VBAParser.VariableSubStmtContext;
270
+ //if (variableContext != null)
271
+ //{
272
+ // return variableContext.asTypeClause() != null || HasTypeHint();
273
+ //}
274
+
275
+ //var argContext = Context as VBAParser.ArgContext;
276
+ //if (argContext != null)
277
+ //{
278
+ // return argContext.asTypeClause() != null || HasTypeHint();
279
+ //}
280
+
281
+ //var constContext = Context as VBAParser.ConstSubStmtContext;
282
+ //if (constContext != null)
283
+ //{
284
+ // return constContext.asTypeClause() != null || HasTypeHint();
285
+ //}
286
+
287
+ //var functionContext = Context as VBAParser.FunctionStmtContext;
288
+ //if (functionContext != null)
289
+ //{
290
+ // return functionContext.asTypeClause() != null || HasTypeHint();
291
+ //}
292
+
293
+ //var getterContext = Context as VBAParser.PropertyGetStmtContext;
294
+ //if (getterContext != null)
295
+ //{
296
+ // return getterContext.asTypeClause() != null || HasTypeHint();
297
+ //}
298
+
299
+ //var typeElementContext = Context as VBAParser.TypeStmt_ElementContext;
300
+ //if (typeElementContext != null)
301
+ //{
302
+ // return typeElementContext.asTypeClause() != null || HasTypeHint();
303
+ //}
304
+
305
+ //return false;
306
+
238
307
try
239
308
{
240
- var asType = ( ( dynamic ) Context ) . asTypeClause ( ) as VBAParser . AsTypeClauseContext ;
309
+ var asType = ( ( dynamic ) Context ) . asTypeClause ( ) as VBAParser . AsTypeClauseContext ;
241
310
return asType != null || HasTypeHint ( ) ;
242
311
}
243
312
catch ( RuntimeBinderException )
@@ -246,8 +315,15 @@ public bool IsTypeSpecified()
246
315
}
247
316
}
248
317
318
+ private bool ? _hasTypeHint ;
319
+
249
320
public bool HasTypeHint ( )
250
321
{
322
+ if ( _hasTypeHint . HasValue )
323
+ {
324
+ return _hasTypeHint . Value ;
325
+ }
326
+
251
327
string token ;
252
328
return HasTypeHint ( out token ) ;
253
329
}
@@ -260,6 +336,47 @@ public bool HasTypeHint(out string token)
260
336
return false ;
261
337
}
262
338
339
+ //VBAParser.TypeHintContext hint = null;
340
+ //var variableContext = Context as VBAParser.VariableSubStmtContext;
341
+ //if (variableContext != null)
342
+ //{
343
+ // hint = variableContext.typeHint();
344
+ //}
345
+
346
+ ////var argContext = Context as VBAParser.ArgContext;
347
+ ////if (argContext != null)
348
+ ////{
349
+ //// hint = argContext.typeHint();
350
+ ////}
351
+
352
+ //var constContext = Context as VBAParser.ConstSubStmtContext;
353
+ //if (constContext != null)
354
+ //{
355
+ // hint = constContext.typeHint();
356
+ //}
357
+
358
+ //var functionContext = Context as VBAParser.FunctionStmtContext;
359
+ //if (functionContext != null)
360
+ //{
361
+ // hint = functionContext.typeHint();
362
+ //}
363
+
364
+ //var getterContext = Context as VBAParser.PropertyGetStmtContext;
365
+ //if (getterContext != null)
366
+ //{
367
+ // hint = getterContext.typeHint();
368
+ //}
369
+
370
+ ////var typeElementContext = Context as VBAParser.TypeStmt_ElementContext;
371
+ ////if (typeElementContext != null)
372
+ ////{
373
+ //// hint = typeElementContext.typeHint();
374
+ ////}
375
+
376
+ //token = hint == null ? null : hint.GetText();
377
+ //return hint != null;
378
+
379
+
263
380
try
264
381
{
265
382
var hint = ( ( dynamic ) Context ) . typeHint ( ) as VBAParser . TypeHintContext ;
@@ -350,7 +467,8 @@ public bool Equals(Declaration other)
350
467
&& other . IdentifierName == IdentifierName
351
468
&& other . DeclarationType == DeclarationType
352
469
&& other . Scope == Scope
353
- && other . ParentScope == ParentScope ;
470
+ && other . ParentScope == ParentScope
471
+ && other . Selection . Equals ( Selection ) ;
354
472
}
355
473
356
474
public override bool Equals ( object obj )
@@ -360,7 +478,17 @@ public override bool Equals(object obj)
360
478
361
479
public override int GetHashCode ( )
362
480
{
363
- return string . Concat ( QualifiedName . QualifiedModuleName . ProjectHashCode , _identifierName , _declarationType , Scope , _parentScope ) . GetHashCode ( ) ;
481
+ unchecked
482
+ {
483
+ var hash = 17 ;
484
+ hash = hash * 23 + QualifiedName . QualifiedModuleName . ProjectHashCode ;
485
+ hash = hash * 23 + _identifierName . GetHashCode ( ) ;
486
+ hash = hash * 23 + _declarationType . GetHashCode ( ) ;
487
+ hash = hash * 23 + Scope . GetHashCode ( ) ;
488
+ hash = hash * 23 + _parentScope == null ? 0 : _parentScope . GetHashCode ( ) ;
489
+ hash = hash * 23 + _selection . GetHashCode ( ) ;
490
+ return hash ;
491
+ }
364
492
}
365
493
}
366
494
}
0 commit comments