Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for SettingsHelper optimizations #3635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ public override void Initialize(AnalysisContext context)
/// Analyzes the XML elements of a documentation comment.
/// </summary>
/// <param name="context">The current analysis context.</param>
/// <param name="settings">The StyleCop settings to use.</param>
/// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
/// element should be documented; otherwise, <see langword="false"/>.</param>
/// <param name="completeDocumentation">The complete documentation for the declared symbol, with any
/// <c>&lt;include&gt;</c> elements expanded. If the XML documentation comment included a <c>&lt;param&gt;</c>
/// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
/// <c>&lt;include&gt;</c> element.</param>
/// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param>
protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);
protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);

private void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
Expand Down Expand Up @@ -232,7 +233,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
}

var hasIncludedDocumentation =
documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is object;
documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) != null;

if (hasIncludedDocumentation)
{
Expand All @@ -255,7 +256,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
return;
}

this.HandleCompleteDocumentation(context, needsComment, completeDocumentation, locations);
this.HandleCompleteDocumentation(context, settings, needsComment, completeDocumentation, locations);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void Initialize(AnalysisContext context)
/// Analyzes the top-level <c>&lt;summary&gt;</c> element of a documentation comment.
/// </summary>
/// <param name="context">The current analysis context.</param>
/// <param name="settings">The StyleCop settings to use.</param>
/// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
/// element should be documented; otherwise, <see langword="false"/>.</param>
/// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
Expand All @@ -60,7 +61,7 @@ public override void Initialize(AnalysisContext context)
/// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
/// <c>&lt;include&gt;</c> element.</param>
/// <param name="diagnosticLocation">The location where diagnostics, if any, should be reported.</param>
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);

private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
Expand All @@ -73,10 +74,10 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleC
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
}

private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComment, SyntaxNode node, Location location)
private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, SyntaxNode node, Location location)
{
var documentation = node.GetDocumentationCommentTriviaSyntax();
if (documentation == null)
Expand Down Expand Up @@ -110,7 +111,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComm
}
}

this.HandleXmlElement(context, needsComment, relevantXmlElement, completeDocumentation, location);
this.HandleXmlElement(context, settings, needsComment, relevantXmlElement, completeDocumentation, location);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
using System.Globalization;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
/// Analyzes the correct usage of property summary documentation.
Expand Down Expand Up @@ -59,11 +59,10 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
protected override string XmlTagToHandle => XmlCommentHelper.SummaryXmlTag;

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type.StripRefFromType());
var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
// We are working with an <include> element
var includedSummaryElement = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
/// The XML header documentation for a C# property does not contain a <c>&lt;value&gt;</c> tag.
Expand Down Expand Up @@ -48,7 +49,7 @@ internal class SA1609PropertyDocumentationMustHaveValue : PropertyDocumentationB
protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag;

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
if (!needsComment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
/// The XML header documentation for a C# property contains an empty <c>&lt;value&gt;</c> tag.
Expand Down Expand Up @@ -48,7 +49,7 @@ internal class SA1610PropertyDocumentationMustHaveValueText : PropertyDocumentat
protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag;

/// <inheritdoc/>
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
var properties = ImmutableDictionary.Create<string, string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
if (!needsComment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var node = context.Node;
var identifier = GetIdentifier(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var returnsNodes = completeDocumentation.Nodes()
.OfType<XElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace StyleCop.Analyzers.DocumentationRules
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -117,11 +116,10 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var objectPool = SharedPools.Default<HashSet<string>>();
HashSet<string> documentationTexts = objectPool.Allocate();
var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}

/// <inheritdoc/>
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
foreach (var node in completeDocumentation.Nodes().OfType<XElement>())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
/// The XML documentation header for a C# constructor does not contain the appropriate summary text.
Expand Down Expand Up @@ -107,7 +107,7 @@ internal class SA1642ConstructorSummaryDocumentationMustBeginWithStandardText :
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

private static readonly Action<SyntaxNodeAnalysisContext> ConstructorDeclarationAction = HandleConstructorDeclaration;
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> ConstructorDeclarationAction = HandleConstructorDeclaration;

/// <inheritdoc/>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
Expand All @@ -122,11 +122,10 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(ConstructorDeclarationAction, SyntaxKind.ConstructorDeclaration);
}

private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context)
private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var constructorDeclarationSyntax = (ConstructorDeclarationSyntax)context.Node;

var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
using System.Globalization;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
/// The XML documentation header for a C# finalizer does not contain the appropriate summary text.
Expand Down Expand Up @@ -62,7 +62,7 @@ internal class SA1643DestructorSummaryDocumentationMustBeginWithStandardText : S
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

private static readonly Action<SyntaxNodeAnalysisContext> DestructorDeclarationAction = HandleDestructor;
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> DestructorDeclarationAction = HandleDestructor;

/// <inheritdoc/>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
Expand All @@ -77,9 +77,8 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(DestructorDeclarationAction, SyntaxKind.DestructorDeclaration);
}

private static void HandleDestructor(SyntaxNodeAnalysisContext context)
private static void HandleDestructor(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;

Expand Down
Loading