Skip to content

Commit e1fa460

Browse files
authored
Merge pull request #3635 from bjornhellander/feature/settings-performance1
Preparations for SettingsHelper optimizations
2 parents d02bf2b + ab8a6e8 commit e1fa460

19 files changed

+92
-93
lines changed

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ public override void Initialize(AnalysisContext context)
8686
/// Analyzes the XML elements of a documentation comment.
8787
/// </summary>
8888
/// <param name="context">The current analysis context.</param>
89+
/// <param name="settings">The StyleCop settings to use.</param>
8990
/// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
9091
/// element should be documented; otherwise, <see langword="false"/>.</param>
9192
/// <param name="completeDocumentation">The complete documentation for the declared symbol, with any
9293
/// <c>&lt;include&gt;</c> elements expanded. If the XML documentation comment included a <c>&lt;param&gt;</c>
9394
/// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
9495
/// <c>&lt;include&gt;</c> element.</param>
9596
/// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param>
96-
protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);
97+
protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);
9798

9899
private void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
99100
{
@@ -232,7 +233,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
232233
}
233234

234235
var hasIncludedDocumentation =
235-
documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is object;
236+
documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) != null;
236237

237238
if (hasIncludedDocumentation)
238239
{
@@ -255,7 +256,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
255256
return;
256257
}
257258

258-
this.HandleCompleteDocumentation(context, needsComment, completeDocumentation, locations);
259+
this.HandleCompleteDocumentation(context, settings, needsComment, completeDocumentation, locations);
259260
return;
260261
}
261262
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public override void Initialize(AnalysisContext context)
5151
/// Analyzes the top-level <c>&lt;summary&gt;</c> element of a documentation comment.
5252
/// </summary>
5353
/// <param name="context">The current analysis context.</param>
54+
/// <param name="settings">The StyleCop settings to use.</param>
5455
/// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
5556
/// element should be documented; otherwise, <see langword="false"/>.</param>
5657
/// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
@@ -60,7 +61,7 @@ public override void Initialize(AnalysisContext context)
6061
/// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
6162
/// <c>&lt;include&gt;</c> element.</param>
6263
/// <param name="diagnosticLocation">The location where diagnostics, if any, should be reported.</param>
63-
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);
64+
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);
6465

6566
private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
6667
{
@@ -73,10 +74,10 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleC
7374
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
7475
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
7576
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
76-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
77+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
7778
}
7879

79-
private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComment, SyntaxNode node, Location location)
80+
private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, SyntaxNode node, Location location)
8081
{
8182
var documentation = node.GetDocumentationCommentTriviaSyntax();
8283
if (documentation == null)
@@ -110,7 +111,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComm
110111
}
111112
}
112113

113-
this.HandleXmlElement(context, needsComment, relevantXmlElement, completeDocumentation, location);
114+
this.HandleXmlElement(context, settings, needsComment, relevantXmlElement, completeDocumentation, location);
114115
}
115116
}
116117
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace StyleCop.Analyzers.DocumentationRules
77
{
88
using System;
99
using System.Collections.Immutable;
10-
using System.Globalization;
1110
using System.Xml.Linq;
1211
using Microsoft.CodeAnalysis;
1312
using Microsoft.CodeAnalysis.CSharp;
1413
using Microsoft.CodeAnalysis.CSharp.Syntax;
1514
using Microsoft.CodeAnalysis.Diagnostics;
1615
using StyleCop.Analyzers.Helpers;
16+
using StyleCop.Analyzers.Settings.ObjectModel;
1717

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

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

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
7979
}
8080

8181
/// <inheritdoc/>
82-
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
82+
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
8383
{
8484
// We are working with an <include> element
8585
var includedSummaryElement = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1212
using Microsoft.CodeAnalysis.CSharp.Syntax;
1313
using Microsoft.CodeAnalysis.Diagnostics;
1414
using StyleCop.Analyzers.Helpers;
15+
using StyleCop.Analyzers.Settings.ObjectModel;
1516

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

5051
/// <inheritdoc/>
51-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
52+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
5253
{
5354
if (!needsComment)
5455
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1212
using Microsoft.CodeAnalysis.CSharp.Syntax;
1313
using Microsoft.CodeAnalysis.Diagnostics;
1414
using StyleCop.Analyzers.Helpers;
15+
using StyleCop.Analyzers.Settings.ObjectModel;
1516

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

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

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
7575
}
7676

7777
/// <inheritdoc/>
78-
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
78+
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
7979
{
8080
if (!needsComment)
8181
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
127127
}
128128

129129
/// <inheritdoc/>
130-
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
130+
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
131131
{
132132
var node = context.Node;
133133
var identifier = GetIdentifier(node);

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
7272
}
7373

7474
/// <inheritdoc/>
75-
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
75+
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
7676
{
7777
var xmlParamTags = completeDocumentation.Nodes()
7878
.OfType<XElement>()

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
6666
}
6767

6868
/// <inheritdoc/>
69-
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
69+
protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
7070
{
7171
var xmlParamTags = completeDocumentation.Nodes()
7272
.OfType<XElement>()

0 commit comments

Comments
 (0)