Ejemplo n.º 1
0
        private Diagnostic?AnalyzeNamespace(CodeStyleOption2 <NamespaceDeclarationPreference> option, FileScopedNamespaceDeclarationSyntax declaration)
        {
            if (!ConvertNamespaceAnalysis.CanOfferUseBlockScoped(option, declaration, forAnalyzer: true))
            {
                return(null);
            }

            // if the diagnostic is hidden, show it anywhere from the `namespace` keyword through the name.
            // otherwise, if it's not hidden, just squiggle the name.
            var severity           = option.Notification.Severity;
            var diagnosticLocation = severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) != ReportDiagnostic.Hidden
                ? declaration.Name.GetLocation()
                : declaration.SyntaxTree.GetLocation(TextSpan.FromBounds(declaration.SpanStart, declaration.SemicolonToken.Span.End));

            return(DiagnosticHelper.Create(
                       this.Descriptor,
                       diagnosticLocation,
                       severity,
                       ImmutableArray.Create(declaration.GetLocation()),
                       ImmutableDictionary <string, string?> .Empty));
        }
        private Diagnostic?AnalyzeNamespace(OptionSet optionSet, CompilationUnitSyntax root, BaseNamespaceDeclarationSyntax declaration)
        {
            var tree   = declaration.SyntaxTree;
            var option = optionSet.GetOption(CSharpCodeStyleOptions.NamespaceDeclarations);

            if (!ConvertNamespaceAnalysis.CanOfferUseFileScoped(optionSet, root, declaration, forAnalyzer: true))
            {
                return(null);
            }

            // if the diagnostic is hidden, show it anywhere from the `namespace` keyword through the name.
            // otherwise, if it's not hidden, just squiggle the name.
            var severity           = option.Notification.Severity;
            var diagnosticLocation = severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) != ReportDiagnostic.Hidden
                ? declaration.Name.GetLocation()
                : tree.GetLocation(TextSpan.FromBounds(declaration.SpanStart, declaration.Name.Span.End));

            return(DiagnosticHelper.Create(
                       this.Descriptor,
                       diagnosticLocation,
                       severity,
                       ImmutableArray.Create(declaration.GetLocation()),
                       ImmutableDictionary <string, string?> .Empty));
        }