Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jun 27, 2021
1 parent 4e56074 commit a35b306
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,29 @@ public override void Initialize(AnalysisContext context)
// any diagnostics from it.
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze);

context.RegisterCompilationStartAction(cc =>
context.RegisterCompilationStartAction(context =>
{
INamedTypeSymbol? generatedCode = cc.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCodeDomCompilerGeneratedCodeAttribute);
if (generatedCode is null)
if (!context.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCodeDomCompilerGeneratedCodeAttribute, out var generatedCode))
{
return;
}

INamedTypeSymbol? attribute = cc.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemResourcesNeutralResourcesLanguageAttribute);
INamedTypeSymbol? attribute = context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemResourcesNeutralResourcesLanguageAttribute);
if (attribute is null)
{
return;
}

if (TryCheckNeutralResourcesLanguageAttribute(cc.Compilation, attribute, out var data))
if (TryCheckNeutralResourcesLanguageAttribute(context.Compilation, attribute, out var data))
{
// attribute already exist
return;
}

var hasResource = false;
RegisterAttributeAnalyzer(cc, () => hasResource = true, generatedCode);
RegisterAttributeAnalyzer(context, () => hasResource = true, generatedCode);

cc.RegisterCompilationEndAction(ce =>
context.RegisterCompilationEndAction(context =>
{
// there is nothing to do.
if (!hasResource)
Expand All @@ -85,12 +84,12 @@ public override void Initialize(AnalysisContext context)
if (data != null)
{
// we have the attribute but its doing it wrong.
ce.ReportDiagnostic(data.ApplicationSyntaxReference.GetSyntax(ce.CancellationToken).CreateDiagnostic(Rule));
context.ReportDiagnostic(data.ApplicationSyntaxReference.GetSyntax(context.CancellationToken).CreateDiagnostic(Rule));
return;
}

// attribute just don't exist
ce.ReportNoLocationDiagnostic(Rule);
context.ReportNoLocationDiagnostic(Rule);
});
});
}
Expand Down

0 comments on commit a35b306

Please sign in to comment.