提交 82de928e 编写于 作者: C CyrusNajmabadi

Add comments and simplify code.

上级 fea33a0d
......@@ -26,7 +26,6 @@ internal class CSharpInlineDeclarationDiagnosticAnalyzer : AbstractCodeStyleDiag
{
public CSharpInlineDeclarationDiagnosticAnalyzer()
: base(IDEDiagnosticIds.InlineDeclarationDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.Inline_variable_declaration), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Inline_variable_declaration), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
}
......@@ -197,7 +196,7 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context)
: localDeclarator;
context.ReportDiagnostic(Diagnostic.Create(
CreateDescriptor(this.Id, option.Notification.Value),
CreateDescriptor(this.DescriptorId, option.Notification.Value),
reportNode.GetLocation(),
additionalLocations: allLocations));
}
......
......@@ -7,23 +7,43 @@ namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
{
protected readonly string Id;
protected readonly string DescriptorId;
/// <summary>
/// Diagnostic descriptor for code you want to fade out *and* want to have a smart-tag
/// appear for. This is the common descriptor for code that is being faded out
/// </summary>
protected readonly DiagnosticDescriptor UnnecessaryWithSuggestionDescriptor;
/// <summary>
/// Diagnostic descriptor for code you want to fade out and do *not* want to have a smart-tag
/// appear for. This is uncommon but useful in some cases. For example, if you are fading
/// out pieces of code before/after another piece of code *on the same line*, then you will
/// only want one usafe of <see cref="UnnecessaryWithSuggestionDescriptor"/> and multiple
/// usages of <see cref="UnnecessaryWithoutSuggestionDescriptor"/>.
///
/// That's because if you use <see cref="UnnecessaryWithSuggestionDescriptor"/> for all the
/// faded out code then that will mean the user will see multiple code actions to fix the
/// same issue when they bring up the code action on that line. Using these two descriptors
/// helps ensure that there will not be useless code-action overload.
/// </summary>
protected readonly DiagnosticDescriptor UnnecessaryWithoutSuggestionDescriptor;
private readonly LocalizableString _localizableTitle;
private readonly LocalizableString _localizableMessage;
private readonly DiagnosticDescriptor _descriptor;
protected AbstractCodeStyleDiagnosticAnalyzer(string id, LocalizableString title, LocalizableString message)
protected AbstractCodeStyleDiagnosticAnalyzer(
string descriptorId, LocalizableString title, LocalizableString message = null)
{
Id = id;
DescriptorId = descriptorId;
_localizableTitle = title;
_localizableMessage = message;
_descriptor = CreateDescriptor(id, DiagnosticSeverity.Hidden);
_localizableMessage = message ?? title;
_descriptor = CreateDescriptor(descriptorId, DiagnosticSeverity.Hidden);
UnnecessaryWithSuggestionDescriptor = CreateDescriptor(
id, DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary);
UnnecessaryWithoutSuggestionDescriptor = CreateDescriptor(id + "WithoutSuggestion",
descriptorId, DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary);
UnnecessaryWithoutSuggestionDescriptor = CreateDescriptor(descriptorId + "WithoutSuggestion",
DiagnosticSeverity.Hidden, DiagnosticCustomTags.Unnecessary);
SupportedDiagnostics = ImmutableArray.Create(
_descriptor, UnnecessaryWithoutSuggestionDescriptor, UnnecessaryWithSuggestionDescriptor);
......
......@@ -33,8 +33,7 @@ internal abstract class AbstractUseObjectInitializerDiagnosticAnalyzer<
protected AbstractUseObjectInitializerDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseObjectInitializerDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.Object_initialization_can_be_simplified), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Object_initialization_can_be_simplified), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
new LocalizableResourceString(nameof(FeaturesResources.Object_initialization_can_be_simplified), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
}
......@@ -72,7 +71,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
var severity = option.Notification.Value;
context.ReportDiagnostic(Diagnostic.Create(
CreateDescriptor(Id, severity),
CreateDescriptor(DescriptorId, severity),
objectCreationExpression.GetLocation(),
additionalLocations: locations));
......
......@@ -35,7 +35,6 @@ internal abstract class AbstractUseThrowExpressionDiagnosticAnalyzer : AbstractC
{
protected AbstractUseThrowExpressionDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseThrowExpressionDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.Use_throw_expression), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Use_throw_expression), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
}
......@@ -133,7 +132,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
throwOperation.ThrownObject.Syntax.GetLocation(),
assignmentExpression.Value.Syntax.GetLocation());
var descriptor = CreateDescriptor(Id, option.Notification.Value);
var descriptor = CreateDescriptor(DescriptorId, option.Notification.Value);
context.ReportDiagnostic(
Diagnostic.Create(descriptor, throwStatement.GetLocation(), additionalLocations: allLocations));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册