protected override void AnalyzeAssertInvocation(SyntaxNodeAnalysisContext context,
                                                 InvocationExpressionSyntax assertExpression, IMethodSymbol methodSymbol)
 {
     if (ClassicModelAssertUsageAnalyzer.name.ContainsKey(methodSymbol.Name))
     {
         context.ReportDiagnostic(Diagnostic.Create(
                                      ClassicModelAssertUsageAnalyzer.name[methodSymbol.Name],
                                      assertExpression.GetLocation(),
                                      ClassicModelAssertUsageAnalyzer.GetProperties(methodSymbol)));
     }
 }
Beispiel #2
0
        protected override void AnalyzeAssertInvocation(OperationAnalysisContext context, IInvocationOperation assertOperation)
        {
            var methodSymbol = assertOperation.TargetMethod;

            if (ClassicModelAssertUsageAnalyzer.NameToDescriptor.TryGetValue(methodSymbol.Name, out DiagnosticDescriptor? descriptor))
            {
                context.ReportDiagnostic(Diagnostic.Create(
                                             descriptor,
                                             assertOperation.Syntax.GetLocation(),
                                             ClassicModelAssertUsageAnalyzer.GetProperties(methodSymbol)));
            }
        }
        private static void AnalyzeInvocation(SyntaxNodeAnalysisContext context)
        {
            if (!context.Node.Ancestors().OfType <MethodDeclarationSyntax>().Single().ContainsDiagnostics)
            {
                var invocationNode   = (InvocationExpressionSyntax)context.Node;
                var invocationSymbol = context.SemanticModel.GetSymbolInfo(
                    invocationNode.Expression).Symbol as IMethodSymbol;

                if (invocationSymbol != null && invocationSymbol.ContainingType.IsAssert())
                {
                    context.CancellationToken.ThrowIfCancellationRequested();

                    if (ClassicModelAssertUsageAnalyzer.Names.ContainsKey(invocationSymbol.Name))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(
                                                     ClassicModelAssertUsageAnalyzer.Names[invocationSymbol.Name],
                                                     invocationNode.GetLocation(),
                                                     ClassicModelAssertUsageAnalyzer.GetProperties(invocationSymbol)));
                    }
                }
            }
        }