コード例 #1
0
        private IEnumerable <Diagnostic> EnumerateDiagnosticsForDocument([NotNull] Document document,
                                                                         DiagnosticsCaptureMode diagnosticsCaptureMode, [NotNull] CompilationWithAnalyzers compilationWithAnalyzers)
        {
            SyntaxTree tree = document.GetSyntaxTreeAsync().Result;

            return(EnumerateAnalyzerDiagnostics(compilationWithAnalyzers, tree, diagnosticsCaptureMode));
        }
コード例 #2
0
        private static void VerifyDiagnosticCount([NotNull] AnalysisResult result, DiagnosticsCaptureMode captureMode)
        {
            if (captureMode == DiagnosticsCaptureMode.RequireInSourceTree)
            {
                result.Diagnostics.Should().HaveSameCount(result.Spans);
            }

            result.Diagnostics.Should().HaveSameCount(result.Messages);
        }
コード例 #3
0
#pragma warning disable AV1561 // Method or constructor contains more than three parameters
#pragma warning disable AV1500 // Member contains more than seven statements
        private AnalyzerTestContext([NotNull] string markupCode, [NotNull] string languageName, [NotNull] string fileName,
                                    [NotNull] string assemblyName, [NotNull][ItemNotNull] ImmutableHashSet <MetadataReference> references,
                                    DocumentationMode documentationMode, [CanBeNull] int?compilerWarningLevel, TestValidationMode validationMode,
                                    DiagnosticsCaptureMode diagnosticsCaptureMode)
        {
            MarkupCode             = markupCode;
            LanguageName           = languageName;
            FileName               = fileName;
            AssemblyName           = assemblyName;
            References             = references;
            DocumentationMode      = documentationMode;
            CompilerWarningLevel   = compilerWarningLevel;
            ValidationMode         = validationMode;
            DiagnosticsCaptureMode = diagnosticsCaptureMode;
        }
コード例 #4
0
        private static IEnumerable <Diagnostic> EnumerateAnalyzerDiagnostics(
            [NotNull] CompilationWithAnalyzers compilationWithAnalyzers, [NotNull] SyntaxTree tree,
            DiagnosticsCaptureMode diagnosticsCaptureMode)
        {
            foreach (Diagnostic analyzerDiagnostic in compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result)
            {
                Location location = analyzerDiagnostic.Location;

                if (diagnosticsCaptureMode == DiagnosticsCaptureMode.AllowOutsideSourceTree ||
                    LocationIsInSourceTree(location, tree))
                {
                    yield return(analyzerDiagnostic);
                }
            }
        }
コード例 #5
0
        private IEnumerable <Diagnostic> EnumerateDiagnosticsForDocument([NotNull] Document document,
                                                                         TestValidationMode validationMode, DiagnosticsCaptureMode diagnosticsCaptureMode, [NotNull] AnalyzerOptions options)
        {
            CompilationWithAnalyzers compilationWithAnalyzers = GetCompilationWithAnalyzers(document, validationMode, options);

            SyntaxTree tree = document.GetSyntaxTreeAsync().Result;

            return(EnumerateAnalyzerDiagnostics(compilationWithAnalyzers, tree, diagnosticsCaptureMode));
        }