1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using System . Linq ;
4
5
using System . Threading ;
5
6
using System . Threading . Tasks ;
@@ -19,15 +20,17 @@ public sealed class MemberAttributeRecoverer : IMemberAttributeRecovererWithSett
19
20
private IRewritingManager _rewritingManager ;
20
21
private readonly IMemberAttributeRecoveryFailureNotifier _failureNotifier ;
21
22
22
- private readonly
23
- IDictionary < QualifiedModuleName , IDictionary < string , HashSet < AttributeNode > > > _attributesToRecover
24
- = new Dictionary < QualifiedModuleName , IDictionary < string , HashSet < AttributeNode > > > ( ) ;
25
- private readonly HashSet < QualifiedMemberName > _missingMembers = new HashSet < QualifiedMemberName > ( ) ;
23
+ private readonly IDictionary < QualifiedModuleName , IDictionary < ( string memberName , DeclarationType memberType ) , HashSet < AttributeNode > > > _attributesToRecover
24
+ = new Dictionary < QualifiedModuleName , IDictionary < ( string memberName , DeclarationType memberType ) , HashSet < AttributeNode > > > ( ) ;
25
+ private readonly HashSet < ( QualifiedMemberName memberName , DeclarationType memberType ) > _missingMembers = new HashSet < ( QualifiedMemberName memberName , DeclarationType memberType ) > ( ) ;
26
26
27
27
private readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
28
28
29
- public MemberAttributeRecoverer ( IDeclarationFinderProvider declarationFinderProvider ,
30
- IParseManager parseManager , IAttributesUpdater attributesUpdater , IMemberAttributeRecoveryFailureNotifier failureNotifier )
29
+ public MemberAttributeRecoverer (
30
+ IDeclarationFinderProvider declarationFinderProvider ,
31
+ IParseManager parseManager ,
32
+ IAttributesUpdater attributesUpdater ,
33
+ IMemberAttributeRecoveryFailureNotifier failureNotifier )
31
34
{
32
35
_declarationFinderProvider = declarationFinderProvider ;
33
36
_parseManager = parseManager ;
@@ -83,7 +86,7 @@ private void SaveAttributesToRecover(IDictionary<QualifiedModuleName, IEnumerabl
83
86
var attributesByMember = declarationsByModule [ module ]
84
87
. Where ( decl => decl . Attributes . Any ( ) )
85
88
. ToDictionary (
86
- decl => decl . IdentifierName ,
89
+ decl => ( decl . IdentifierName , decl . DeclarationType ) ,
87
90
decl => ( HashSet < AttributeNode > ) decl . Attributes ) ;
88
91
_attributesToRecover . Add ( module , attributesByMember ) ;
89
92
}
@@ -154,41 +157,41 @@ private void CancelTheCurrentParse()
154
157
_parseManager . OnParseCancellationRequested ( this ) ;
155
158
}
156
159
157
- private void RecoverAttributes ( IRewriteSession rewriteSession , QualifiedModuleName module , IDictionary < string , HashSet < AttributeNode > > attributesByMember )
160
+ private void RecoverAttributes ( IRewriteSession rewriteSession , QualifiedModuleName module , IDictionary < ( string memberName , DeclarationType memberType ) , HashSet < AttributeNode > > attributesByMember )
158
161
{
159
162
var membersWithAttributesToRecover = attributesByMember . Keys . ToHashSet ( ) ;
160
163
var declarationFinder = _declarationFinderProvider . DeclarationFinder ;
161
164
var declarationsWithAttributesToRecover = declarationFinder . Members ( module )
162
- . Where ( decl => membersWithAttributesToRecover . Contains ( decl . IdentifierName )
165
+ . Where ( decl => membersWithAttributesToRecover . Contains ( ( decl . IdentifierName , decl . DeclarationType ) )
163
166
&& decl . ParentScopeDeclaration . DeclarationType . HasFlag ( DeclarationType . Module ) )
164
167
. ToList ( ) ;
165
168
166
169
if ( membersWithAttributesToRecover . Count != declarationsWithAttributesToRecover . Count )
167
170
{
168
171
var membersWithoutDeclarations = MembersWithoutDeclarations ( membersWithAttributesToRecover , declarationsWithAttributesToRecover ) ;
169
172
LogFailureToRecoverAllAttributes ( module , membersWithoutDeclarations ) ;
170
- _missingMembers . UnionWith ( membersWithoutDeclarations . Select ( memberName => new QualifiedMemberName ( module , memberName ) ) ) ;
173
+ _missingMembers . UnionWith ( membersWithoutDeclarations . Select ( tpl => ( new QualifiedMemberName ( module , tpl . memberName ) , tpl . memberType ) ) ) ;
171
174
}
172
175
173
176
foreach ( var declaration in declarationsWithAttributesToRecover )
174
177
{
175
- RecoverAttributes ( rewriteSession , declaration , attributesByMember [ declaration . IdentifierName ] ) ;
178
+ RecoverAttributes ( rewriteSession , declaration , attributesByMember [ ( declaration . IdentifierName , declaration . DeclarationType ) ] ) ;
176
179
}
177
180
}
178
181
179
- private static ICollection < string > MembersWithoutDeclarations ( HashSet < string > membersWithAttributesToRecover , IEnumerable < Declaration > declarationsWithAttributesToRecover )
182
+ private static ICollection < ( string memberName , DeclarationType memberType ) > MembersWithoutDeclarations ( HashSet < ( string memberName , DeclarationType memberType ) > membersWithAttributesToRecover , IEnumerable < Declaration > declarationsWithAttributesToRecover )
180
183
{
181
184
var membersWithoutDeclarations = membersWithAttributesToRecover . ToHashSet ( ) ;
182
- membersWithoutDeclarations . ExceptWith ( declarationsWithAttributesToRecover . Select ( decl => decl . IdentifierName ) ) ;
185
+ membersWithoutDeclarations . ExceptWith ( declarationsWithAttributesToRecover . Select ( decl => ( decl . IdentifierName , decl . DeclarationType ) ) ) ;
183
186
return membersWithoutDeclarations ;
184
187
}
185
188
186
- private void LogFailureToRecoverAllAttributes ( QualifiedModuleName module , IEnumerable < string > membersWithoutDeclarations )
189
+ private void LogFailureToRecoverAllAttributes ( QualifiedModuleName module , IEnumerable < ( string memberName , DeclarationType memberType ) > membersWithoutDeclarations )
187
190
{
188
191
_logger . Warn ( "Could not recover the attributes for all members because one or more members could no longer be found." ) ;
189
- foreach ( var member in membersWithoutDeclarations )
192
+ foreach ( var ( memberName , memberType ) in membersWithoutDeclarations )
190
193
{
191
- _logger . Trace ( $ "Could not recover the attributes for member { member } in module { module } because a member of that name exists no longer.") ;
194
+ _logger . Trace ( $ "Could not recover the attributes for member { memberName } of type { memberType } in module { module } because a member of that name and type exists no longer.") ;
192
195
}
193
196
}
194
197
0 commit comments