-
Notifications
You must be signed in to change notification settings - Fork 4k
/
CompilationWithAnalyzersOptions.cs
108 lines (97 loc) · 5.74 KB
/
CompilationWithAnalyzersOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// Options to configure analyzer execution within <see cref="CompilationWithAnalyzers"/>.
/// </summary>
public sealed class CompilationWithAnalyzersOptions
{
private readonly AnalyzerOptions _options;
private readonly Action<Exception, DiagnosticAnalyzer, Diagnostic> _onAnalyzerException;
private readonly Func<Exception, bool> _analyzerExceptionFilter;
private readonly bool _concurrentAnalysis;
private readonly bool _logAnalyzerExecutionTime;
private readonly bool _reportSuppressedDiagnostics;
/// <summary>
/// Options passed to <see cref="DiagnosticAnalyzer"/>s.
/// </summary>
public AnalyzerOptions Options => _options;
/// <summary>
/// An optional delegate to be invoked when an analyzer throws an exception.
/// </summary>
public Action<Exception, DiagnosticAnalyzer, Diagnostic> OnAnalyzerException => _onAnalyzerException;
/// <summary>
/// An optional delegate to be invoked when an analyzer throws an exception as an exception filter.
/// </summary>
public Func<Exception, bool> AnalyzerExceptionFilter => _analyzerExceptionFilter;
/// <summary>
/// Flag indicating whether analysis can be performed concurrently on multiple threads.
/// </summary>
public bool ConcurrentAnalysis => _concurrentAnalysis;
/// <summary>
/// Flag indicating whether analyzer execution time should be logged.
/// </summary>
public bool LogAnalyzerExecutionTime => _logAnalyzerExecutionTime;
/// <summary>
/// Flag indicating whether analyzer diagnostics with <see cref="Diagnostic.IsSuppressed"/> should be reported.
/// </summary>
public bool ReportSuppressedDiagnostics => _reportSuppressedDiagnostics;
/// <summary>
/// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
/// </summary>
/// <param name="options">Options that are passed to analyzers.</param>
/// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
/// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
/// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
public CompilationWithAnalyzersOptions(
AnalyzerOptions options,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool concurrentAnalysis,
bool logAnalyzerExecutionTime)
: this(options, onAnalyzerException, concurrentAnalysis, logAnalyzerExecutionTime, reportSuppressedDiagnostics: false)
{
}
/// <summary>
/// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
/// </summary>
/// <param name="options">Options that are passed to analyzers.</param>
/// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
/// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
/// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
/// <param name="reportSuppressedDiagnostics">Flag indicating whether analyzer diagnostics with <see cref="Diagnostic.IsSuppressed"/> should be reported.</param>
public CompilationWithAnalyzersOptions(
AnalyzerOptions options,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool concurrentAnalysis,
bool logAnalyzerExecutionTime,
bool reportSuppressedDiagnostics)
: this(options, onAnalyzerException, concurrentAnalysis, logAnalyzerExecutionTime, reportSuppressedDiagnostics, analyzerExceptionFilter: null)
{
}
/// <summary>
/// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
/// </summary>
/// <param name="options">Options that are passed to analyzers.</param>
/// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
/// <param name="analyzerExceptionFilter">Action to invoke if an analyzer throws an exception as an exception filter.</param>
/// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
/// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
/// <param name="reportSuppressedDiagnostics">Flag indicating whether analyzer diagnostics with <see cref="Diagnostic.IsSuppressed"/> should be reported.</param>
public CompilationWithAnalyzersOptions(
AnalyzerOptions options,
Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
bool concurrentAnalysis,
bool logAnalyzerExecutionTime,
bool reportSuppressedDiagnostics,
Func<Exception, bool> analyzerExceptionFilter)
{
_options = options;
_onAnalyzerException = onAnalyzerException;
_analyzerExceptionFilter = analyzerExceptionFilter;
_concurrentAnalysis = concurrentAnalysis;
_logAnalyzerExecutionTime = logAnalyzerExecutionTime;
_reportSuppressedDiagnostics = reportSuppressedDiagnostics;
}
}
}