From 22d17150095ad5d8a9c409e119512c9c4bd10007 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 9 Nov 2021 11:09:39 -0800 Subject: [PATCH] Support C# 10 'record struct' Fixes #3384 Fixes #3395 --- .../LayoutRules/SA1502CodeFixProvider.cs | 1 + .../SA1400CodeFixProvider.cs | 2 + .../OrderingRules/SA1205CodeFixProvider.cs | 2 + .../NamingRules/SA1313CSharp10UnitTests.cs | 41 ++++ .../DocumentationRules/SA1618UnitTests.cs | 26 ++- .../DocumentationRules/SA1619UnitTests.cs | 26 ++- .../DocumentationRules/SA1625UnitTests.cs | 6 + .../Helpers/CommonMemberData.cs | 7 + .../OrderingRules/SA1205UnitTests.cs | 38 ++++ .../Helpers/NamedTypeHelpers.cs | 1 + .../StyleCop.Analyzers/Helpers/SyntaxKinds.cs | 6 +- .../BaseExpressionColonSyntaxWrapper.g.cs | 96 ++++++++ ...BaseNamespaceDeclarationSyntaxWrapper.g.cs | 147 ++++++++++++ .../ExpressionColonSyntaxWrapper.g.cs | 96 ++++++++ ...opedNamespaceDeclarationSyntaxWrapper.g.cs | 189 ++++++++++++++++ .../LineDirectivePositionSyntaxWrapper.g.cs | 142 ++++++++++++ ...ineOrSpanDirectiveTriviaSyntaxWrapper.g.cs | 96 ++++++++ .../LineSpanDirectiveTriviaSyntaxWrapper.g.cs | 210 ++++++++++++++++++ .../RecordDeclarationSyntaxWrapper.g.cs | 17 ++ .../SubpatternSyntaxWrapper.g.cs | 16 +- .../SyntaxWrapperHelper.g.cs | 7 + .../Lightup/LanguageVersionEx.cs | 1 + .../Lightup/LightupHelpers.cs | 3 + .../StyleCop.Analyzers/Lightup/Syntax.xml | 120 ++++++++-- .../Lightup/SyntaxKindEx.cs | 1 + ...1300ElementMustBeginWithUpperCaseLetter.cs | 3 +- ...ameterNamesMustBeginWithLowerCaseLetter.cs | 3 +- ...1201ElementsMustAppearInTheCorrectOrder.cs | 2 + ...137ElementsShouldHaveTheSameIndentation.cs | 1 + 29 files changed, 1261 insertions(+), 45 deletions(-) create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseExpressionColonSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseNamespaceDeclarationSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionColonSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FileScopedNamespaceDeclarationSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineDirectivePositionSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineOrSpanDirectiveTriviaSyntaxWrapper.g.cs create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineSpanDirectiveTriviaSyntaxWrapper.g.cs diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs index 5d3b3d508..c7d3a9c98 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs @@ -70,6 +70,7 @@ private Document CreateCodeFix(Document document, IndentationSettings indentatio case SyntaxKind.InterfaceDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: case SyntaxKind.EnumDeclaration: newSyntaxRoot = this.RegisterBaseTypeDeclarationCodeFix(syntaxRoot, (BaseTypeDeclarationSyntax)node, indentationSettings); break; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1400CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1400CodeFixProvider.cs index 8ca6a3930..1271d0b0a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1400CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1400CodeFixProvider.cs @@ -84,6 +84,7 @@ private static Task GetTransformedDocumentAsync(Document document, Syn break; case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: updatedDeclarationNode = HandleRecordDeclaration((RecordDeclarationSyntaxWrapper)declarationNode); break; @@ -378,6 +379,7 @@ private static SyntaxNode FindParentDeclarationNode(SyntaxNode node) case SyntaxKind.EnumDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: case SyntaxKind.DelegateDeclaration: case SyntaxKind.EventDeclaration: case SyntaxKind.EventFieldDeclaration: diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/SA1205CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/SA1205CodeFixProvider.cs index 7dd09d5ce..9e1c9992e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/SA1205CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/SA1205CodeFixProvider.cs @@ -113,6 +113,7 @@ private static TypeDeclarationSyntax ReplaceModifiers(TypeDeclarationSyntax node case SyntaxKind.StructDeclaration: return ((StructDeclarationSyntax)node).WithModifiers(modifiers); case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: return ((RecordDeclarationSyntaxWrapper)node).WithModifiers(modifiers); } @@ -132,6 +133,7 @@ private static TypeDeclarationSyntax ReplaceKeyword(TypeDeclarationSyntax node, case SyntaxKind.StructDeclaration: return ((StructDeclarationSyntax)node).WithKeyword(keyword); case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: return ((RecordDeclarationSyntaxWrapper)node).WithKeyword(keyword); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs index c40f29095..a6b229536 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs @@ -3,9 +3,50 @@ namespace StyleCop.Analyzers.Test.CSharp10.NamingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.CSharp; using StyleCop.Analyzers.Test.CSharp9.NamingRules; + using StyleCop.Analyzers.Test.Verifiers; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.NamingRules.SA1313ParameterNamesMustBeginWithLowerCaseLetter, + StyleCop.Analyzers.NamingRules.RenameToLowerCaseCodeFixProvider>; public class SA1313CSharp10UnitTests : SA1313CSharp9UnitTests { + [Theory] + [WorkItem(3384, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3384")] + [InlineData("class")] + [InlineData("struct")] + public async Task TestRecordTypeAsync(string typeKind) + { + var testCode = $@" +public record {typeKind} R(int A) +{{ + public R(int [|A|], int [|B|]) + : this(A) + {{ + }} +}} +"; + + var fixedCode = $@" +public record {typeKind} R(int A) +{{ + public R(int a, int b) + : this(a) + {{ + }} +}} +"; + + await new CSharpTest(LanguageVersion.CSharp10) + { + ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60, + TestCode = testCode, + FixedCode = fixedCode, + }.RunAsync(CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1618UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1618UnitTests.cs index a36b30ac1..cd840ba69 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1618UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1618UnitTests.cs @@ -34,16 +34,22 @@ public static IEnumerable Types { get { - yield return new object[] { "class Foo { }" }; - yield return new object[] { "struct Foo { }" }; - yield return new object[] { "interface Foo { }" }; - yield return new object[] { "class Foo { }" }; - yield return new object[] { "struct Foo { }" }; - yield return new object[] { "interface Foo { }" }; + yield return new object[] { "class Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "struct Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "interface Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "class Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + yield return new object[] { "struct Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + yield return new object[] { "interface Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; if (LightupHelpers.SupportsCSharp9) { - yield return new object[] { "record Foo { }" }; - yield return new object[] { "record Foo { }" }; + yield return new object[] { "record Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "record Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new object[] { "record class Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "record struct Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; } } } @@ -264,8 +270,8 @@ public async Task TestTypesWithMissingDocumentationAsync(string p) var expected = new[] { - Diagnostic().WithLocation(5, 22).WithArguments("Ta"), - Diagnostic().WithLocation(5, 26).WithArguments("Tb"), + Diagnostic().WithLocation(0).WithArguments("Ta"), + Diagnostic().WithLocation(1).WithArguments("Tb"), }; await VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1619UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1619UnitTests.cs index c5e996eb8..5f0542c26 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1619UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1619UnitTests.cs @@ -22,16 +22,22 @@ public static IEnumerable Types { get { - yield return new object[] { "class Foo { }" }; - yield return new object[] { "struct Foo { }" }; - yield return new object[] { "interface Foo { }" }; - yield return new object[] { "class Foo { }" }; - yield return new object[] { "struct Foo { }" }; - yield return new object[] { "interface Foo { }" }; + yield return new object[] { "class Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "struct Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "interface Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "class Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + yield return new object[] { "struct Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + yield return new object[] { "interface Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; if (LightupHelpers.SupportsCSharp9) { - yield return new object[] { "record Foo { }" }; - yield return new object[] { "record Foo { }" }; + yield return new object[] { "record Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "record Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; + } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new object[] { "record class Foo<{|#0:Ta|}, {|#1:Tb|}> { }" }; + yield return new object[] { "record struct Foo<{|#0:Ta|}, {|#1:T\\u0062|}> { }" }; } } } @@ -120,8 +126,8 @@ public async Task TestPartialTypesWithMissingDocumentationAsync(string p) var expected = new[] { - Diagnostic().WithLocation(5, 30).WithArguments("Ta"), - Diagnostic().WithLocation(5, 34).WithArguments("Tb"), + Diagnostic().WithLocation(0).WithArguments("Ta"), + Diagnostic().WithLocation(1).WithArguments("Tb"), }; await VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs index 590ad2893..9b69ccfdb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs @@ -33,6 +33,12 @@ public static IEnumerable Members { yield return new[] { "public record Test { }" }; } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new[] { "public record class Test { }" }; + yield return new[] { "public record struct Test { }" }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/CommonMemberData.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/CommonMemberData.cs index eb74fdfc0..197191bab 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/CommonMemberData.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/CommonMemberData.cs @@ -15,10 +15,17 @@ public static IEnumerable DataTypeDeclarationKeywords { yield return new[] { "class" }; yield return new[] { "struct" }; + if (LightupHelpers.SupportsCSharp9) { yield return new[] { "record" }; } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new[] { "record class" }; + yield return new[] { "record struct" }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1205UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1205UnitTests.cs index 62417a7e8..832382ea9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1205UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1205UnitTests.cs @@ -55,6 +55,19 @@ public static IEnumerable ValidDeclarations yield return new object[] { "internal sealed partial record" }; yield return new object[] { "record" }; } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new object[] { "public partial record class" }; + yield return new object[] { "internal partial record class" }; + yield return new object[] { "public sealed partial record class" }; + yield return new object[] { "internal sealed partial record class" }; + yield return new object[] { "record class" }; + + yield return new object[] { "public partial record struct" }; + yield return new object[] { "internal partial record struct" }; + yield return new object[] { "record struct" }; + } } } @@ -72,6 +85,14 @@ public static IEnumerable InvalidDeclarations yield return new object[] { "partial record" }; yield return new object[] { "sealed partial record" }; } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new object[] { "partial record class" }; + yield return new object[] { "sealed partial record class" }; + + yield return new object[] { "partial record struct" }; + } } } @@ -113,6 +134,23 @@ public static IEnumerable ValidNestedDeclarations yield return new object[] { "private", "record" }; yield return new object[] { "private protected", "record" }; } + + if (LightupHelpers.SupportsCSharp10) + { + yield return new object[] { "public", "record class" }; + yield return new object[] { "protected", "record class" }; + yield return new object[] { "internal", "record class" }; + yield return new object[] { "protected internal", "record class" }; + yield return new object[] { "private", "record class" }; + yield return new object[] { "private protected", "record class" }; + + yield return new object[] { "public", "record struct" }; + yield return new object[] { "protected", "record struct" }; + yield return new object[] { "internal", "record struct" }; + yield return new object[] { "protected internal", "record struct" }; + yield return new object[] { "private", "record struct" }; + yield return new object[] { "private protected", "record struct" }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/NamedTypeHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/NamedTypeHelpers.cs index f0dabde55..ec33a0660 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/NamedTypeHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/NamedTypeHelpers.cs @@ -87,6 +87,7 @@ internal static string GetNameOrIdentifier(MemberDeclarationSyntax member) case SyntaxKind.InterfaceDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: return ((TypeDeclarationSyntax)member).Identifier.Text; case SyntaxKind.EnumDeclaration: diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxKinds.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxKinds.cs index c9bd85aaa..0451f4056 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxKinds.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxKinds.cs @@ -24,7 +24,8 @@ internal static class SyntaxKinds SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.EnumDeclaration, - SyntaxKindEx.RecordDeclaration); + SyntaxKindEx.RecordDeclaration, + SyntaxKindEx.RecordStructDeclaration); /// /// Gets a collection of values which appear in the syntax tree as a @@ -39,7 +40,8 @@ internal static class SyntaxKinds SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration, - SyntaxKindEx.RecordDeclaration); + SyntaxKindEx.RecordDeclaration, + SyntaxKindEx.RecordStructDeclaration); /// /// Gets a collection of values which appear in the syntax tree as a diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseExpressionColonSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseExpressionColonSyntaxWrapper.g.cs new file mode 100644 index 000000000..954c53bca --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseExpressionColonSyntaxWrapper.g.cs @@ -0,0 +1,96 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct BaseExpressionColonSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.BaseExpressionColonSyntax"; + private static readonly Type WrappedType; + + private static readonly Func ExpressionAccessor; + private static readonly Func ColonTokenAccessor; + private static readonly Func WithExpressionAccessor; + private static readonly Func WithColonTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static BaseExpressionColonSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(BaseExpressionColonSyntaxWrapper)); + ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); + ColonTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ColonToken)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); + WithColonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ColonToken)); + } + + private BaseExpressionColonSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public ExpressionSyntax Expression + { + get + { + return ExpressionAccessor(this.SyntaxNode); + } + } + + public SyntaxToken ColonToken + { + get + { + return ColonTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator BaseExpressionColonSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new BaseExpressionColonSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(BaseExpressionColonSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public BaseExpressionColonSyntaxWrapper WithExpression(ExpressionSyntax expression) + { + return new BaseExpressionColonSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + } + + public BaseExpressionColonSyntaxWrapper WithColonToken(SyntaxToken colonToken) + { + return new BaseExpressionColonSyntaxWrapper(WithColonTokenAccessor(this.SyntaxNode, colonToken)); + } + + internal static BaseExpressionColonSyntaxWrapper FromUpcast(CSharpSyntaxNode node) + { + return new BaseExpressionColonSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseNamespaceDeclarationSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseNamespaceDeclarationSyntaxWrapper.g.cs new file mode 100644 index 000000000..79637d5e1 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseNamespaceDeclarationSyntaxWrapper.g.cs @@ -0,0 +1,147 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct BaseNamespaceDeclarationSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.BaseNamespaceDeclarationSyntax"; + private static readonly Type WrappedType; + + private static readonly Func NamespaceKeywordAccessor; + private static readonly Func NameAccessor; + private static readonly Func> ExternsAccessor; + private static readonly Func> UsingsAccessor; + private static readonly Func> MembersAccessor; + private static readonly Func WithNamespaceKeywordAccessor; + private static readonly Func WithNameAccessor; + private static readonly Func, MemberDeclarationSyntax> WithExternsAccessor; + private static readonly Func, MemberDeclarationSyntax> WithUsingsAccessor; + private static readonly Func, MemberDeclarationSyntax> WithMembersAccessor; + + private readonly MemberDeclarationSyntax node; + + static BaseNamespaceDeclarationSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(BaseNamespaceDeclarationSyntaxWrapper)); + NamespaceKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(NamespaceKeyword)); + NameAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Name)); + ExternsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(Externs)); + UsingsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(Usings)); + MembersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(Members)); + WithNamespaceKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NamespaceKeyword)); + WithNameAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Name)); + WithExternsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Externs)); + WithUsingsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Usings)); + WithMembersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Members)); + } + + private BaseNamespaceDeclarationSyntaxWrapper(MemberDeclarationSyntax node) + { + this.node = node; + } + + public MemberDeclarationSyntax SyntaxNode => this.node; + + public SyntaxToken NamespaceKeyword + { + get + { + return NamespaceKeywordAccessor(this.SyntaxNode); + } + } + + public NameSyntax Name + { + get + { + return NameAccessor(this.SyntaxNode); + } + } + + public SyntaxList Externs + { + get + { + return ExternsAccessor(this.SyntaxNode); + } + } + + public SyntaxList Usings + { + get + { + return UsingsAccessor(this.SyntaxNode); + } + } + + public SyntaxList Members + { + get + { + return MembersAccessor(this.SyntaxNode); + } + } + + public static explicit operator BaseNamespaceDeclarationSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new BaseNamespaceDeclarationSyntaxWrapper((MemberDeclarationSyntax)node); + } + + public static implicit operator MemberDeclarationSyntax(BaseNamespaceDeclarationSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public BaseNamespaceDeclarationSyntaxWrapper WithNamespaceKeyword(SyntaxToken namespaceKeyword) + { + return new BaseNamespaceDeclarationSyntaxWrapper(WithNamespaceKeywordAccessor(this.SyntaxNode, namespaceKeyword)); + } + + public BaseNamespaceDeclarationSyntaxWrapper WithName(NameSyntax name) + { + return new BaseNamespaceDeclarationSyntaxWrapper(WithNameAccessor(this.SyntaxNode, name)); + } + + public BaseNamespaceDeclarationSyntaxWrapper WithExterns(SyntaxList externs) + { + return new BaseNamespaceDeclarationSyntaxWrapper(WithExternsAccessor(this.SyntaxNode, externs)); + } + + public BaseNamespaceDeclarationSyntaxWrapper WithUsings(SyntaxList usings) + { + return new BaseNamespaceDeclarationSyntaxWrapper(WithUsingsAccessor(this.SyntaxNode, usings)); + } + + public BaseNamespaceDeclarationSyntaxWrapper WithMembers(SyntaxList members) + { + return new BaseNamespaceDeclarationSyntaxWrapper(WithMembersAccessor(this.SyntaxNode, members)); + } + + internal static BaseNamespaceDeclarationSyntaxWrapper FromUpcast(MemberDeclarationSyntax node) + { + return new BaseNamespaceDeclarationSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionColonSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionColonSyntaxWrapper.g.cs new file mode 100644 index 000000000..3a01e8de2 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionColonSyntaxWrapper.g.cs @@ -0,0 +1,96 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct ExpressionColonSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionColonSyntax"; + private static readonly Type WrappedType; + private static readonly Func WithExpressionAccessor; + private static readonly Func WithColonTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static ExpressionColonSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ExpressionColonSyntaxWrapper)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); + WithColonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ColonToken)); + } + + private ExpressionColonSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public ExpressionSyntax Expression + { + get + { + return ((BaseExpressionColonSyntaxWrapper)this).Expression; + } + } + + public SyntaxToken ColonToken + { + get + { + return ((BaseExpressionColonSyntaxWrapper)this).ColonToken; + } + } + + public static explicit operator ExpressionColonSyntaxWrapper(BaseExpressionColonSyntaxWrapper node) + { + return (ExpressionColonSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator ExpressionColonSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ExpressionColonSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator BaseExpressionColonSyntaxWrapper(ExpressionColonSyntaxWrapper wrapper) + { + return BaseExpressionColonSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(ExpressionColonSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public ExpressionColonSyntaxWrapper WithExpression(ExpressionSyntax expression) + { + return new ExpressionColonSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + } + + public ExpressionColonSyntaxWrapper WithColonToken(SyntaxToken colonToken) + { + return new ExpressionColonSyntaxWrapper(WithColonTokenAccessor(this.SyntaxNode, colonToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FileScopedNamespaceDeclarationSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FileScopedNamespaceDeclarationSyntaxWrapper.g.cs new file mode 100644 index 000000000..4d45bb464 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FileScopedNamespaceDeclarationSyntaxWrapper.g.cs @@ -0,0 +1,189 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct FileScopedNamespaceDeclarationSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FileScopedNamespaceDeclarationSyntax"; + private static readonly Type WrappedType; + + private static readonly Func SemicolonTokenAccessor; + private static readonly Func, MemberDeclarationSyntax> WithAttributeListsAccessor; + private static readonly Func WithModifiersAccessor; + private static readonly Func WithNamespaceKeywordAccessor; + private static readonly Func WithNameAccessor; + private static readonly Func WithSemicolonTokenAccessor; + private static readonly Func, MemberDeclarationSyntax> WithExternsAccessor; + private static readonly Func, MemberDeclarationSyntax> WithUsingsAccessor; + private static readonly Func, MemberDeclarationSyntax> WithMembersAccessor; + + private readonly MemberDeclarationSyntax node; + + static FileScopedNamespaceDeclarationSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FileScopedNamespaceDeclarationSyntaxWrapper)); + SemicolonTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SemicolonToken)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); + WithNamespaceKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NamespaceKeyword)); + WithNameAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Name)); + WithSemicolonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SemicolonToken)); + WithExternsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Externs)); + WithUsingsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Usings)); + WithMembersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Members)); + } + + private FileScopedNamespaceDeclarationSyntaxWrapper(MemberDeclarationSyntax node) + { + this.node = node; + } + + public MemberDeclarationSyntax SyntaxNode => this.node; + + public SyntaxList AttributeLists + { + get + { + return this.SyntaxNode.AttributeLists(); + } + } + + public SyntaxTokenList Modifiers + { + get + { + return this.SyntaxNode.Modifiers(); + } + } + + public SyntaxToken NamespaceKeyword + { + get + { + return ((BaseNamespaceDeclarationSyntaxWrapper)this).NamespaceKeyword; + } + } + + public NameSyntax Name + { + get + { + return ((BaseNamespaceDeclarationSyntaxWrapper)this).Name; + } + } + + public SyntaxToken SemicolonToken + { + get + { + return SemicolonTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxList Externs + { + get + { + return ((BaseNamespaceDeclarationSyntaxWrapper)this).Externs; + } + } + + public SyntaxList Usings + { + get + { + return ((BaseNamespaceDeclarationSyntaxWrapper)this).Usings; + } + } + + public SyntaxList Members + { + get + { + return ((BaseNamespaceDeclarationSyntaxWrapper)this).Members; + } + } + + public static explicit operator FileScopedNamespaceDeclarationSyntaxWrapper(BaseNamespaceDeclarationSyntaxWrapper node) + { + return (FileScopedNamespaceDeclarationSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator FileScopedNamespaceDeclarationSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FileScopedNamespaceDeclarationSyntaxWrapper((MemberDeclarationSyntax)node); + } + + public static implicit operator BaseNamespaceDeclarationSyntaxWrapper(FileScopedNamespaceDeclarationSyntaxWrapper wrapper) + { + return BaseNamespaceDeclarationSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator MemberDeclarationSyntax(FileScopedNamespaceDeclarationSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithNamespaceKeyword(SyntaxToken namespaceKeyword) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithNamespaceKeywordAccessor(this.SyntaxNode, namespaceKeyword)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithName(NameSyntax name) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithNameAccessor(this.SyntaxNode, name)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithSemicolonToken(SyntaxToken semicolonToken) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithSemicolonTokenAccessor(this.SyntaxNode, semicolonToken)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithExterns(SyntaxList externs) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithExternsAccessor(this.SyntaxNode, externs)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithUsings(SyntaxList usings) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithUsingsAccessor(this.SyntaxNode, usings)); + } + + public FileScopedNamespaceDeclarationSyntaxWrapper WithMembers(SyntaxList members) + { + return new FileScopedNamespaceDeclarationSyntaxWrapper(WithMembersAccessor(this.SyntaxNode, members)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineDirectivePositionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineDirectivePositionSyntaxWrapper.g.cs new file mode 100644 index 000000000..c2a7cca4d --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineDirectivePositionSyntaxWrapper.g.cs @@ -0,0 +1,142 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct LineDirectivePositionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.LineDirectivePositionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func LineAccessor; + private static readonly Func CommaTokenAccessor; + private static readonly Func CharacterAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func WithLineAccessor; + private static readonly Func WithCommaTokenAccessor; + private static readonly Func WithCharacterAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static LineDirectivePositionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(LineDirectivePositionSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + LineAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Line)); + CommaTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CommaToken)); + CharacterAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Character)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithLineAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Line)); + WithCommaTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CommaToken)); + WithCharacterAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Character)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private LineDirectivePositionSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken Line + { + get + { + return LineAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CommaToken + { + get + { + return CommaTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken Character + { + get + { + return CharacterAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator LineDirectivePositionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new LineDirectivePositionSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(LineDirectivePositionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public LineDirectivePositionSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new LineDirectivePositionSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public LineDirectivePositionSyntaxWrapper WithLine(SyntaxToken line) + { + return new LineDirectivePositionSyntaxWrapper(WithLineAccessor(this.SyntaxNode, line)); + } + + public LineDirectivePositionSyntaxWrapper WithCommaToken(SyntaxToken commaToken) + { + return new LineDirectivePositionSyntaxWrapper(WithCommaTokenAccessor(this.SyntaxNode, commaToken)); + } + + public LineDirectivePositionSyntaxWrapper WithCharacter(SyntaxToken character) + { + return new LineDirectivePositionSyntaxWrapper(WithCharacterAccessor(this.SyntaxNode, character)); + } + + public LineDirectivePositionSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new LineDirectivePositionSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineOrSpanDirectiveTriviaSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineOrSpanDirectiveTriviaSyntaxWrapper.g.cs new file mode 100644 index 000000000..340bc01ed --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineOrSpanDirectiveTriviaSyntaxWrapper.g.cs @@ -0,0 +1,96 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct LineOrSpanDirectiveTriviaSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.LineOrSpanDirectiveTriviaSyntax"; + private static readonly Type WrappedType; + + private static readonly Func LineKeywordAccessor; + private static readonly Func FileAccessor; + private static readonly Func WithLineKeywordAccessor; + private static readonly Func WithFileAccessor; + + private readonly DirectiveTriviaSyntax node; + + static LineOrSpanDirectiveTriviaSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(LineOrSpanDirectiveTriviaSyntaxWrapper)); + LineKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(LineKeyword)); + FileAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(File)); + WithLineKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(LineKeyword)); + WithFileAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(File)); + } + + private LineOrSpanDirectiveTriviaSyntaxWrapper(DirectiveTriviaSyntax node) + { + this.node = node; + } + + public DirectiveTriviaSyntax SyntaxNode => this.node; + + public SyntaxToken LineKeyword + { + get + { + return LineKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken File + { + get + { + return FileAccessor(this.SyntaxNode); + } + } + + public static explicit operator LineOrSpanDirectiveTriviaSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new LineOrSpanDirectiveTriviaSyntaxWrapper((DirectiveTriviaSyntax)node); + } + + public static implicit operator DirectiveTriviaSyntax(LineOrSpanDirectiveTriviaSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public LineOrSpanDirectiveTriviaSyntaxWrapper WithLineKeyword(SyntaxToken lineKeyword) + { + return new LineOrSpanDirectiveTriviaSyntaxWrapper(WithLineKeywordAccessor(this.SyntaxNode, lineKeyword)); + } + + public LineOrSpanDirectiveTriviaSyntaxWrapper WithFile(SyntaxToken file) + { + return new LineOrSpanDirectiveTriviaSyntaxWrapper(WithFileAccessor(this.SyntaxNode, file)); + } + + internal static LineOrSpanDirectiveTriviaSyntaxWrapper FromUpcast(DirectiveTriviaSyntax node) + { + return new LineOrSpanDirectiveTriviaSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineSpanDirectiveTriviaSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineSpanDirectiveTriviaSyntaxWrapper.g.cs new file mode 100644 index 000000000..39b149b06 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LineSpanDirectiveTriviaSyntaxWrapper.g.cs @@ -0,0 +1,210 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace StyleCop.Analyzers.Lightup +{ + using System; + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal readonly partial struct LineSpanDirectiveTriviaSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.LineSpanDirectiveTriviaSyntax"; + private static readonly Type WrappedType; + + private static readonly Func StartAccessor; + private static readonly Func MinusTokenAccessor; + private static readonly Func EndAccessor; + private static readonly Func CharacterOffsetAccessor; + private static readonly Func WithHashTokenAccessor; + private static readonly Func WithLineKeywordAccessor; + private static readonly Func WithStartAccessor; + private static readonly Func WithMinusTokenAccessor; + private static readonly Func WithEndAccessor; + private static readonly Func WithCharacterOffsetAccessor; + private static readonly Func WithFileAccessor; + private static readonly Func WithEndOfDirectiveTokenAccessor; + private static readonly Func WithIsActiveAccessor; + + private readonly DirectiveTriviaSyntax node; + + static LineSpanDirectiveTriviaSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(LineSpanDirectiveTriviaSyntaxWrapper)); + StartAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Start)); + MinusTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(MinusToken)); + EndAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(End)); + CharacterOffsetAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CharacterOffset)); + WithHashTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(HashToken)); + WithLineKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(LineKeyword)); + WithStartAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Start)); + WithMinusTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(MinusToken)); + WithEndAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(End)); + WithCharacterOffsetAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CharacterOffset)); + WithFileAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(File)); + WithEndOfDirectiveTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(EndOfDirectiveToken)); + WithIsActiveAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(IsActive)); + } + + private LineSpanDirectiveTriviaSyntaxWrapper(DirectiveTriviaSyntax node) + { + this.node = node; + } + + public DirectiveTriviaSyntax SyntaxNode => this.node; + + public SyntaxToken HashToken + { + get + { + return this.SyntaxNode.HashToken; + } + } + + public SyntaxToken LineKeyword + { + get + { + return ((LineOrSpanDirectiveTriviaSyntaxWrapper)this).LineKeyword; + } + } + + public LineDirectivePositionSyntaxWrapper Start + { + get + { + return (LineDirectivePositionSyntaxWrapper)StartAccessor(this.SyntaxNode); + } + } + + public SyntaxToken MinusToken + { + get + { + return MinusTokenAccessor(this.SyntaxNode); + } + } + + public LineDirectivePositionSyntaxWrapper End + { + get + { + return (LineDirectivePositionSyntaxWrapper)EndAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CharacterOffset + { + get + { + return CharacterOffsetAccessor(this.SyntaxNode); + } + } + + public SyntaxToken File + { + get + { + return ((LineOrSpanDirectiveTriviaSyntaxWrapper)this).File; + } + } + + public SyntaxToken EndOfDirectiveToken + { + get + { + return this.SyntaxNode.EndOfDirectiveToken; + } + } + + public bool IsActive + { + get + { + return this.SyntaxNode.IsActive; + } + } + + public static explicit operator LineSpanDirectiveTriviaSyntaxWrapper(LineOrSpanDirectiveTriviaSyntaxWrapper node) + { + return (LineSpanDirectiveTriviaSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator LineSpanDirectiveTriviaSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new LineSpanDirectiveTriviaSyntaxWrapper((DirectiveTriviaSyntax)node); + } + + public static implicit operator LineOrSpanDirectiveTriviaSyntaxWrapper(LineSpanDirectiveTriviaSyntaxWrapper wrapper) + { + return LineOrSpanDirectiveTriviaSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator DirectiveTriviaSyntax(LineSpanDirectiveTriviaSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithHashToken(SyntaxToken hashToken) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithHashTokenAccessor(this.SyntaxNode, hashToken)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithLineKeyword(SyntaxToken lineKeyword) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithLineKeywordAccessor(this.SyntaxNode, lineKeyword)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithStart(LineDirectivePositionSyntaxWrapper start) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithStartAccessor(this.SyntaxNode, start)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithMinusToken(SyntaxToken minusToken) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithMinusTokenAccessor(this.SyntaxNode, minusToken)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithEnd(LineDirectivePositionSyntaxWrapper end) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithEndAccessor(this.SyntaxNode, end)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithCharacterOffset(SyntaxToken characterOffset) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithCharacterOffsetAccessor(this.SyntaxNode, characterOffset)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithFile(SyntaxToken file) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithFileAccessor(this.SyntaxNode, file)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithEndOfDirectiveToken(SyntaxToken endOfDirectiveToken) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithEndOfDirectiveTokenAccessor(this.SyntaxNode, endOfDirectiveToken)); + } + + public LineSpanDirectiveTriviaSyntaxWrapper WithIsActive(bool isActive) + { + return new LineSpanDirectiveTriviaSyntaxWrapper(WithIsActiveAccessor(this.SyntaxNode, isActive)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecordDeclarationSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecordDeclarationSyntaxWrapper.g.cs index bbcfc89a4..16baa432b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecordDeclarationSyntaxWrapper.g.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecordDeclarationSyntaxWrapper.g.cs @@ -14,10 +14,12 @@ namespace StyleCop.Analyzers.Lightup internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RecordDeclarationSyntax"; private static readonly Type WrappedType; + private static readonly Func ClassOrStructKeywordAccessor; private static readonly Func ParameterListAccessor; private static readonly Func, TypeDeclarationSyntax> WithAttributeListsAccessor; private static readonly Func WithModifiersAccessor; private static readonly Func WithKeywordAccessor; + private static readonly Func WithClassOrStructKeywordAccessor; private static readonly Func WithIdentifierAccessor; private static readonly Func WithTypeParameterListAccessor; private static readonly Func WithParameterListAccessor; @@ -33,10 +35,12 @@ namespace StyleCop.Analyzers.Lightup static RecordDeclarationSyntaxWrapper() { WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RecordDeclarationSyntaxWrapper)); + ClassOrStructKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ClassOrStructKeyword)); ParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ParameterList)); WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); WithKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Keyword)); + WithClassOrStructKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ClassOrStructKeyword)); WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); WithTypeParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(TypeParameterList)); WithParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ParameterList)); @@ -79,6 +83,14 @@ public SyntaxToken Keyword } } + public SyntaxToken ClassOrStructKeyword + { + get + { + return ClassOrStructKeywordAccessor(this.SyntaxNode); + } + } + public SyntaxToken Identifier { get @@ -191,6 +203,11 @@ public RecordDeclarationSyntaxWrapper WithKeyword(SyntaxToken keyword) return new RecordDeclarationSyntaxWrapper(WithKeywordAccessor(this.SyntaxNode, keyword)); } + public RecordDeclarationSyntaxWrapper WithClassOrStructKeyword(SyntaxToken classOrStructKeyword) + { + return new RecordDeclarationSyntaxWrapper(WithClassOrStructKeywordAccessor(this.SyntaxNode, classOrStructKeyword)); + } + public RecordDeclarationSyntaxWrapper WithIdentifier(SyntaxToken identifier) { return new RecordDeclarationSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs index d7beccbc3..1c0786cd3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs @@ -14,9 +14,9 @@ namespace StyleCop.Analyzers.Lightup internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SubpatternSyntax"; private static readonly Type WrappedType; - private static readonly Func NameColonAccessor; + private static readonly Func ExpressionColonAccessor; private static readonly Func PatternAccessor; - private static readonly Func WithNameColonAccessor; + private static readonly Func WithExpressionColonAccessor; private static readonly Func WithPatternAccessor; private readonly CSharpSyntaxNode node; @@ -24,9 +24,9 @@ namespace StyleCop.Analyzers.Lightup static SubpatternSyntaxWrapper() { WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)); - NameColonAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(NameColon)); + ExpressionColonAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ExpressionColon)); PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); - WithNameColonAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NameColon)); + WithExpressionColonAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ExpressionColon)); WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); } @@ -37,11 +37,11 @@ private SubpatternSyntaxWrapper(CSharpSyntaxNode node) public CSharpSyntaxNode SyntaxNode => this.node; - public NameColonSyntax NameColon + public BaseExpressionColonSyntaxWrapper ExpressionColon { get { - return NameColonAccessor(this.SyntaxNode); + return (BaseExpressionColonSyntaxWrapper)ExpressionColonAccessor(this.SyntaxNode); } } @@ -78,9 +78,9 @@ public static bool IsInstance(SyntaxNode node) return node != null && LightupHelpers.CanWrapNode(node, WrappedType); } - public SubpatternSyntaxWrapper WithNameColon(NameColonSyntax nameColon) + public SubpatternSyntaxWrapper WithExpressionColon(BaseExpressionColonSyntaxWrapper expressionColon) { - return new SubpatternSyntaxWrapper(WithNameColonAccessor(this.SyntaxNode, nameColon)); + return new SubpatternSyntaxWrapper(WithExpressionColonAccessor(this.SyntaxNode, expressionColon)); } public SubpatternSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs index 0587ee482..6d88cc6b8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs @@ -17,6 +17,8 @@ static SyntaxWrapperHelper() { var csharpCodeAnalysisAssembly = typeof(CSharpSyntaxNode).GetTypeInfo().Assembly; var builder = ImmutableDictionary.CreateBuilder(); + builder.Add(typeof(BaseExpressionColonSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(BaseExpressionColonSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(BaseNamespaceDeclarationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(BaseNamespaceDeclarationSyntaxWrapper.WrappedTypeName)); var objectCreationExpressionSyntaxType = csharpCodeAnalysisAssembly.GetType(BaseObjectCreationExpressionSyntaxWrapper.WrappedTypeName) ?? csharpCodeAnalysisAssembly.GetType(BaseObjectCreationExpressionSyntaxWrapper.FallbackWrappedTypeName); builder.Add(typeof(BaseObjectCreationExpressionSyntaxWrapper), objectCreationExpressionSyntaxType); @@ -31,7 +33,9 @@ static SyntaxWrapperHelper() builder.Add(typeof(DefaultConstraintSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(DefaultConstraintSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(DiscardDesignationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(DiscardDesignationSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(DiscardPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(DiscardPatternSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(ExpressionColonSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ExpressionColonSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ExpressionOrPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ExpressionOrPatternSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FileScopedNamespaceDeclarationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FileScopedNamespaceDeclarationSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ForEachVariableStatementSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ForEachVariableStatementSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(FunctionPointerCallingConventionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerCallingConventionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(FunctionPointerParameterListSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerParameterListSyntaxWrapper.WrappedTypeName)); @@ -42,6 +46,9 @@ static SyntaxWrapperHelper() builder.Add(typeof(ImplicitObjectCreationExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ImplicitObjectCreationExpressionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(IsPatternExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(IsPatternExpressionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(LineDirectivePositionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(LineDirectivePositionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(LineOrSpanDirectiveTriviaSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(LineOrSpanDirectiveTriviaSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(LineSpanDirectiveTriviaSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(LineSpanDirectiveTriviaSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(LocalFunctionStatementSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(LocalFunctionStatementSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(NullableDirectiveTriviaSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(NullableDirectiveTriviaSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ParenthesizedPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ParenthesizedPatternSyntaxWrapper.WrappedTypeName)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LanguageVersionEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LanguageVersionEx.cs index e1c8986d8..49d2c9168 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LanguageVersionEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LanguageVersionEx.cs @@ -16,6 +16,7 @@ internal static class LanguageVersionEx public const LanguageVersion CSharp7_3 = (LanguageVersion)703; public const LanguageVersion CSharp8 = (LanguageVersion)800; public const LanguageVersion CSharp9 = (LanguageVersion)900; + public const LanguageVersion CSharp10 = (LanguageVersion)1000; public const LanguageVersion LatestMajor = (LanguageVersion)int.MaxValue - 2; public const LanguageVersion Preview = (LanguageVersion)int.MaxValue - 1; public const LanguageVersion Latest = (LanguageVersion)int.MaxValue; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs index 2b5b9a42b..4d59502fd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs @@ -41,6 +41,9 @@ private static readonly ConcurrentDictionary SupportsCSharp73; internal static bool CanWrapObject(object obj, Type underlyingType) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml index f24059e17..452c34af0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml @@ -1254,7 +1254,18 @@ Creates an ArgumentSyntax node. - + + + + + + + + + + + + @@ -1262,8 +1273,7 @@ IdentifierNameSyntax representing the identifier name. - - + SyntaxToken representing colon. @@ -1386,6 +1396,7 @@ Provides the base class from which the classes that represent lambda expressions are derived. + @@ -1396,6 +1407,7 @@ + @@ -1444,7 +1456,9 @@ + + ParameterListSyntax node representing the list of parameters for the lambda expression. @@ -2030,7 +2044,7 @@ - + @@ -3000,6 +3014,9 @@ + + + @@ -3027,20 +3044,29 @@ - + + + + + + + + + + - + - + - - - + + + @@ -3051,6 +3077,21 @@ + + + + + + + + + + + + + + + Class representing one or more attributes applied to a language construct. @@ -3352,11 +3393,16 @@ + + + + + @@ -3709,6 +3755,7 @@ Gets the return type. + Gets the "operator" keyword. @@ -3772,6 +3819,7 @@ + Gets the "operator" token. @@ -4711,12 +4759,16 @@ - + + + + + - + @@ -4724,7 +4776,49 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs index d07e72561..11eb92a3c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs @@ -58,5 +58,6 @@ internal static class SyntaxKindEx public const SyntaxKind WithInitializerExpression = (SyntaxKind)9062; public const SyntaxKind RecordDeclaration = (SyntaxKind)9063; public const SyntaxKind FunctionPointerUnmanagedCallingConventionList = (SyntaxKind)9066; + public const SyntaxKind RecordStructDeclaration = (SyntaxKind)9068; } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1300ElementMustBeginWithUpperCaseLetter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1300ElementMustBeginWithUpperCaseLetter.cs index aece90384..e88f0d569 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1300ElementMustBeginWithUpperCaseLetter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1300ElementMustBeginWithUpperCaseLetter.cs @@ -78,6 +78,7 @@ public override void Initialize(AnalysisContext context) context.RegisterSyntaxNodeAction(NamespaceDeclarationAction, SyntaxKind.NamespaceDeclaration); context.RegisterSyntaxNodeAction(ClassDeclarationAction, SyntaxKind.ClassDeclaration); context.RegisterSyntaxNodeAction(RecordDeclarationAction, SyntaxKindEx.RecordDeclaration); + context.RegisterSyntaxNodeAction(RecordDeclarationAction, SyntaxKindEx.RecordStructDeclaration); context.RegisterSyntaxNodeAction(EnumDeclarationAction, SyntaxKind.EnumDeclaration); context.RegisterSyntaxNodeAction(EnumMemberDeclarationAction, SyntaxKind.EnumMemberDeclaration); context.RegisterSyntaxNodeAction(StructDeclarationAction, SyntaxKind.StructDeclaration); @@ -216,7 +217,7 @@ private static void HandleParameter(SyntaxNodeAnalysisContext context) { var parameterDeclaration = (ParameterSyntax)context.Node; if (!parameterDeclaration.Parent.IsKind(SyntaxKind.ParameterList) - || !parameterDeclaration.Parent.Parent.IsKind(SyntaxKindEx.RecordDeclaration)) + || (!parameterDeclaration.Parent.Parent.IsKind(SyntaxKindEx.RecordDeclaration) && !parameterDeclaration.Parent.Parent.IsKind(SyntaxKindEx.RecordStructDeclaration))) { // Only positional parameters of records are treated as properties return; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1313ParameterNamesMustBeginWithLowerCaseLetter.cs b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1313ParameterNamesMustBeginWithLowerCaseLetter.cs index dbb798e7c..f838537f2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1313ParameterNamesMustBeginWithLowerCaseLetter.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1313ParameterNamesMustBeginWithLowerCaseLetter.cs @@ -65,7 +65,8 @@ private static void HandleParameter(SyntaxNodeAnalysisContext context) return; } - if (syntax.Parent.Parent.IsKind(SyntaxKindEx.RecordDeclaration)) + if (syntax.Parent.Parent.IsKind(SyntaxKindEx.RecordDeclaration) + || syntax.Parent.Parent.IsKind(SyntaxKindEx.RecordStructDeclaration)) { // Positional parameters of a record are treated as properties for naming conventions return; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1201ElementsMustAppearInTheCorrectOrder.cs b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1201ElementsMustAppearInTheCorrectOrder.cs index 97f314aca..f37532b96 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1201ElementsMustAppearInTheCorrectOrder.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1201ElementsMustAppearInTheCorrectOrder.cs @@ -155,6 +155,7 @@ internal class SA1201ElementsMustAppearInTheCorrectOrder : DiagnosticAnalyzer [SyntaxKind.StructDeclaration] = "struct", [SyntaxKind.ClassDeclaration] = "class", [SyntaxKindEx.RecordDeclaration] = "record", + [SyntaxKindEx.RecordStructDeclaration] = "record struct", [SyntaxKind.FieldDeclaration] = "field", [SyntaxKind.ConstructorDeclaration] = "constructor", [SyntaxKind.DestructorDeclaration] = "destructor", @@ -309,6 +310,7 @@ private static SyntaxKind GetSyntaxKindForOrdering(SyntaxKind syntaxKind) { SyntaxKind.EventFieldDeclaration => SyntaxKind.EventDeclaration, SyntaxKindEx.RecordDeclaration => SyntaxKind.ClassDeclaration, + SyntaxKindEx.RecordStructDeclaration => SyntaxKind.StructDeclaration, _ => syntaxKind, }; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1137ElementsShouldHaveTheSameIndentation.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1137ElementsShouldHaveTheSameIndentation.cs index e51db24c3..ea4317290 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1137ElementsShouldHaveTheSameIndentation.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1137ElementsShouldHaveTheSameIndentation.cs @@ -309,6 +309,7 @@ private static void AddMemberAndAttributes(ImmutableList.Builder ele case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKindEx.RecordDeclaration: + case SyntaxKindEx.RecordStructDeclaration: elements.AddRange(((BaseTypeDeclarationSyntax)member).AttributeLists); break;