Exemple #1
0
        private void StartAnalyzeCompilation([NotNull] CompilationStartAnalysisContext context)
        {
            Guard.NotNull(context, nameof(context));

            AnalyzerSettings settings = SettingsProvider.LoadSettings(context.Options, context.CancellationToken);

            NullabilityAttributeSymbols nullSymbols = NullabilityAttributeProvider.GetCached()
                                                      .GetSymbols(context.Compilation, context.CancellationToken);

            if (nullSymbols == null)
            {
                // Nullability attributes not found; keep silent.
                return;
            }

            IExternalAnnotationsResolver resolver = ExternalAnnotationsResolver.GetCached();

            resolver.EnsureScanned();

            var generatedCodeCache = new GeneratedCodeDocumentCache();
            var typeCache          = new FrameworkTypeCache(context.Compilation);

            var nullabilityContext = new AnalysisScope(resolver, generatedCodeCache, typeCache, settings,
                                                       disableReportOnNullableValueTypesRule, appliesToItem);

            var factory = new SymbolAnalyzerFactory(nullabilityContext);

            ImmutableDictionary <string, string> properties = nullSymbols.GetMetadataNamesAsProperties();

            context.RegisterSymbolAction(c => AnalyzeField(c, factory, properties), SymbolKind.Field);
            context.RegisterSymbolAction(c => AnalyzeProperty(c, factory, properties), SymbolKind.Property);
            context.RegisterSymbolAction(c => AnalyzeMethod(c, factory, properties), SymbolKind.Method);
            context.RegisterSyntaxNodeAction(c => AnalyzeParameter(SyntaxToSymbolContext(c), factory, properties),
                                             SyntaxKind.Parameter);
        }
Exemple #2
0
        private void AnalyzeMethod(SymbolAnalysisContext context, [NotNull] SymbolAnalyzerFactory factory,
                                   [NotNull] ImmutableDictionary <string, string> properties)
        {
            MethodReturnValueAnalyzer analyzer = factory.GetMethodReturnValueAnalyzer(context);

            analyzer.Analyze(ruleForMethodReturnValue, properties);
        }
Exemple #3
0
        private void AnalyzeProperty(SymbolAnalysisContext context, [NotNull] SymbolAnalyzerFactory factory,
                                     [NotNull] ImmutableDictionary <string, string> properties)
        {
            PropertyAnalyzer analyzer = factory.GetPropertyAnalyzer(context);

            analyzer.Analyze(ruleForProperty, properties);
        }
Exemple #4
0
 private void AnalyzeParameter(SymbolAnalysisContext context, [NotNull] SymbolAnalyzerFactory factory,
                               [NotNull] ImmutableDictionary <string, string> properties)
 {
     // Bug workaround for https://github.com/dotnet/roslyn/issues/16209
     if (context.Symbol != null)
     {
         ParameterAnalyzer analyzer = factory.GetParameterAnalyzer(context);
         analyzer.Analyze(ruleForParameter, properties);
     }
 }