@@ -430,7 +430,7 @@ public void AddDeclaration(Declaration declaration)
430
430
}
431
431
}
432
432
433
- public void ClearStateCache ( VBProject project , bool setStateChanged = false )
433
+ public void ClearStateCache ( VBProject project , bool notifyStateChanged = false )
434
434
{
435
435
try
436
436
{
@@ -447,7 +447,7 @@ public void ClearStateCache(VBProject project, bool setStateChanged = false)
447
447
_declarations . Clear ( ) ;
448
448
}
449
449
450
- if ( setStateChanged )
450
+ if ( notifyStateChanged )
451
451
{
452
452
OnStateChanged ( ) ;
453
453
}
@@ -461,45 +461,18 @@ public void ClearBuiltInReferences()
461
461
}
462
462
}
463
463
464
- public bool ClearStateCache ( VBComponent component , bool setStateChanged = false )
464
+ public bool ClearStateCache ( VBComponent component , bool notifyStateChanged = false )
465
465
{
466
466
var match = new QualifiedModuleName ( component ) ;
467
467
var keys = _declarations . Keys . Where ( kvp => kvp . Equals ( match ) )
468
468
. Union ( new [ ] { match } ) . Distinct ( ) ; // make sure the key is present, even if there are no declarations left
469
469
470
- var success = true ;
471
- var declarationsRemoved = 0 ;
472
- foreach ( var key in keys )
473
- {
474
- ConcurrentDictionary < Declaration , byte > declarations = null ;
475
- success = success && ( ! _declarations . ContainsKey ( key ) || _declarations . TryRemove ( key , out declarations ) ) ;
476
- declarationsRemoved = declarations == null ? 0 : declarations . Count ;
477
-
478
- IParseTree tree ;
479
- success = success && ( ! _parseTrees . ContainsKey ( key ) || _parseTrees . TryRemove ( key , out tree ) ) ;
480
-
481
- int contentHash ;
482
- success = success && ( ! _moduleContentHashCodes . ContainsKey ( key ) || _moduleContentHashCodes . TryRemove ( key , out contentHash ) ) ;
483
-
484
- IList < IAnnotation > annotations ;
485
- success = success && ( ! _annotations . ContainsKey ( key ) || _annotations . TryRemove ( key , out annotations ) ) ;
486
-
487
- ITokenStream stream ;
488
- success = success && ( ! _tokenStreams . ContainsKey ( key ) || _tokenStreams . TryRemove ( key , out stream ) ) ;
489
-
490
- ParserState state ;
491
- success = success && ( ! _moduleStates . ContainsKey ( key ) || _moduleStates . TryRemove ( key , out state ) ) ;
492
-
493
- SyntaxErrorException exception ;
494
- success = success && ( ! _moduleExceptions . ContainsKey ( key ) || _moduleExceptions . TryRemove ( key , out exception ) ) ;
495
-
496
- IList < CommentNode > nodes ;
497
- success = success && ( ! _comments . ContainsKey ( key ) || _comments . TryRemove ( key , out nodes ) ) ;
498
- }
470
+ var success = RemoveKeysFromCollections ( keys ) ;
499
471
500
472
var projectId = component . Collection . Parent . HelpFile ;
501
473
var sameProjectDeclarations = _declarations . Where ( item => item . Key . ProjectId == projectId ) . ToList ( ) ;
502
- if ( sameProjectDeclarations . Any ( ) && sameProjectDeclarations . Count ( item => item . Value . Any ( key => key . Key . DeclarationType == DeclarationType . Project ) ) == sameProjectDeclarations . Count )
474
+ if ( sameProjectDeclarations . Any ( ) &&
475
+ sameProjectDeclarations . Count ( item => item . Value . Any ( key => key . Key . DeclarationType == DeclarationType . Project ) ) == sameProjectDeclarations . Count )
503
476
{
504
477
// only the project declaration is left; remove it.
505
478
ConcurrentDictionary < Declaration , byte > declarations ;
@@ -508,12 +481,11 @@ public bool ClearStateCache(VBComponent component, bool setStateChanged = false)
508
481
Debug . WriteLine ( string . Format ( "Removed Project declaration for project Id {0}" , projectId ) ) ;
509
482
}
510
483
511
- if ( setStateChanged )
484
+ if ( notifyStateChanged )
512
485
{
513
486
OnStateChanged ( ) ;
514
487
}
515
488
516
- Debug . WriteLine ( "ClearDeclarations({0}): {1} - {2} declarations removed" , component . Name , success ? "succeeded" : "failed" , declarationsRemoved ) ;
517
489
return success ;
518
490
}
519
491
@@ -522,13 +494,19 @@ public bool RemoveRenamedComponent(VBComponent component, string oldComponentNam
522
494
var match = new QualifiedModuleName ( component , oldComponentName ) ;
523
495
var keys = _declarations . Keys . Where ( kvp => kvp . ComponentName == oldComponentName && kvp . ProjectId == match . ProjectId ) ;
524
496
497
+ var success = RemoveKeysFromCollections ( keys ) ;
498
+
499
+ OnStateChanged ( ) ;
500
+ return success ;
501
+ }
502
+
503
+ private bool RemoveKeysFromCollections ( IEnumerable < QualifiedModuleName > keys )
504
+ {
525
505
var success = true ;
526
- var declarationsRemoved = 0 ;
527
506
foreach ( var key in keys )
528
507
{
529
- ConcurrentDictionary < Declaration , byte > declarations = null ;
508
+ ConcurrentDictionary < Declaration , byte > declarations ;
530
509
success = success && ( ! _declarations . ContainsKey ( key ) || _declarations . TryRemove ( key , out declarations ) ) ;
531
- declarationsRemoved = declarations == null ? 0 : declarations . Count ;
532
510
533
511
IParseTree tree ;
534
512
success = success && ( ! _parseTrees . ContainsKey ( key ) || _parseTrees . TryRemove ( key , out tree ) ) ;
@@ -552,9 +530,6 @@ public bool RemoveRenamedComponent(VBComponent component, string oldComponentNam
552
530
success = success && ( ! _comments . ContainsKey ( key ) || _comments . TryRemove ( key , out nodes ) ) ;
553
531
}
554
532
555
- OnStateChanged ( ) ;
556
-
557
- Debug . WriteLine ( "RemoveRenamedComponent({0}): {1} - {2} declarations removed" , oldComponentName , success ? "succeeded" : "failed" , declarationsRemoved ) ;
558
533
return success ;
559
534
}
560
535
0 commit comments