private static void AnalyzeInvocationOp(OperationAnalysisContext context) { var invocation = (IInvocationOperation)context.Operation; if (invocation.TargetMethod.Kind != SymbolKind.Method || !invocation.TargetMethod.IsStatic) { return; } if (!IsCodeContractToReplace(context.Compilation, invocation)) { return; } DiagnosticDescriptor rule = Rule; if (ContractStatementAnalyzer.IsContractClass(context.ContainingSymbol)) { rule = RuleWithinCC; } var invocationSyntax = (InvocationExpressionSyntax)invocation.Syntax; if (invocationSyntax.Expression is MemberAccessExpressionSyntax memberAccess) { context.ReportDiagnostic(Diagnostic.Create(rule, memberAccess.Expression.GetLocation())); } }
private static void AnalyzeClassDeclaration(SymbolAnalysisContext context) { var namedType = context.Symbol as INamedTypeSymbol; if (namedType == null || namedType.TypeKind != TypeKind.Class) { return; } if (!ContractStatementAnalyzer.IsContractClass(namedType)) { return; } foreach (var syntax in namedType.DeclaringSyntaxReferences) { var syntaxNode = syntax.GetSyntax(context.CancellationToken); if (syntaxNode is ClassDeclarationSyntax classDecl) { context.ReportDiagnostic(Diagnostic.Create(Rule, classDecl.Identifier.GetLocation())); } } }
private static void AnalyzeInvocationOp(OperationAnalysisContext context) { var invocation = (IInvocationOperation)context.Operation; if (invocation.TargetMethod.Kind != SymbolKind.Method || !invocation.TargetMethod.IsStatic) { return; } if (invocation.Parent.Kind != OperationKind.ExpressionStatement) { return; } if (!IsCodeContractToReplace(invocation)) { return; } if (ContractStatementAnalyzer.IsContractClass(context.ContainingSymbol)) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.Parent.Syntax.GetLocation())); }
private static void AnalyzeInvocationOp(OperationAnalysisContext context) { var statement = (IExpressionStatementOperation)context.Operation; var invocation = statement.Operation as IInvocationOperation; if (invocation == null) { return; } if (!IsCodeContractToRemove(context.Compilation, invocation)) { return; } if (ContractStatementAnalyzer.IsInvariantMethod(context.ContainingSymbol) || ContractStatementAnalyzer.IsContractClass(context.ContainingSymbol)) { return; } var invocationSyntax = (InvocationExpressionSyntax)invocation.Syntax; if (invocationSyntax.Expression is MemberAccessExpressionSyntax memberAccess) { context.ReportDiagnostic(Diagnostic.Create(Rule, statement.Syntax.GetLocation())); } }