Ejemplo n.º 1
0
 public static bool IsEnabled(
     this AnalyzerOptionDescriptor analyzerOption,
     Document document,
     SyntaxToken token)
 {
     return(IsEnabled(analyzerOption, document, token.SyntaxTree));
 }
Ejemplo n.º 2
0
 public static bool IsEnabled(
     this AnalyzerOptionDescriptor analyzerOption,
     Document document,
     SyntaxNode node)
 {
     return(IsEnabled(analyzerOption, document, node.SyntaxTree));
 }
Ejemplo n.º 3
0
 private static Diagnostic CreateObsoleteDiagnostic(AnalyzerOptionDescriptor analyzerOption, Location location)
 {
     return(Diagnostic.Create(
                descriptor: CommonDiagnosticRules.AnalyzerIsObsolete,
                location: location,
                $"option '{analyzerOption.Descriptor.Id}'",
                $" Use EditorConfig option '{analyzerOption.OptionKey} = true' instead."));
 }
Ejemplo n.º 4
0
 private static void ReportObsolete(
     SymbolAnalysisContext context,
     Location location,
     AnalyzerOptionDescriptor analyzerOption)
 {
     if (analyzerOption.Descriptor?.IsEffective(context.Compilation) == true)
     {
         ReportDiagnostic(context, CreateObsoleteDiagnostic(analyzerOption, location));
     }
 }
Ejemplo n.º 5
0
 public static bool IsEnabled(
     this AnalyzerOptionDescriptor analyzerOption,
     SymbolAnalysisContext context)
 {
     return(IsEnabled(
                analyzerOption,
                context.Symbol.Locations[0].SourceTree,
                context.Compilation.Options,
                context.Options));
 }
Ejemplo n.º 6
0
 public static void ReportObsolete(
     SyntaxNodeAnalysisContext context,
     SyntaxNode node,
     AnalyzerOptionDescriptor analyzerOption)
 {
     if (analyzerOption.Descriptor?.IsEffective(context.Compilation) == true)
     {
         ReportDiagnostic(context, CreateObsoleteDiagnostic(analyzerOption, node.GetLocation()));
     }
 }
Ejemplo n.º 7
0
 public static int GetInt32Value(
     this AnalyzerOptionDescriptor analyzerOption,
     SyntaxTree syntaxTree,
     AnalyzerOptions analyzerOptions,
     int defaultValue)
 {
     return((TryGetInt32Value(analyzerOption, syntaxTree, analyzerOptions, out int result))
         ? result
         : defaultValue);
 }
Ejemplo n.º 8
0
 public static bool IsEnabled(
     this AnalyzerOptionDescriptor analyzerOption,
     SyntaxNodeAnalysisContext context)
 {
     return(IsEnabled(
                analyzerOption,
                context.Node.SyntaxTree,
                context.Compilation.Options,
                context.Options));
 }
Ejemplo n.º 9
0
 public static bool IsEnabled(
     this AnalyzerOptionDescriptor analyzerOption,
     Document document,
     SyntaxTree syntaxTree)
 {
     return(analyzerOption.Parent.IsEffective(syntaxTree, document.Project.CompilationOptions) &&
            analyzerOption.IsEnabled(
                syntaxTree,
                document.Project.CompilationOptions,
                document.Project.AnalyzerOptions));
 }
Ejemplo n.º 10
0
        public static void ReportDiagnostic(
            SymbolAnalysisContext context,
            DiagnosticDescriptor descriptor,
            Location location,
            AnalyzerOptionDescriptor obsoleteAnalyzerOption,
            params object[] messageArgs)
        {
            ReportDiagnostic(context, descriptor, location, messageArgs);

            ReportObsolete(context, location, obsoleteAnalyzerOption);
        }
Ejemplo n.º 11
0
        public static void ReportDiagnostic(
            SyntaxNodeAnalysisContext context,
            DiagnosticDescriptor descriptor,
            Location location,
            ImmutableDictionary <string, string> properties,
            AnalyzerOptionDescriptor obsoleteAnalyzerOption,
            params object[] messageArgs)
        {
            ReportDiagnostic(context, descriptor, location, properties, messageArgs);

            ReportObsolete(context, location, obsoleteAnalyzerOption);
        }
Ejemplo n.º 12
0
 public static void ReportDiagnostic(
     SyntaxNodeAnalysisContext context,
     DiagnosticDescriptor descriptor,
     SyntaxNode node,
     AnalyzerOptionDescriptor obsoleteAnalyzerOption,
     params object[] messageArgs)
 {
     ReportDiagnostic(
         context: context,
         descriptor: descriptor,
         location: node.GetLocation(),
         obsoleteAnalyzerOption,
         messageArgs: messageArgs);
 }
Ejemplo n.º 13
0
        public static bool?IsEnabled(
            this AnalyzerOptionDescriptor analyzerOption,
            SyntaxTree syntaxTree,
            CompilationOptions compilationOptions,
            AnalyzerOptions analyzerOptions,
            bool checkParent)
        {
            if (checkParent && !analyzerOption.Parent.IsEffective(syntaxTree, compilationOptions))
            {
                return(null);
            }

            return(IsEnabled(analyzerOption, syntaxTree, compilationOptions, analyzerOptions));
        }
Ejemplo n.º 14
0
        public static bool TryGetInt32Value(
            this AnalyzerOptionDescriptor analyzerOption,
            SyntaxTree syntaxTree,
            AnalyzerOptions analyzerOptions,
            out int result)
        {
            if (analyzerOptions
                .AnalyzerConfigOptionsProvider
                .GetOptions(syntaxTree)
                .TryGetValue(analyzerOption.OptionKey, out string textValue) &&
                int.TryParse(textValue, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out int value))
            {
                result = value;
                return(true);
            }

            result = default;
            return(false);
        }
Ejemplo n.º 15
0
        public static bool IsEnabled(
            this AnalyzerOptionDescriptor analyzerOption,
            SyntaxTree syntaxTree,
            CompilationOptions compilationOptions,
            AnalyzerOptions analyzerOptions)
        {
            if (analyzerOptions
                .AnalyzerConfigOptionsProvider
                .GetOptions(syntaxTree)
                .TryGetValue(analyzerOption.OptionKey, out string value) &&
                bool.TryParse(value, out bool enabled) &&
                enabled)
            {
                return(true);
            }

            if (analyzerOption.Descriptor != null &&
                compilationOptions
                .SpecificDiagnosticOptions
                .TryGetValue(analyzerOption.Descriptor.Id, out ReportDiagnostic reportDiagnostic))
            {
                switch (reportDiagnostic)
                {
                case ReportDiagnostic.Default:
                case ReportDiagnostic.Suppress:
                    return(false);

                case ReportDiagnostic.Error:
                case ReportDiagnostic.Warn:
                case ReportDiagnostic.Info:
                case ReportDiagnostic.Hidden:
                    return(true);

                default:
                    throw new InvalidOperationException();
                }
            }

            return(false);
        }