Example #1
0
        public void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
        {
            var type       = (TypeDeclarationSyntax)context.Node;
            var typeSymbol = context.SemanticModel.GetDeclaredSymbol(type);

            if (RoslynUtil.IsSymbolGenerated(typeSymbol))
            {
                return;
            }
            var maxFieldCount      = GetMaxFieldCount(typeSymbol.ContainingAssembly);
            var previousFieldCount = GetPreviousFieldCount(typeSymbol);
            var fieldCount         = GetFieldCount(type);

            if (fieldCount > previousFieldCount && fieldCount > maxFieldCount)
            {
                var severity   = DebtAsErrorUtil.GetDiagnosticSeverity(typeSymbol);
                var descriptor = CreateDiagnosticDescriptor(severity);
                var diagnostic = Diagnostic.Create(descriptor, type.Identifier.GetLocation(), typeSymbol.Name, fieldCount, maxFieldCount);

                context.ReportDiagnostic(diagnostic);
            }
        }
        public void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
        {
            var method       = (BaseMethodDeclarationSyntax)context.Node;
            var methodSymbol = (IMethodSymbol)context.SemanticModel.GetDeclaredSymbol(method);

            if (RoslynUtil.IsSymbolGenerated(methodSymbol))
            {
                return;
            }

            var maxParameterCount      = GetMaxParameterCount(methodSymbol.ContainingAssembly);
            var previousParameterCount = GetPreviousParameterCount(methodSymbol);
            var parameterCount         = methodSymbol.Parameters.Length;

            if (parameterCount > previousParameterCount && parameterCount > maxParameterCount)
            {
                var severity   = DebtAsErrorUtil.GetDiagnosticSeverity(methodSymbol);
                var descriptor = CreateDiagnosticDescriptor(severity);
                var identifier = method.GetIdentifier();
                var diagnostic = Diagnostic.Create(descriptor, identifier.GetLocation(), identifier.Text, parameterCount, maxParameterCount);

                context.ReportDiagnostic(diagnostic);
            }
        }