Skip to content

Commit

Permalink
Get the CodeAnnotationsCache providers late to workaround an issue …
Browse files Browse the repository at this point in the history
…with NREs in the `_assertionMethodAnnotationProvider.GetInfo(method)` call in `Run()`
  • Loading branch information
ulrichb committed Oct 10, 2024
1 parent e9fb446 commit 05f9720
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ namespace Roflcopter.Plugin.AssertionMessages
HighlightingTypes = new[] { typeof(InvalidAssertionMessageHighlighting) })]
public class InvalidAssertionMessageProblemAnalyzer : ElementProblemAnalyzer<IInvocationExpression>
{
private readonly ContractAnnotationProvider _contractAnnotationProvider;
private readonly AssertionMethodAnnotationProvider _assertionMethodAnnotationProvider;
private readonly AssertionConditionAnnotationProvider _assertionConditionAnnotationProvider;
private readonly CodeAnnotationsCache _annotationsCache;

public InvalidAssertionMessageProblemAnalyzer(CodeAnnotationsCache annotationsCache)
{
_contractAnnotationProvider = annotationsCache.GetProvider<ContractAnnotationProvider>();
_assertionMethodAnnotationProvider = annotationsCache.GetProvider<AssertionMethodAnnotationProvider>();
_assertionConditionAnnotationProvider = annotationsCache.GetProvider<AssertionConditionAnnotationProvider>();
_annotationsCache = annotationsCache.NotNull();
}

protected override void Run(
Expand All @@ -46,9 +42,10 @@ protected override void Run(
{
// Following 'FDTApplicator..ctor' and 'CSharpControlFlowGraphInspector.PatchContextByObsoleteAnnotatedMethodCall'

var functionDefinitionTable = _contractAnnotationProvider.GetInfo(method);

if (functionDefinitionTable != null || _assertionMethodAnnotationProvider.GetInfo(method))
var functionDefinitionTable = _annotationsCache.GetProvider<ContractAnnotationProvider>().NotNull().GetInfo(method);
var isAssertionMethod = _annotationsCache.GetProvider<AssertionMethodAnnotationProvider>().NotNull().GetInfo(method);

if (functionDefinitionTable != null || isAssertionMethod)
{
if (resolveResult.Result.IsExtensionMethodInvocation())
{
Expand Down Expand Up @@ -139,7 +136,7 @@ protected override void Run(

private ConditionType? GetAssertionConditionAnnotationConditionType(IParameter parameter)
{
var assertionConditionType = _assertionConditionAnnotationProvider.GetInfo(parameter);
var assertionConditionType = _annotationsCache.GetProvider<AssertionConditionAnnotationProvider>().NotNull().GetInfo(parameter);

switch (assertionConditionType)
{
Expand Down

0 comments on commit 05f9720

Please sign in to comment.