@@ -153,33 +153,36 @@ private static void OnCompilationStart(CompilationStartAnalysisContext context)
153
153
methods = namedType ? . GetMembers ( LongCountAsync ) . OfType < IMethodSymbol > ( ) . Where ( m => m . Parameters . Length <= 2 ) ;
154
154
AddIfNotNull ( asyncMethods , methods ) ;
155
155
156
- // Disallowed types that shouldn't report a diagnosis given that there is no proven benefit on doing so.
157
- ImmutableHashSet < ITypeSymbol > . Builder disallowedTypesBuilder = ImmutableHashSet . CreateBuilder < ITypeSymbol > ( ) ;
156
+ // Allowed types that should report a CA1836 diagnosis given that there is proven benefit on doing so.
157
+ ImmutableHashSet < ITypeSymbol > . Builder allowedTypesBuilder = ImmutableHashSet . CreateBuilder < ITypeSymbol > ( ) ;
158
158
159
- namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemMemory1 ) ;
160
- disallowedTypesBuilder . AddIfNotNull ( namedType ) ;
159
+ namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemCollectionsConcurrentConcurrentBag1 ) ;
160
+ allowedTypesBuilder . AddIfNotNull ( namedType ) ;
161
161
162
- namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemSpan1 ) ;
163
- disallowedTypesBuilder . AddIfNotNull ( namedType ) ;
162
+ namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemCollectionsConcurrentConcurrentDictionary2 ) ;
163
+ allowedTypesBuilder . AddIfNotNull ( namedType ) ;
164
164
165
- namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemReadOnlyMemory1 ) ;
166
- disallowedTypesBuilder . AddIfNotNull ( namedType ) ;
165
+ namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemCollectionsConcurrentConcurrentQueue1 ) ;
166
+ allowedTypesBuilder . AddIfNotNull ( namedType ) ;
167
167
168
- namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemReadOnlySpan1 ) ;
169
- disallowedTypesBuilder . AddIfNotNull ( namedType ) ;
168
+ namedType = context . Compilation . GetOrCreateTypeByMetadataName ( WellKnownTypeNames . SystemCollectionsConcurrentConcurrentStack1 ) ;
169
+ allowedTypesBuilder . AddIfNotNull ( namedType ) ;
170
170
171
- ImmutableHashSet < ITypeSymbol > disallowedTypesForCA1836 = disallowedTypesBuilder . ToImmutable ( ) ;
171
+ ImmutableHashSet < ITypeSymbol > allowedTypesForCA1836 = allowedTypesBuilder . ToImmutable ( ) ;
172
172
173
173
if ( syncMethods . Count > 0 || asyncMethods . Count > 0 )
174
174
{
175
175
context . RegisterOperationAction ( operationContext => AnalyzeInvocationOperation (
176
- operationContext , syncMethods . ToImmutable ( ) , asyncMethods . ToImmutable ( ) , disallowedTypesForCA1836 ) ,
176
+ operationContext , syncMethods . ToImmutable ( ) , asyncMethods . ToImmutable ( ) , allowedTypesForCA1836 ) ,
177
177
OperationKind . Invocation ) ;
178
178
}
179
179
180
- context . RegisterOperationAction ( operationContext => AnalyzePropertyReference (
181
- operationContext , disallowedTypesForCA1836 ) ,
182
- OperationKind . PropertyReference ) ;
180
+ if ( ! allowedTypesForCA1836 . IsEmpty )
181
+ {
182
+ context . RegisterOperationAction ( operationContext => AnalyzePropertyReference (
183
+ operationContext , allowedTypesForCA1836 ) ,
184
+ OperationKind . PropertyReference ) ;
185
+ }
183
186
184
187
static void AddIfNotNull ( ImmutableHashSet < IMethodSymbol > . Builder set , IEnumerable < IMethodSymbol > ? others )
185
188
{
@@ -194,7 +197,7 @@ private static void AnalyzeInvocationOperation(
194
197
OperationAnalysisContext context ,
195
198
ImmutableHashSet < IMethodSymbol > syncMethods ,
196
199
ImmutableHashSet < IMethodSymbol > asyncMethods ,
197
- ImmutableHashSet < ITypeSymbol > disallowedTypesForCA1836 )
200
+ ImmutableHashSet < ITypeSymbol > allowedTypesForCA1836 )
198
201
{
199
202
var invocationOperation = ( IInvocationOperation ) context . Operation ;
200
203
@@ -236,10 +239,10 @@ private static void AnalyzeInvocationOperation(
236
239
bool shouldReplaceParent = ShouldReplaceParent ( ref parentOperation , out string ? operationKey , out bool shouldNegateIsEmpty ) ;
237
240
238
241
DetermineReportForInvocationAnalysis ( context , invocationOperation , parentOperation ,
239
- shouldReplaceParent , isAsync , shouldNegateIsEmpty , hasPredicate , originalDefinition . Name , operationKey , disallowedTypesForCA1836 ) ;
242
+ shouldReplaceParent , isAsync , shouldNegateIsEmpty , hasPredicate , originalDefinition . Name , operationKey , allowedTypesForCA1836 ) ;
240
243
}
241
244
242
- private static void AnalyzePropertyReference ( OperationAnalysisContext context , ImmutableHashSet < ITypeSymbol > disallowedTypesForCA1836 )
245
+ private static void AnalyzePropertyReference ( OperationAnalysisContext context , ImmutableHashSet < ITypeSymbol > allowedTypesForCA1836 )
243
246
{
244
247
var propertyReferenceOperation = ( IPropertyReferenceOperation ) context . Operation ;
245
248
@@ -259,7 +262,7 @@ private static void AnalyzePropertyReference(OperationAnalysisContext context, I
259
262
if ( shouldReplaceParent )
260
263
{
261
264
DetermineReportForPropertyReference ( context , propertyReferenceOperation , parentOperation ,
262
- operationKey , shouldNegateIsEmpty , disallowedTypesForCA1836 ) ;
265
+ operationKey , shouldNegateIsEmpty , allowedTypesForCA1836 ) ;
263
266
}
264
267
}
265
268
@@ -409,7 +412,7 @@ private static void DetermineReportForInvocationAnalysis(
409
412
OperationAnalysisContext context ,
410
413
IInvocationOperation invocationOperation , IOperation parent ,
411
414
bool shouldReplaceParent , bool isAsync , bool shouldNegateIsEmpty , bool hasPredicate , string methodName , string ? operationKey ,
412
- ImmutableHashSet < ITypeSymbol > disallowedTypesForCA1836 )
415
+ ImmutableHashSet < ITypeSymbol > allowedTypesForCA1836 )
413
416
{
414
417
if ( ! shouldReplaceParent )
415
418
{
@@ -438,7 +441,7 @@ private static void DetermineReportForInvocationAnalysis(
438
441
}
439
442
else
440
443
{
441
- if ( ! disallowedTypesForCA1836 . Contains ( type . OriginalDefinition ) &&
444
+ if ( allowedTypesForCA1836 . Contains ( type . OriginalDefinition ) &&
442
445
TypeContainsVisibleProperty ( context , type , IsEmpty , SpecialType . System_Boolean , out ISymbol ? isEmptyPropertySymbol ) &&
443
446
! IsPropertyGetOfIsEmptyUsingThisInstance ( context , invocationOperation , isEmptyPropertySymbol ! ) )
444
447
{
@@ -465,12 +468,12 @@ private static void DetermineReportForInvocationAnalysis(
465
468
private static void DetermineReportForPropertyReference (
466
469
OperationAnalysisContext context , IOperation operation , IOperation parent ,
467
470
string ? operationKey , bool shouldNegateIsEmpty ,
468
- ImmutableHashSet < ITypeSymbol > disallowedTypesForCA1836 )
471
+ ImmutableHashSet < ITypeSymbol > allowedTypesForCA1836 )
469
472
{
470
473
ITypeSymbol ? type = operation . GetInstanceType ( ) ;
471
474
if ( type != null )
472
475
{
473
- if ( ! disallowedTypesForCA1836 . Contains ( type . OriginalDefinition ) &&
476
+ if ( allowedTypesForCA1836 . Contains ( type . OriginalDefinition ) &&
474
477
TypeContainsVisibleProperty ( context , type , IsEmpty , SpecialType . System_Boolean , out ISymbol ? isEmptyPropertySymbol ) &&
475
478
! IsPropertyGetOfIsEmptyUsingThisInstance ( context , operation , isEmptyPropertySymbol ! ) )
476
479
{
0 commit comments