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); }
private ProblemCollection CheckSymbol([CanBeNull] ISymbol symbol) { if (symbol != null) { // When unable to load external annotations, the rule would likely report lots // of false positives. This is prevented by letting it throw here and report nothing. IExternalAnnotationsResolver resolver = ExternalAnnotationsResolver.GetCached(); resolver.EnsureScanned(); var analyzerFactory = new AnalyzerFactory(resolver, appliesToItem); BaseAnalyzer analyzer = analyzerFactory.CreateFor(symbol); analyzer.Analyze(ReportProblem); } return(Problems); }