Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29929 from dotnet/merges/dev16.0.x-to-master
Merge dev16.0.x to master
- Loading branch information
Showing
21 changed files
with
541 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Features/Core/Portable/CodeQuality/AbstractCodeQualityDiagnosticAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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.Collections.Immutable; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeQuality | ||
{ | ||
internal abstract class AbstractCodeQualityDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer | ||
{ | ||
private readonly GeneratedCodeAnalysisFlags _generatedCodeAnalysisFlags; | ||
|
||
protected AbstractCodeQualityDiagnosticAnalyzer( | ||
ImmutableArray<DiagnosticDescriptor> descriptors, | ||
GeneratedCodeAnalysisFlags generatedCodeAnalysisFlags) | ||
{ | ||
SupportedDiagnostics = descriptors; | ||
_generatedCodeAnalysisFlags = generatedCodeAnalysisFlags; | ||
} | ||
|
||
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } | ||
|
||
public sealed override void Initialize(AnalysisContext context) | ||
{ | ||
context.ConfigureGeneratedCodeAnalysis(_generatedCodeAnalysisFlags); | ||
context.EnableConcurrentExecution(); | ||
|
||
InitializeWorker(context); | ||
} | ||
|
||
protected abstract void InitializeWorker(AnalysisContext context); | ||
|
||
public abstract DiagnosticAnalyzerCategory GetAnalyzerCategory(); | ||
public abstract bool OpenFileOnly(Workspace workspace); | ||
|
||
protected static DiagnosticDescriptor CreateDescriptor( | ||
string id, | ||
LocalizableString title, | ||
LocalizableString messageFormat, | ||
bool isUnneccessary, | ||
bool isEnabledByDefault = true, | ||
bool isConfigurable = true, | ||
params string[] customTags) | ||
{ | ||
var customTagsBuilder = ArrayBuilder<string>.GetInstance(); | ||
customTagsBuilder.AddRange(customTags.Concat(WellKnownDiagnosticTags.Telemetry)); | ||
|
||
if (!isConfigurable) | ||
{ | ||
customTagsBuilder.Add(WellKnownDiagnosticTags.NotConfigurable); | ||
} | ||
|
||
if (isUnneccessary) | ||
{ | ||
customTagsBuilder.Add(WellKnownDiagnosticTags.Unnecessary); | ||
} | ||
|
||
return new DiagnosticDescriptor( | ||
id, title, messageFormat, | ||
DiagnosticCategory.CodeQuality, | ||
DiagnosticSeverity.Info, | ||
isEnabledByDefault, | ||
customTags: customTagsBuilder.ToArrayAndFree()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.