diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs index dc01b335c2..b53676c8a8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs @@ -104,7 +104,7 @@ private static SyntaxNode GetReplacementNode(SemanticModel semanticModel, Syntax private static SyntaxNode TransformGenericNameToTuple(SemanticModel semanticModel, GenericNameSyntax genericName) { - var implementationType = typeof(SeparatedSyntaxListWrapper<>.AutoWrapSeparatedSyntaxList<>).MakeGenericType(typeof(TupleElementSyntaxWrapper), WrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper))); + var implementationType = typeof(SeparatedSyntaxListWrapper<>.AutoWrapSeparatedSyntaxList<>).MakeGenericType(typeof(TupleElementSyntaxWrapper), SyntaxWrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper))); var tupleElements = (SeparatedSyntaxListWrapper)Activator.CreateInstance(implementationType); foreach (var typeArgument in genericName.TypeArgumentList.Arguments) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/GeneratorSyntaxExtensions.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/GeneratorSyntaxExtensions.cs new file mode 100644 index 0000000000..ad25f4aa38 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/GeneratorSyntaxExtensions.cs @@ -0,0 +1,19 @@ +// 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.CodeGeneration +{ + using System; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + + internal static class GeneratorSyntaxExtensions + { + public static TSyntax WithLeadingBlankLine(this TSyntax syntax) + where TSyntax : SyntaxNode + { + return syntax.WithLeadingTrivia(SyntaxFactory.TriviaList( + SyntaxFactory.PreprocessingMessage(Environment.NewLine))); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs index 98c9176bfc..2c287c21fb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/OperationLightupGenerator.cs @@ -179,7 +179,8 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In identifier: SyntaxFactory.Identifier(node.WrapperName), parameterList: SyntaxFactory.ParameterList(), initializer: null, - body: SyntaxFactory.Block(staticCtorStatements))); + body: SyntaxFactory.Block(staticCtorStatements), + expressionBody: null)); // private IArgumentOperationWrapper(IOperation operation) // { @@ -203,7 +204,8 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In SyntaxKind.SimpleMemberAccessExpression, expression: SyntaxFactory.ThisExpression(), name: SyntaxFactory.IdentifierName("operation")), - right: SyntaxFactory.IdentifierName("operation")))))); + right: SyntaxFactory.IdentifierName("operation")))), + expressionBody: null)); // public IOperation WrappedOperation => this.operation; members = members.Add(SyntaxFactory.PropertyDeclaration( @@ -679,8 +681,14 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context identifier: SyntaxFactory.Identifier("OperationWrapperHelper"), parameterList: SyntaxFactory.ParameterList(), initializer: null, - body: SyntaxFactory.Block(staticCtorStatements)); + body: SyntaxFactory.Block(staticCtorStatements), + expressionBody: null); + // /// + // /// Gets the type that is wrapped by the given wrapper. + // /// + // /// Type of the wrapper for which the wrapped type should be retrieved. + // /// The wrapped type, or null if there is no info. // internal static Type GetWrappedType(Type wrapperType) // { // if (WrappedTypes.TryGetValue(wrapperType, out Type wrappedType)) @@ -727,6 +735,25 @@ private void GenerateOperationWrapperHelper(in GeneratorExecutionContext context SyntaxFactory.ReturnStatement(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))), expressionBody: null); + getWrappedType = getWrappedType.WithLeadingTrivia(SyntaxFactory.TriviaList( + SyntaxFactory.Trivia(SyntaxFactory.DocumentationComment( + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlSummaryElement( + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" Gets the type that is wrapped by the given wrapper."), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" ")), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlParamElement( + "wrapperType", + SyntaxFactory.XmlText("Type of the wrapper for which the wrapped type should be retrieved.")), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlReturnsElement( + SyntaxFactory.XmlText("The wrapped type, or null if there is no info.")), + SyntaxFactory.XmlNewLine(Environment.NewLine).WithoutTrailingTrivia())))); + var wrapperHelperClass = SyntaxFactory.ClassDeclaration( attributeLists: default, modifiers: SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.InternalKeyword)).Add(SyntaxFactory.Token(SyntaxKind.StaticKeyword)), @@ -831,7 +858,7 @@ public DocumentData(XDocument document) if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds)) { - kinds = ImmutableArray<(string name, int value, string extraDescription)>.Empty; + kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty; } var interfaceData = new InterfaceData(this, node, kinds); @@ -847,7 +874,7 @@ public DocumentData(XDocument document) if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds)) { - kinds = ImmutableArray<(string name, int value, string extraDescription)>.Empty; + kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty; } var interfaceData = new InterfaceData(this, node, kinds); @@ -859,11 +886,11 @@ public DocumentData(XDocument document) public ReadOnlyDictionary Interfaces { get; } - private static ImmutableDictionary> GetOperationKinds(XDocument document) + private static ImmutableDictionary> GetOperationKinds(XDocument document) { var skippedOperationKinds = GetSkippedOperationKinds(document); - var builder = ImmutableDictionary.CreateBuilder>(); + var builder = ImmutableDictionary.CreateBuilder>(); int operationKind = 0; foreach (var node in document.XPathSelectElements("/Tree/AbstractNode|/Tree/Node")) @@ -886,7 +913,7 @@ public DocumentData(XDocument document) } else if (explicitKind.XPathSelectElements("Entry").Any()) { - var nodeBuilder = ImmutableArray.CreateBuilder<(string name, int value, string extraDescription)>(); + var nodeBuilder = ImmutableArray.CreateBuilder<(string name, int value, string? extraDescription)>(); foreach (var entry in explicitKind.XPathSelectElements("Entry")) { if (entry.Attribute("EditorBrowsable")?.Value == "false") @@ -918,7 +945,7 @@ public DocumentData(XDocument document) var nodeName = node.Attribute("Name").Value; var kindName = nodeName.Substring("I".Length, nodeName.Length - "I".Length - "Operation".Length); - builder.Add(nodeName, ImmutableArray.Create((kindName, operationKind, (string)null))); + builder.Add(nodeName, ImmutableArray.Create((kindName, operationKind, (string?)null))); } return builder.ToImmutable(); @@ -955,7 +982,7 @@ private sealed class InterfaceData { private readonly DocumentData documentData; - public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(string name, int value, string extraDescription)> operationKinds) + public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(string name, int value, string? extraDescription)> operationKinds) { this.documentData = documentData; @@ -968,7 +995,7 @@ public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(s this.Properties = node.XPathSelectElements("Property").Select(property => new PropertyData(property)).ToImmutableArray(); } - public ImmutableArray<(string name, int value, string extraDescription)> OperationKinds { get; } + public ImmutableArray<(string name, int value, string? extraDescription)> OperationKinds { get; } public string InterfaceName { get; } @@ -982,7 +1009,7 @@ public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(s public ImmutableArray Properties { get; } - public InterfaceData BaseInterface + public InterfaceData? BaseInterface { get { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj index 53cf970df5..a4892d2cf3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.csproj @@ -3,6 +3,7 @@ netstandard2.0 + enable @@ -16,6 +17,8 @@ + + \ No newline at end of file diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs new file mode 100644 index 0000000000..7308e921f7 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeGeneration/SyntaxLightupGenerator.cs @@ -0,0 +1,1284 @@ +// 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.CodeGeneration +{ + using System; + using System.Collections.Generic; + using System.Collections.Immutable; + using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; + using System.IO; + using System.Linq; + using System.Text; + using System.Xml.Linq; + using System.Xml.XPath; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using Microsoft.CodeAnalysis.Text; + + [Generator] + internal sealed class SyntaxLightupGenerator : ISourceGenerator + { + private enum NodeKind + { + Predefined, + Abstract, + Concrete, + } + + public void Initialize(GeneratorInitializationContext context) + { + } + + public void Execute(GeneratorExecutionContext context) + { + var syntaxFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "Syntax.xml"); + var syntaxText = syntaxFile.GetText(context.CancellationToken); + if (syntaxText is null) + { + throw new InvalidOperationException("Failed to read Syntax.xml"); + } + + var syntaxData = new SyntaxData(in context, XDocument.Parse(syntaxText.ToString())); + this.GenerateSyntaxWrappers(in context, syntaxData); + this.GenerateSyntaxWrapperHelper(in context, syntaxData.Nodes); + } + + private void GenerateSyntaxWrappers(in GeneratorExecutionContext context, SyntaxData syntaxData) + { + foreach (var node in syntaxData.Nodes) + { + this.GenerateSyntaxWrapper(in context, syntaxData, node); + } + } + + private void GenerateSyntaxWrapper(in GeneratorExecutionContext context, SyntaxData syntaxData, NodeData nodeData) + { + if (nodeData.WrapperName is null) + { + // No need to generate a wrapper for this type + return; + } + + var concreteBase = syntaxData.TryGetConcreteBase(nodeData)?.Name ?? nameof(SyntaxNode); + + var members = SyntaxFactory.List(); + + // internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax"; + members = members.Add(SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.ConstKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.StringKeyword)), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator( + identifier: SyntaxFactory.Identifier("WrappedTypeName"), + argumentList: null, + initializer: SyntaxFactory.EqualsValueClause(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal("Microsoft.CodeAnalysis.CSharp.Syntax." + nodeData.Name)))))))); + + // private static readonly Type WrappedType; + members = members.Add(SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.IdentifierName("Type"), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator("WrappedType"))))); + + bool first = true; + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + if (field.IsOverride) + { + // The 'get' accessor is skipped for override fields + continue; + } + + // private static readonly Func FieldAccessor; + FieldDeclarationSyntax fieldAccessor = SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("Func"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)), + }))), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(field.AccessorName)))); + + if (first) + { + fieldAccessor = fieldAccessor.WithLeadingBlankLine(); + first = false; + } + + members = members.Add(fieldAccessor); + } + + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + // private static readonly Func WithFieldAccessor; + members = members.Add(SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("Func"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)), + SyntaxFactory.IdentifierName(concreteBase), + }))), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(field.WithAccessorName))))); + } + + // private readonly SyntaxNode node; + members = members.Add(SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.IdentifierName(concreteBase), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator("node")))).WithLeadingBlankLine()); + + // WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SyntaxWrapper)); + var staticCtorStatements = SyntaxFactory.SingletonList( + SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + left: SyntaxFactory.IdentifierName("WrappedType"), + right: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("SyntaxWrapperHelper"), + name: SyntaxFactory.IdentifierName("GetWrappedType")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.TypeOfExpression(SyntaxFactory.IdentifierName(nodeData.WrapperName))))))))); + + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + if (field.IsOverride) + { + // The 'get' accessor is skipped for override fields + continue; + } + + SimpleNameSyntax helperName; + if (field.IsWrappedSeparatedSyntaxList(syntaxData, out var elementNode)) + { + Debug.Assert(elementNode.WrapperName is not null, $"Assertion failed: {nameof(elementNode)}.{nameof(elementNode.WrapperName)} is not null"); + + // CreateSeparatedSyntaxListPropertyAccessor + helperName = SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("CreateSeparatedSyntaxListPropertyAccessor"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.IdentifierName(elementNode.WrapperName), + }))); + } + else + { + // CreateSyntaxPropertyAccessor + helperName = SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("CreateSyntaxPropertyAccessor"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)), + }))); + } + + // ReturnTypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ReturnType)); + staticCtorStatements = staticCtorStatements.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + left: SyntaxFactory.IdentifierName(field.AccessorName), + right: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("LightupHelpers"), + name: helperName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("WrappedType")), + SyntaxFactory.Argument(SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName("nameof"), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(field.Name)))))), + })))))); + } + + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + SimpleNameSyntax helperName; + if (field.IsWrappedSeparatedSyntaxList(syntaxData, out var elementNode)) + { + Debug.Assert(elementNode.WrapperName is not null, $"Assertion failed: {nameof(elementNode)}.{nameof(elementNode.WrapperName)} is not null"); + + // CreateSeparatedSyntaxListWithPropertyAccessor + helperName = SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("CreateSeparatedSyntaxListWithPropertyAccessor"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.IdentifierName(elementNode.WrapperName), + }))); + } + else + { + // CreateSyntaxWithPropertyAccessor + helperName = SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("CreateSyntaxWithPropertyAccessor"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName(concreteBase), + SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)), + }))); + } + + // WithReturnTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ReturnType)); + staticCtorStatements = staticCtorStatements.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + left: SyntaxFactory.IdentifierName(field.WithAccessorName), + right: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("LightupHelpers"), + name: helperName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("WrappedType")), + SyntaxFactory.Argument(SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName("nameof"), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(field.Name)))))), + })))))); + } + + // static SyntaxWrapper() + // { + // WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SyntaxWrapper)); + // } + members = members.Add(SyntaxFactory.ConstructorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + identifier: SyntaxFactory.Identifier(nodeData.WrapperName), + parameterList: SyntaxFactory.ParameterList(), + initializer: null, + body: SyntaxFactory.Block(staticCtorStatements), + expressionBody: null).WithLeadingBlankLine()); + + // private SyntaxNodeWrapper(SyntaxNode node) + // { + // this.node = node; + // } + members = members.Add(SyntaxFactory.ConstructorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)), + identifier: SyntaxFactory.Identifier(nodeData.WrapperName), + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName(concreteBase), + identifier: SyntaxFactory.Identifier("node"), + @default: null))), + initializer: null, + body: SyntaxFactory.Block( + SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + left: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("node")), + right: SyntaxFactory.IdentifierName("node")))), + expressionBody: null)); + + // public SyntaxNode SyntaxNode => this.node; + members = members.Add(SyntaxFactory.PropertyDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)), + type: SyntaxFactory.IdentifierName(concreteBase), + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier("SyntaxNode"), + accessorList: null, + expressionBody: SyntaxFactory.ArrowExpressionClause(SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("node"))), + initializer: null, + semicolonToken: SyntaxFactory.Token(SyntaxKind.SemicolonToken))); + + // public T Field + // { + // get + // { + // return ...; + // } + // } + first = true; + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + TypeSyntax propertyType = SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)); + ExpressionSyntax returnExpression; + if (field.IsOverride) + { + var declaringNode = field.GetDeclaringNode(syntaxData); + if (declaringNode.WrapperName is not null) + { + // ((CommonForEachStatementSyntaxWrapper)this).OpenParenToken + returnExpression = SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ParenthesizedExpression( + SyntaxFactory.CastExpression( + type: SyntaxFactory.IdentifierName(declaringNode.WrapperName ?? declaringNode.Name), + expression: SyntaxFactory.ThisExpression())), + name: SyntaxFactory.IdentifierName(field.Name)); + } + else + { + // this.SyntaxNode.OpenParenToken + returnExpression = SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("SyntaxNode")), + name: SyntaxFactory.IdentifierName(field.Name)); + + if (declaringNode.TryGetField(field.Name) is { IsExtensionField: true }) + { + // this.SyntaxNode.OpenParenToken() + returnExpression = SyntaxFactory.InvocationExpression( + expression: returnExpression, + argumentList: SyntaxFactory.ArgumentList()); + } + } + } + else if (field.IsWrappedSeparatedSyntaxList(syntaxData, out var elementNode)) + { + // PatternAccessor(this.SyntaxNode) + returnExpression = SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName(field.AccessorName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("SyntaxNode")))))); + } + else if (syntaxData.TryGetNode(field.Type) is { } fieldNodeType) + { + // PatternAccessor(this.SyntaxNode) + returnExpression = SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName(field.AccessorName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("SyntaxNode")))))); + + if (fieldNodeType.WrapperName is not null) + { + // (PatternSyntaxWrapper)... + propertyType = SyntaxFactory.IdentifierName(fieldNodeType.WrapperName); + returnExpression = SyntaxFactory.CastExpression( + type: SyntaxFactory.IdentifierName(fieldNodeType.WrapperName), + expression: returnExpression); + } + } + else + { + // PatternAccessor(this.SyntaxNode) + returnExpression = SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName(field.AccessorName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("SyntaxNode")))))); + } + + // public T Field + // { + // get + // { + // return ...; + // } + // } + PropertyDeclarationSyntax property = SyntaxFactory.PropertyDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)), + type: propertyType, + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier(field.Name), + accessorList: SyntaxFactory.AccessorList(SyntaxFactory.SingletonList(SyntaxFactory.AccessorDeclaration( + SyntaxKind.GetAccessorDeclaration, + SyntaxFactory.Block( + SyntaxFactory.ReturnStatement(returnExpression))))), + expressionBody: null, + initializer: null, + semicolonToken: default); + + if (first) + { + property = property.WithLeadingBlankLine(); + first = false; + } + + members = members.Add(property); + } + + for (var baseNode = syntaxData.TryGetNode(nodeData.BaseName); baseNode?.WrapperName is not null; baseNode = syntaxData.TryGetNode(baseNode.BaseName)) + { + // public static explicit operator SyntaxWrapper(BaseSyntaxWrapper node) + // { + // return (SyntaxWrapper)node.SyntaxNode; + // } + ConversionOperatorDeclarationSyntax wrapperConversion = SyntaxFactory.ConversionOperatorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + implicitOrExplicitKeyword: SyntaxFactory.Token(SyntaxKind.ExplicitKeyword), + operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName(baseNode.WrapperName), + identifier: SyntaxFactory.Identifier("node"), + @default: null))), + body: SyntaxFactory.Block(SyntaxFactory.ReturnStatement( + SyntaxFactory.CastExpression( + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("node"), + name: SyntaxFactory.IdentifierName("SyntaxNode"))))), + expressionBody: null, + semicolonToken: default); + + if (first) + { + wrapperConversion = wrapperConversion.WithLeadingBlankLine(); + first = false; + } + + members = members.Add(wrapperConversion); + } + + // public static explicit operator WhenClauseSyntaxWrapper(SyntaxNode node) + // { + // if (node == null) + // { + // return default; + // } + // + // if (!IsInstance(node)) + // { + // throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + // } + // + // return new WhenClauseSyntaxWrapper((CSharpSyntaxNode)node); + // } + var nodeConversion = SyntaxFactory.ConversionOperatorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + implicitOrExplicitKeyword: SyntaxFactory.Token(SyntaxKind.ExplicitKeyword), + operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName("SyntaxNode"), + identifier: SyntaxFactory.Identifier("node"), + @default: null))), + body: SyntaxFactory.Block( + SyntaxFactory.IfStatement( + condition: SyntaxFactory.BinaryExpression( + SyntaxKind.EqualsExpression, + left: SyntaxFactory.IdentifierName("node"), + right: SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)), + statement: SyntaxFactory.Block( + SyntaxFactory.ReturnStatement(SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression)))), + SyntaxFactory.IfStatement( + condition: SyntaxFactory.PrefixUnaryExpression( + SyntaxKind.LogicalNotExpression, + operand: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName("IsInstance"), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(SyntaxFactory.IdentifierName("node")))))), + statement: SyntaxFactory.Block( + SyntaxFactory.ThrowStatement(SyntaxFactory.ObjectCreationExpression( + type: SyntaxFactory.IdentifierName("InvalidCastException"), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.InterpolatedStringExpression( + SyntaxFactory.Token(SyntaxKind.InterpolatedStringStartToken), + SyntaxFactory.List(new InterpolatedStringContentSyntax[] + { + SyntaxFactory.InterpolatedStringText(SyntaxFactory.Token( + leading: default, + SyntaxKind.InterpolatedStringTextToken, + "Cannot cast '", + "Cannot cast '", + trailing: default)), + SyntaxFactory.Interpolation(SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("node"), + name: SyntaxFactory.IdentifierName("GetType")), + argumentList: SyntaxFactory.ArgumentList()), + name: SyntaxFactory.IdentifierName("FullName"))), + SyntaxFactory.InterpolatedStringText(SyntaxFactory.Token( + leading: default, + SyntaxKind.InterpolatedStringTextToken, + "' to '", + "' to '", + trailing: default)), + SyntaxFactory.Interpolation(SyntaxFactory.IdentifierName("WrappedTypeName")), + SyntaxFactory.InterpolatedStringText(SyntaxFactory.Token( + leading: default, + SyntaxKind.InterpolatedStringTextToken, + "'", + "'", + trailing: default)), + }))))), + initializer: null)))), + SyntaxFactory.ReturnStatement(SyntaxFactory.ObjectCreationExpression( + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.CastExpression( + type: SyntaxFactory.IdentifierName(concreteBase), + expression: SyntaxFactory.IdentifierName("node"))))), + initializer: null))), + expressionBody: null, + semicolonToken: default); + + if (first) + { + nodeConversion = nodeConversion.WithLeadingBlankLine(); + first = false; + } + + members = members.Add(nodeConversion); + + for (var baseNode = syntaxData.TryGetNode(nodeData.BaseName); baseNode?.WrapperName is not null; baseNode = syntaxData.TryGetNode(baseNode.BaseName)) + { + // public static implicit operator BaseSyntaxWrapper(SyntaxWrapper wrapper) + // { + // return BaseSyntaxWrapper.FromUpcast(wrapper.node); + // } + members = members.Add(SyntaxFactory.ConversionOperatorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + implicitOrExplicitKeyword: SyntaxFactory.Token(SyntaxKind.ImplicitKeyword), + operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), + type: SyntaxFactory.IdentifierName(baseNode.WrapperName), + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + identifier: SyntaxFactory.Identifier("wrapper"), + @default: null))), + body: SyntaxFactory.Block(SyntaxFactory.ReturnStatement( + SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName(baseNode.WrapperName), + name: SyntaxFactory.IdentifierName("FromUpcast")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("wrapper"), + name: SyntaxFactory.IdentifierName("node")))))))), + expressionBody: null, + semicolonToken: default)); + } + + // public static implicit operator CSharpSyntaxNode(SyntaxWrapper wrapper) + // { + // return wrapper.node; + // } + members = members.Add(SyntaxFactory.ConversionOperatorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + implicitOrExplicitKeyword: SyntaxFactory.Token(SyntaxKind.ImplicitKeyword), + operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), + type: SyntaxFactory.IdentifierName(concreteBase), + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + identifier: SyntaxFactory.Identifier("wrapper"), + @default: null))), + body: SyntaxFactory.Block(SyntaxFactory.ReturnStatement(SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("wrapper"), + name: SyntaxFactory.IdentifierName("node")))), + expressionBody: null, + semicolonToken: default)); + + // public static bool IsInstance(SyntaxNode node) + // { + // return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + // } + members = members.Add(SyntaxFactory.MethodDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + returnType: SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.BoolKeyword)), + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier("IsInstance"), + typeParameterList: null, + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName("SyntaxNode"), + identifier: SyntaxFactory.Identifier("node"), + @default: null))), + constraintClauses: default, + body: SyntaxFactory.Block( + SyntaxFactory.ReturnStatement(SyntaxFactory.BinaryExpression( + SyntaxKind.LogicalAndExpression, + left: SyntaxFactory.BinaryExpression( + SyntaxKind.NotEqualsExpression, + left: SyntaxFactory.IdentifierName("node"), + right: SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)), + right: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("LightupHelpers"), + name: SyntaxFactory.IdentifierName("CanWrapNode")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("node")), + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("WrappedType")), + })))))), + expressionBody: null)); + + foreach (var field in nodeData.Fields) + { + if (field.IsSkipped) + { + continue; + } + + string valueName = char.ToLowerInvariant(field.Name[0]) + field.Name.Substring(1); + + ExpressionSyntax convertedValue = SyntaxFactory.IdentifierName(valueName); + + TypeSyntax propertyType = SyntaxFactory.ParseTypeName(field.GetAccessorResultType(syntaxData)); + if (syntaxData.TryGetNode(field.Type) is { WrapperName: { } wrapperName }) + { + propertyType = SyntaxFactory.IdentifierName(wrapperName); + } + + ExpressionSyntax returnExpression = SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.IdentifierName(field.WithAccessorName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.ThisExpression(), + name: SyntaxFactory.IdentifierName("SyntaxNode"))), + SyntaxFactory.Argument(convertedValue), + }))); + + // public SyntaxWrapper WithField(T value) + // { + // return new SyntaxWrapper(...); + // } + members = members.Add(SyntaxFactory.MethodDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)), + returnType: SyntaxFactory.IdentifierName(nodeData.WrapperName), + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier("With" + field.Name), + typeParameterList: null, + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: propertyType, + identifier: SyntaxFactory.Identifier(valueName), + @default: null))), + constraintClauses: default, + body: SyntaxFactory.Block(SyntaxFactory.ReturnStatement( + SyntaxFactory.ObjectCreationExpression( + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(returnExpression))), + initializer: null))), + expressionBody: null, + semicolonToken: default)); + } + + if (nodeData.Kind == NodeKind.Abstract) + { + // internal static SyntaxWrapper FromUpcast(CSharpSyntaxNode node) + // { + // return new SyntaxWrapper(node); + // } + members = members.Add(SyntaxFactory.MethodDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + returnType: SyntaxFactory.IdentifierName(nodeData.WrapperName), + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier("FromUpcast"), + typeParameterList: null, + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName(concreteBase), + identifier: SyntaxFactory.Identifier("node"), + @default: null))), + constraintClauses: default, + body: SyntaxFactory.Block( + SyntaxFactory.ReturnStatement(SyntaxFactory.ObjectCreationExpression( + type: SyntaxFactory.IdentifierName(nodeData.WrapperName), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument(SyntaxFactory.IdentifierName("node")))), + initializer: null))), + expressionBody: null)); + } + + var wrapperStruct = SyntaxFactory.StructDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword), SyntaxFactory.Token(SyntaxKind.PartialKeyword)), + identifier: SyntaxFactory.Identifier(nodeData.WrapperName), + typeParameterList: null, + baseList: SyntaxFactory.BaseList(SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.SimpleBaseType(SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("ISyntaxWrapper"), + typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.IdentifierName(concreteBase))))))), + constraintClauses: default, + members: members); + var wrapperNamespace = SyntaxFactory.NamespaceDeclaration( + name: SyntaxFactory.ParseName("StyleCop.Analyzers.Lightup"), + externs: default, + usings: SyntaxFactory.List() + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System.Collections.Immutable"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Microsoft.CodeAnalysis"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Microsoft.CodeAnalysis.CSharp"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Microsoft.CodeAnalysis.CSharp.Syntax"))), + members: SyntaxFactory.SingletonList(wrapperStruct)); + + wrapperNamespace = wrapperNamespace + .NormalizeWhitespace() + .WithLeadingTrivia( + SyntaxFactory.Comment("// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved."), + SyntaxFactory.CarriageReturnLineFeed, + SyntaxFactory.Comment("// Licensed under the MIT License. See LICENSE in the project root for license information."), + SyntaxFactory.CarriageReturnLineFeed, + SyntaxFactory.CarriageReturnLineFeed) + .WithTrailingTrivia( + SyntaxFactory.CarriageReturnLineFeed); + + context.AddSource(nodeData.WrapperName + ".g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8)); + } + + private void GenerateSyntaxWrapperHelper(in GeneratorExecutionContext context, ImmutableArray wrapperTypes) + { + // private static readonly ImmutableDictionary WrappedTypes; + var wrappedTypes = SyntaxFactory.FieldDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), + declaration: SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("ImmutableDictionary"), + typeArgumentList: SyntaxFactory.TypeArgumentList( + SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName("Type"), + SyntaxFactory.IdentifierName("Type"), + }))), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier("WrappedTypes"))))); + + // var csharpCodeAnalysisAssembly = typeof(CSharpSyntaxNode).GetTypeInfo().Assembly; + // var builder = ImmutableDictionary.CreateBuilder(); + var staticCtorStatements = SyntaxFactory.List() + .Add(SyntaxFactory.LocalDeclarationStatement(SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.IdentifierName("var"), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator( + identifier: SyntaxFactory.Identifier("csharpCodeAnalysisAssembly"), + argumentList: null, + initializer: SyntaxFactory.EqualsValueClause( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.InvocationExpression( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.TypeOfExpression(SyntaxFactory.IdentifierName("CSharpSyntaxNode")), + name: SyntaxFactory.IdentifierName("GetTypeInfo"))), + name: SyntaxFactory.IdentifierName("Assembly")))))))) + .Add(SyntaxFactory.LocalDeclarationStatement(SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.IdentifierName("var"), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator( + identifier: SyntaxFactory.Identifier("builder"), + argumentList: null, + initializer: SyntaxFactory.EqualsValueClause( + SyntaxFactory.InvocationExpression( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("ImmutableDictionary"), + name: SyntaxFactory.GenericName( + identifier: SyntaxFactory.Identifier("CreateBuilder"), + typeArgumentList: SyntaxFactory.TypeArgumentList( + SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.IdentifierName("Type"), + SyntaxFactory.IdentifierName("Type"), + }))))))))))); + + bool first = true; + foreach (var node in wrapperTypes.OrderBy(node => node.Name, StringComparer.OrdinalIgnoreCase)) + { + if (node.WrapperName is null) + { + continue; + } + + if (node.Name == nameof(CommonForEachStatementSyntax)) + { + // Prior to C# 7, ForEachStatementSyntax was the base type for all foreach statements. If + // the CommonForEachStatementSyntax type isn't found at runtime, we fall back to using this type instead. + // + // var forEachStatementSyntaxType = csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.WrappedTypeName) + // ?? csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.FallbackWrappedTypeName); + staticCtorStatements = staticCtorStatements.Add( + SyntaxFactory.LocalDeclarationStatement(SyntaxFactory.VariableDeclaration( + type: SyntaxFactory.IdentifierName("var"), + variables: SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator( + identifier: SyntaxFactory.Identifier("forEachStatementSyntaxType"), + argumentList: null, + initializer: SyntaxFactory.EqualsValueClause( + SyntaxFactory.BinaryExpression( + SyntaxKind.CoalesceExpression, + left: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("csharpCodeAnalysisAssembly"), + name: SyntaxFactory.IdentifierName("GetType")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName(node.WrapperName), + name: SyntaxFactory.IdentifierName("WrappedTypeName")))))), + right: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("csharpCodeAnalysisAssembly"), + name: SyntaxFactory.IdentifierName("GetType")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName(node.WrapperName), + name: SyntaxFactory.IdentifierName("FallbackWrappedTypeName"))))))))))))); + + // builder.Add(typeof(CommonForEachStatementSyntaxWrapper), forEachStatementSyntaxType); + staticCtorStatements = staticCtorStatements.Add(SyntaxFactory.ExpressionStatement( + SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("builder"), + name: SyntaxFactory.IdentifierName("Add")), + argumentList: SyntaxFactory.ArgumentList( + SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(SyntaxFactory.IdentifierName(node.WrapperName))), + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("forEachStatementSyntaxType")), + }))))); + + continue; + } + + // builder.Add(typeof(ConstantPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ConstantPatternSyntaxWrapper.WrappedTypeName)); + ExpressionStatementSyntax statement = SyntaxFactory.ExpressionStatement( + SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("builder"), + name: SyntaxFactory.IdentifierName("Add")), + argumentList: SyntaxFactory.ArgumentList( + SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(SyntaxFactory.IdentifierName(node.WrapperName))), + SyntaxFactory.Argument( + SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("csharpCodeAnalysisAssembly"), + name: SyntaxFactory.IdentifierName("GetType")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Argument( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName(node.WrapperName), + name: SyntaxFactory.IdentifierName("WrappedTypeName"))))))), + })))); + + if (first) + { + statement = statement.WithLeadingBlankLine(); + first = false; + } + + staticCtorStatements = staticCtorStatements.Add(statement); + } + + // WrappedTypes = builder.ToImmutable(); + staticCtorStatements = staticCtorStatements.Add(SyntaxFactory.ExpressionStatement( + SyntaxFactory.AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + left: SyntaxFactory.IdentifierName("WrappedTypes"), + right: SyntaxFactory.InvocationExpression( + SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("builder"), + name: SyntaxFactory.IdentifierName("ToImmutable"))))).WithLeadingBlankLine()); + + var staticCtor = SyntaxFactory.ConstructorDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + identifier: SyntaxFactory.Identifier("SyntaxWrapperHelper"), + parameterList: SyntaxFactory.ParameterList(), + initializer: null, + body: SyntaxFactory.Block(staticCtorStatements), + expressionBody: null).WithLeadingBlankLine(); + + // /// + // /// Gets the type that is wrapped by the given wrapper. + // /// + // /// Type of the wrapper for which the wrapped type should be retrieved. + // /// The wrapped type, or null if there is no info. + // internal static Type GetWrappedType(Type wrapperType) + // { + // if (WrappedTypes.TryGetValue(wrapperType, out Type wrappedType)) + // { + // return wrappedType; + // } + // + // return null; + // } + var getWrappedType = SyntaxFactory.MethodDeclaration( + attributeLists: default, + modifiers: SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + returnType: SyntaxFactory.IdentifierName("Type"), + explicitInterfaceSpecifier: null, + identifier: SyntaxFactory.Identifier("GetWrappedType"), + typeParameterList: null, + parameterList: SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Parameter( + attributeLists: default, + modifiers: default, + type: SyntaxFactory.IdentifierName("Type"), + identifier: SyntaxFactory.Identifier("wrapperType"), + @default: null))), + constraintClauses: default, + body: SyntaxFactory.Block( + SyntaxFactory.IfStatement( + condition: SyntaxFactory.InvocationExpression( + expression: SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + expression: SyntaxFactory.IdentifierName("WrappedTypes"), + name: SyntaxFactory.IdentifierName("TryGetValue")), + argumentList: SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList( + new[] + { + SyntaxFactory.Argument(SyntaxFactory.IdentifierName("wrapperType")), + SyntaxFactory.Argument( + nameColon: null, + refKindKeyword: SyntaxFactory.Token(SyntaxKind.OutKeyword), + expression: SyntaxFactory.DeclarationExpression( + type: SyntaxFactory.IdentifierName("Type"), + designation: SyntaxFactory.SingleVariableDesignation(SyntaxFactory.Identifier("wrappedType")))), + }))), + statement: SyntaxFactory.Block( + SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName("wrappedType")))), + SyntaxFactory.ReturnStatement(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))), + expressionBody: null); + + getWrappedType = getWrappedType.WithLeadingTrivia(SyntaxFactory.TriviaList( + SyntaxFactory.Trivia(SyntaxFactory.DocumentationComment( + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlSummaryElement( + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" Gets the type that is wrapped by the given wrapper."), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" ")), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlParamElement( + "wrapperType", + SyntaxFactory.XmlText("Type of the wrapper for which the wrapped type should be retrieved.")), + SyntaxFactory.XmlNewLine(Environment.NewLine), + SyntaxFactory.XmlText(" "), + SyntaxFactory.XmlReturnsElement( + SyntaxFactory.XmlText("The wrapped type, or null if there is no info.")), + SyntaxFactory.XmlNewLine(Environment.NewLine).WithoutTrailingTrivia())))); + + var wrapperHelperClass = SyntaxFactory.ClassDeclaration( + attributeLists: default, + modifiers: SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.InternalKeyword)).Add(SyntaxFactory.Token(SyntaxKind.StaticKeyword)), + identifier: SyntaxFactory.Identifier("SyntaxWrapperHelper"), + typeParameterList: null, + baseList: null, + constraintClauses: default, + members: SyntaxFactory.List() + .Add(wrappedTypes) + .Add(staticCtor) + .Add(getWrappedType)); + var wrapperNamespace = SyntaxFactory.NamespaceDeclaration( + name: SyntaxFactory.ParseName("StyleCop.Analyzers.Lightup"), + externs: default, + usings: SyntaxFactory.List() + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System.Collections.Immutable"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System.Reflection"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Microsoft.CodeAnalysis"))) + .Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Microsoft.CodeAnalysis.CSharp"))), + members: SyntaxFactory.SingletonList(wrapperHelperClass)); + + wrapperNamespace = wrapperNamespace + .NormalizeWhitespace() + .WithLeadingTrivia( + SyntaxFactory.Comment("// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved."), + SyntaxFactory.CarriageReturnLineFeed, + SyntaxFactory.Comment("// Licensed under the MIT License. See LICENSE in the project root for license information."), + SyntaxFactory.CarriageReturnLineFeed, + SyntaxFactory.CarriageReturnLineFeed) + .WithTrailingTrivia( + SyntaxFactory.CarriageReturnLineFeed); + + context.AddSource("SyntaxWrapperHelper.g.cs", SourceText.From(wrapperNamespace.ToFullString(), Encoding.UTF8)); + } + + private sealed class SyntaxData + { + private readonly Dictionary nameToNode; + + public SyntaxData(in GeneratorExecutionContext context, XDocument document) + { + var nodesBuilder = ImmutableArray.CreateBuilder(); + foreach (var element in document.XPathSelectElement("/Tree[@Root='SyntaxNode']").XPathSelectElements("PredefinedNode|AbstractNode|Node")) + { + nodesBuilder.Add(new NodeData(in context, element)); + } + + this.Nodes = nodesBuilder.ToImmutable(); + this.nameToNode = this.Nodes.ToDictionary(node => node.Name); + } + + public ImmutableArray Nodes { get; } + + public NodeData? TryGetConcreteType(NodeData? node) + { + for (var current = node; current is not null; current = this.TryGetNode(current.BaseName)) + { + if (current.WrapperName is null) + { + // This is not a wrapper + return current; + } + } + + return null; + } + + public NodeData? TryGetConcreteBase(NodeData node) + { + return this.TryGetConcreteType(this.TryGetNode(node.BaseName)); + } + + public NodeData? TryGetNode(string name) + { + this.nameToNode.TryGetValue(name, out var node); + return node; + } + } + + private sealed class NodeData + { + public NodeData(in GeneratorExecutionContext context, XElement element) + { + this.Kind = element.Name.LocalName switch + { + "PredefinedNode" => NodeKind.Predefined, + "AbstractNode" => NodeKind.Abstract, + "Node" => NodeKind.Concrete, + _ => throw new NotSupportedException($"Unknown element name '{element.Name}'"), + }; + + this.Name = element.Attribute("Name").Value; + + this.ExistingType = context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}") + ?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.CSharp.{this.Name}") + ?? context.Compilation.GetTypeByMetadataName($"Microsoft.CodeAnalysis.{this.Name}"); + if (this.ExistingType?.DeclaredAccessibility == Accessibility.Public) + { + this.WrapperName = null; + } + else + { + this.WrapperName = this.Name + "Wrapper"; + } + + this.BaseName = element.Attribute("Base").Value; + this.Fields = element.XPathSelectElements("descendant::Field").Select(field => new FieldData(this, field)).ToImmutableArray(); + } + + public NodeKind Kind { get; } + + public string Name { get; } + + public INamedTypeSymbol? ExistingType { get; } + + public string? WrapperName { get; } + + public string BaseName { get; } + + public ImmutableArray Fields { get; } + + internal FieldData? TryGetField(string name) + { + return this.Fields.SingleOrDefault(field => field.Name == name); + } + } + + private sealed class FieldData + { + private readonly NodeData nodeData; + + public FieldData(NodeData nodeData, XElement element) + { + this.nodeData = nodeData; + + this.Name = element.Attribute("Name").Value; + + var type = element.Attribute("Type").Value; + this.Type = type switch + { + "SyntaxList" => nameof(SyntaxTokenList), + _ => type, + }; + + this.IsOverride = element.Attribute("Override")?.Value == "true"; + + this.AccessorName = this.Name + "Accessor"; + this.WithAccessorName = "With" + this.Name + "Accessor"; + } + + public bool IsSkipped => false; + + public string Name { get; } + + public string AccessorName { get; } + + public string WithAccessorName { get; } + + public string Type { get; } + + public bool IsOverride { get; } + + /// + /// Gets a value indicating whether this field is implemented as an extension method in the lightup layer. + /// + public bool IsExtensionField + { + get + { + return this.nodeData.ExistingType is not null + && this.nodeData.ExistingType.GetMembers(this.Name).IsEmpty; + } + } + + public NodeData GetDeclaringNode(SyntaxData syntaxData) + { + for (var current = this.nodeData; current is not null; current = syntaxData.TryGetNode(current.BaseName)) + { + var currentField = current.TryGetField(this.Name); + if (currentField is { IsOverride: false }) + { + return currentField.nodeData; + } + } + + throw new NotSupportedException("Unable to find declaring node."); + } + + public bool IsWrappedSeparatedSyntaxList(SyntaxData syntaxData, [NotNullWhen(true)] out NodeData? element) + { + if (this.Type.StartsWith("SeparatedSyntaxList<") && this.Type.EndsWith(">")) + { + var elementTypeName = this.Type.Substring("SeparatedSyntaxList<".Length, this.Type.Length - "SeparatedSyntaxList<".Length - ">".Length); + var elementTypeNode = syntaxData.TryGetNode(elementTypeName); + if (elementTypeNode is { WrapperName: not null }) + { + element = elementTypeNode; + return true; + } + } + + element = null; + return false; + } + + public string GetAccessorResultType(SyntaxData syntaxData) + { + var typeNode = syntaxData.TryGetNode(this.Type); + if (typeNode is not null) + { + return syntaxData.TryGetConcreteType(typeNode)?.Name ?? nameof(SyntaxNode); + } + + if (this.IsWrappedSeparatedSyntaxList(syntaxData, out var elementTypeNode)) + { + return $"SeparatedSyntaxListWrapper<{elementTypeNode.WrapperName}>"; + } + + return this.Type; + } + + public string? GetAccessorResultElementType(SyntaxData syntaxData) + { + if (this.IsWrappedSeparatedSyntaxList(syntaxData, out var elementTypeNode)) + { + return elementTypeNode.WrapperName; + } + + return null; + } + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/SyntaxWrapperHelperTestsCSharp7.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/SyntaxWrapperHelperTestsCSharp7.cs new file mode 100644 index 0000000000..0e17cde56f --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/SyntaxWrapperHelperTestsCSharp7.cs @@ -0,0 +1,11 @@ +// 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.Test.CSharp7.Lightup +{ + using StyleCop.Analyzers.Test.Lightup; + + public class SyntaxWrapperHelperTestsCSharp7 : SyntaxWrapperHelperTests + { + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/WrapperHelperTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/WrapperHelperTests.cs deleted file mode 100644 index 9d74fc0ce9..0000000000 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/WrapperHelperTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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.Test.CSharp7.Lightup -{ - using System.Linq; - using System.Reflection; - using StyleCop.Analyzers.Lightup; - using Xunit; - - public class WrapperHelperTests - { - [Fact] - public void VerifyThatAllWrapperClassesArePresent() - { - var wrapperTypes = typeof(ISyntaxWrapper<>).Assembly.GetTypes() - .Where(t => t.GetTypeInfo().ImplementedInterfaces.Any(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(ISyntaxWrapper<>)))); - - foreach (var wrapperType in wrapperTypes) - { - var wrappedType = WrapperHelper.GetWrappedType(wrapperType); - Assert.NotNull(wrapperType); - } - } - } -} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/WrapperHelperTestsCSharp8.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/SyntaxWrapperHelperTestsCSharp8.cs similarity index 77% rename from StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/WrapperHelperTestsCSharp8.cs rename to StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/SyntaxWrapperHelperTestsCSharp8.cs index 6c4c96091d..de7ed0073c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/WrapperHelperTestsCSharp8.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/SyntaxWrapperHelperTestsCSharp8.cs @@ -5,7 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.Lightup { using StyleCop.Analyzers.Test.CSharp7.Lightup; - public class WrapperHelperTestsCSharp8 : WrapperHelperTests + public class SyntaxWrapperHelperTestsCSharp8 : SyntaxWrapperHelperTestsCSharp7 { } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/WrapperHelperTestsCSharp9.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/SyntaxWrapperHelperTestsCSharp9.cs similarity index 77% rename from StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/WrapperHelperTestsCSharp9.cs rename to StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/SyntaxWrapperHelperTestsCSharp9.cs index 132b525270..7df0a8adf9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/WrapperHelperTestsCSharp9.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/SyntaxWrapperHelperTestsCSharp9.cs @@ -5,7 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp9.Lightup { using StyleCop.Analyzers.Test.CSharp8.Lightup; - public class WrapperHelperTestsCSharp9 : WrapperHelperTestsCSharp8 + public class SyntaxWrapperHelperTestsCSharp9 : SyntaxWrapperHelperTestsCSharp8 { } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/SyntaxWrapperHelperTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/SyntaxWrapperHelperTests.cs new file mode 100644 index 0000000000..c32f0ced7e --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/SyntaxWrapperHelperTests.cs @@ -0,0 +1,53 @@ +// 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.Test.Lightup +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using StyleCop.Analyzers.Lightup; + using Xunit; + + public class SyntaxWrapperHelperTests + { + public static IEnumerable SyntaxWrapperClasses + { + get + { + var wrapperTypes = typeof(ISyntaxWrapper<>).Assembly.GetTypes() + .Where(t => t.GetTypeInfo().ImplementedInterfaces.Any(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(ISyntaxWrapper<>)))); + + foreach (var wrapperType in wrapperTypes) + { + yield return new object[] { wrapperType }; + } + } + } + + [Theory] + [MemberData(nameof(SyntaxWrapperClasses))] + public void VerifyThatWrapperClassIsPresent(Type wrapperType) + { + var wrappedTypeName = $"Microsoft.CodeAnalysis.CSharp.Syntax.{wrapperType.Name.Substring(0, wrapperType.Name.Length - "Wrapper".Length)}"; + if (typeof(CSharpSyntaxNode).Assembly.GetType(wrappedTypeName) is { } expected) + { + var wrappedType = SyntaxWrapperHelper.GetWrappedType(wrapperType); + Assert.Same(expected, wrappedType); + } + else if (wrapperType == typeof(CommonForEachStatementSyntaxWrapper)) + { + // Special case for C# 6 analysis compatibility + Assert.False(LightupHelpers.SupportsCSharp7); + Assert.Same(typeof(ForEachStatementSyntax), SyntaxWrapperHelper.GetWrappedType(wrapperType)); + } + else + { + Assert.Null(SyntaxWrapperHelper.GetWrappedType(wrapperType)); + } + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.ruleset b/StyleCop.Analyzers/StyleCop.Analyzers.ruleset index d23c45b61a..35d99263d4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.ruleset +++ b/StyleCop.Analyzers/StyleCop.Analyzers.ruleset @@ -80,6 +80,7 @@ + diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator/OperationWrapperHelper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator/OperationWrapperHelper.g.cs index 4427f80e76..371e9bf6f6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator/OperationWrapperHelper.g.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator/OperationWrapperHelper.g.cs @@ -140,6 +140,11 @@ static OperationWrapperHelper() WrappedTypes = builder.ToImmutable(); } + /// + /// Gets the type that is wrapped by the given wrapper. + /// + /// Type of the wrapper for which the wrapped type should be retrieved. + /// The wrapped type, or null if there is no info. internal static Type GetWrappedType(Type wrapperType) { if (WrappedTypes.TryGetValue(wrapperType, out Type wrappedType)) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseObjectCreationExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseObjectCreationExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..74f02aab9a --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseObjectCreationExpressionSyntaxWrapper.g.cs @@ -0,0 +1,113 @@ +// 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 BaseObjectCreationExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func NewKeywordAccessor; + private static readonly Func ArgumentListAccessor; + private static readonly Func InitializerAccessor; + private static readonly Func WithNewKeywordAccessor; + private static readonly Func WithArgumentListAccessor; + private static readonly Func WithInitializerAccessor; + + private readonly ExpressionSyntax node; + + static BaseObjectCreationExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(BaseObjectCreationExpressionSyntaxWrapper)); + NewKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(NewKeyword)); + ArgumentListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ArgumentList)); + InitializerAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Initializer)); + WithNewKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NewKeyword)); + WithArgumentListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ArgumentList)); + WithInitializerAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Initializer)); + } + + private BaseObjectCreationExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public SyntaxToken NewKeyword + { + get + { + return NewKeywordAccessor(this.SyntaxNode); + } + } + + public ArgumentListSyntax ArgumentList + { + get + { + return ArgumentListAccessor(this.SyntaxNode); + } + } + + public InitializerExpressionSyntax Initializer + { + get + { + return InitializerAccessor(this.SyntaxNode); + } + } + + public static explicit operator BaseObjectCreationExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new BaseObjectCreationExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator ExpressionSyntax(BaseObjectCreationExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public BaseObjectCreationExpressionSyntaxWrapper WithNewKeyword(SyntaxToken newKeyword) + { + return new BaseObjectCreationExpressionSyntaxWrapper(WithNewKeywordAccessor(this.SyntaxNode, newKeyword)); + } + + public BaseObjectCreationExpressionSyntaxWrapper WithArgumentList(ArgumentListSyntax argumentList) + { + return new BaseObjectCreationExpressionSyntaxWrapper(WithArgumentListAccessor(this.SyntaxNode, argumentList)); + } + + public BaseObjectCreationExpressionSyntaxWrapper WithInitializer(InitializerExpressionSyntax initializer) + { + return new BaseObjectCreationExpressionSyntaxWrapper(WithInitializerAccessor(this.SyntaxNode, initializer)); + } + + internal static BaseObjectCreationExpressionSyntaxWrapper FromUpcast(ExpressionSyntax node) + { + return new BaseObjectCreationExpressionSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseParameterSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseParameterSyntaxWrapper.g.cs new file mode 100644 index 0000000000..139edba394 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BaseParameterSyntaxWrapper.g.cs @@ -0,0 +1,113 @@ +// 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 BaseParameterSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.BaseParameterSyntax"; + private static readonly Type WrappedType; + + private static readonly Func> AttributeListsAccessor; + private static readonly Func ModifiersAccessor; + private static readonly Func TypeAccessor; + private static readonly Func, CSharpSyntaxNode> WithAttributeListsAccessor; + private static readonly Func WithModifiersAccessor; + private static readonly Func WithTypeAccessor; + + private readonly CSharpSyntaxNode node; + + static BaseParameterSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(BaseParameterSyntaxWrapper)); + AttributeListsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(AttributeLists)); + ModifiersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Modifiers)); + TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); + WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + } + + private BaseParameterSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxList AttributeLists + { + get + { + return AttributeListsAccessor(this.SyntaxNode); + } + } + + public SyntaxTokenList Modifiers + { + get + { + return ModifiersAccessor(this.SyntaxNode); + } + } + + public TypeSyntax Type + { + get + { + return TypeAccessor(this.SyntaxNode); + } + } + + public static explicit operator BaseParameterSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new BaseParameterSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(BaseParameterSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public BaseParameterSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new BaseParameterSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + + public BaseParameterSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) + { + return new BaseParameterSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); + } + + public BaseParameterSyntaxWrapper WithType(TypeSyntax type) + { + return new BaseParameterSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + } + + internal static BaseParameterSyntaxWrapper FromUpcast(CSharpSyntaxNode node) + { + return new BaseParameterSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BinaryPatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BinaryPatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..305a42df27 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/BinaryPatternSyntaxWrapper.g.cs @@ -0,0 +1,128 @@ +// 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 BinaryPatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.BinaryPatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func LeftAccessor; + private static readonly Func OperatorTokenAccessor; + private static readonly Func RightAccessor; + private static readonly Func WithLeftAccessor; + private static readonly Func WithOperatorTokenAccessor; + private static readonly Func WithRightAccessor; + + private readonly CSharpSyntaxNode node; + + static BinaryPatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(BinaryPatternSyntaxWrapper)); + LeftAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Left)); + OperatorTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OperatorToken)); + RightAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Right)); + WithLeftAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Left)); + WithOperatorTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OperatorToken)); + WithRightAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Right)); + } + + private BinaryPatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public PatternSyntaxWrapper Left + { + get + { + return (PatternSyntaxWrapper)LeftAccessor(this.SyntaxNode); + } + } + + public SyntaxToken OperatorToken + { + get + { + return OperatorTokenAccessor(this.SyntaxNode); + } + } + + public PatternSyntaxWrapper Right + { + get + { + return (PatternSyntaxWrapper)RightAccessor(this.SyntaxNode); + } + } + + public static explicit operator BinaryPatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (BinaryPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator BinaryPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (BinaryPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator BinaryPatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new BinaryPatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(BinaryPatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(BinaryPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(BinaryPatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public BinaryPatternSyntaxWrapper WithLeft(PatternSyntaxWrapper left) + { + return new BinaryPatternSyntaxWrapper(WithLeftAccessor(this.SyntaxNode, left)); + } + + public BinaryPatternSyntaxWrapper WithOperatorToken(SyntaxToken operatorToken) + { + return new BinaryPatternSyntaxWrapper(WithOperatorTokenAccessor(this.SyntaxNode, operatorToken)); + } + + public BinaryPatternSyntaxWrapper WithRight(PatternSyntaxWrapper right) + { + return new BinaryPatternSyntaxWrapper(WithRightAccessor(this.SyntaxNode, right)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CasePatternSwitchLabelSyntaxWrapper.g.cs similarity index 88% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CasePatternSwitchLabelSyntaxWrapper.g.cs index 85ab741d58..927e6dea97 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CasePatternSwitchLabelSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CasePatternSwitchLabelSyntaxWrapper.g.cs @@ -4,11 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct CasePatternSwitchLabelSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct CasePatternSwitchLabelSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.CasePatternSwitchLabelSyntax"; private static readonly Type WrappedType; @@ -16,21 +17,21 @@ internal struct CasePatternSwitchLabelSyntaxWrapper : ISyntaxWrapper PatternAccessor; private static readonly Func WhenClauseAccessor; private static readonly Func WithKeywordAccessor; - private static readonly Func WithColonTokenAccessor; private static readonly Func WithPatternAccessor; private static readonly Func WithWhenClauseAccessor; + private static readonly Func WithColonTokenAccessor; private readonly SwitchLabelSyntax node; static CasePatternSwitchLabelSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(CasePatternSwitchLabelSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(CasePatternSwitchLabelSyntaxWrapper)); PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); WhenClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(WhenClause)); - WithKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SwitchLabelSyntax.Keyword)); - WithColonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SwitchLabelSyntax.ColonToken)); + WithKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Keyword)); WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); WithWhenClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(WhenClause)); + WithColonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ColonToken)); } private CasePatternSwitchLabelSyntaxWrapper(SwitchLabelSyntax node) @@ -40,6 +41,14 @@ private CasePatternSwitchLabelSyntaxWrapper(SwitchLabelSyntax node) public SwitchLabelSyntax SyntaxNode => this.node; + public SyntaxToken Keyword + { + get + { + return this.SyntaxNode.Keyword; + } + } + public PatternSyntaxWrapper Pattern { get @@ -56,6 +65,14 @@ public WhenClauseSyntaxWrapper WhenClause } } + public SyntaxToken ColonToken + { + get + { + return this.SyntaxNode.ColonToken; + } + } + public static explicit operator CasePatternSwitchLabelSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -86,11 +103,6 @@ public CasePatternSwitchLabelSyntaxWrapper WithKeyword(SyntaxToken keyword) return new CasePatternSwitchLabelSyntaxWrapper(WithKeywordAccessor(this.SyntaxNode, keyword)); } - public CasePatternSwitchLabelSyntaxWrapper WithColonToken(SyntaxToken colonToken) - { - return new CasePatternSwitchLabelSyntaxWrapper(WithColonTokenAccessor(this.SyntaxNode, colonToken)); - } - public CasePatternSwitchLabelSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) { return new CasePatternSwitchLabelSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern)); @@ -100,5 +112,10 @@ public CasePatternSwitchLabelSyntaxWrapper WithWhenClause(WhenClauseSyntaxWrappe { return new CasePatternSwitchLabelSyntaxWrapper(WithWhenClauseAccessor(this.SyntaxNode, whenClause)); } + + public CasePatternSwitchLabelSyntaxWrapper WithColonToken(SyntaxToken colonToken) + { + return new CasePatternSwitchLabelSyntaxWrapper(WithColonTokenAccessor(this.SyntaxNode, colonToken)); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CommonForEachStatementSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CommonForEachStatementSyntaxWrapper.g.cs new file mode 100644 index 0000000000..8e91cd2ef8 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/CommonForEachStatementSyntaxWrapper.g.cs @@ -0,0 +1,181 @@ +// 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 CommonForEachStatementSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax"; + private static readonly Type WrappedType; + + private static readonly Func AwaitKeywordAccessor; + private static readonly Func ForEachKeywordAccessor; + private static readonly Func OpenParenTokenAccessor; + private static readonly Func InKeywordAccessor; + private static readonly Func ExpressionAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func StatementAccessor; + private static readonly Func WithAwaitKeywordAccessor; + private static readonly Func WithForEachKeywordAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func WithInKeywordAccessor; + private static readonly Func WithExpressionAccessor; + private static readonly Func WithCloseParenTokenAccessor; + private static readonly Func WithStatementAccessor; + + private readonly StatementSyntax node; + + static CommonForEachStatementSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(CommonForEachStatementSyntaxWrapper)); + AwaitKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(AwaitKeyword)); + ForEachKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ForEachKeyword)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + InKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(InKeyword)); + ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + StatementAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Statement)); + WithAwaitKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(AwaitKeyword)); + WithForEachKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ForEachKeyword)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithInKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(InKeyword)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithStatementAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Statement)); + } + + private CommonForEachStatementSyntaxWrapper(StatementSyntax node) + { + this.node = node; + } + + public StatementSyntax SyntaxNode => this.node; + + public SyntaxToken AwaitKeyword + { + get + { + return AwaitKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken ForEachKeyword + { + get + { + return ForEachKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken InKeyword + { + get + { + return InKeywordAccessor(this.SyntaxNode); + } + } + + public ExpressionSyntax Expression + { + get + { + return ExpressionAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public StatementSyntax Statement + { + get + { + return StatementAccessor(this.SyntaxNode); + } + } + + public static explicit operator CommonForEachStatementSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new CommonForEachStatementSyntaxWrapper((StatementSyntax)node); + } + + public static implicit operator StatementSyntax(CommonForEachStatementSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public CommonForEachStatementSyntaxWrapper WithAwaitKeyword(SyntaxToken awaitKeyword) + { + return new CommonForEachStatementSyntaxWrapper(WithAwaitKeywordAccessor(this.SyntaxNode, awaitKeyword)); + } + + public CommonForEachStatementSyntaxWrapper WithForEachKeyword(SyntaxToken forEachKeyword) + { + return new CommonForEachStatementSyntaxWrapper(WithForEachKeywordAccessor(this.SyntaxNode, forEachKeyword)); + } + + public CommonForEachStatementSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new CommonForEachStatementSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public CommonForEachStatementSyntaxWrapper WithInKeyword(SyntaxToken inKeyword) + { + return new CommonForEachStatementSyntaxWrapper(WithInKeywordAccessor(this.SyntaxNode, inKeyword)); + } + + public CommonForEachStatementSyntaxWrapper WithExpression(ExpressionSyntax expression) + { + return new CommonForEachStatementSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + } + + public CommonForEachStatementSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new CommonForEachStatementSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + + public CommonForEachStatementSyntaxWrapper WithStatement(StatementSyntax statement) + { + return new CommonForEachStatementSyntaxWrapper(WithStatementAccessor(this.SyntaxNode, statement)); + } + + internal static CommonForEachStatementSyntaxWrapper FromUpcast(StatementSyntax node) + { + return new CommonForEachStatementSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ConstantPatternSyntaxWrapper.g.cs similarity index 81% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ConstantPatternSyntaxWrapper.g.cs index 016223938b..b9edf71fbf 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ConstantPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ConstantPatternSyntaxWrapper.g.cs @@ -4,11 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct ConstantPatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct ConstantPatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ConstantPatternSyntax"; private static readonly Type WrappedType; @@ -20,7 +21,7 @@ internal struct ConstantPatternSyntaxWrapper : ISyntaxWrapper static ConstantPatternSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(ConstantPatternSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ConstantPatternSyntaxWrapper)); ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); } @@ -45,6 +46,11 @@ public static explicit operator ConstantPatternSyntaxWrapper(PatternSyntaxWrappe return (ConstantPatternSyntaxWrapper)node.SyntaxNode; } + public static explicit operator ConstantPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (ConstantPatternSyntaxWrapper)node.SyntaxNode; + } + public static explicit operator ConstantPatternSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -65,6 +71,11 @@ public static implicit operator PatternSyntaxWrapper(ConstantPatternSyntaxWrappe return PatternSyntaxWrapper.FromUpcast(wrapper.node); } + public static implicit operator ExpressionOrPatternSyntaxWrapper(ConstantPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + public static implicit operator CSharpSyntaxNode(ConstantPatternSyntaxWrapper wrapper) { return wrapper.node; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationExpressionSyntaxWrapper.g.cs similarity index 91% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationExpressionSyntaxWrapper.g.cs index 5e5dc7ebbd..a5feafe03a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationExpressionSyntaxWrapper.g.cs @@ -4,11 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct DeclarationExpressionSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct DeclarationExpressionSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationExpressionSyntax"; private static readonly Type WrappedType; @@ -22,7 +23,7 @@ internal struct DeclarationExpressionSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(Type)); DesignationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Designation)); WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); @@ -84,7 +85,7 @@ public DeclarationExpressionSyntaxWrapper WithType(TypeSyntax type) public DeclarationExpressionSyntaxWrapper WithDesignation(VariableDesignationSyntaxWrapper designation) { - return new DeclarationExpressionSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation.SyntaxNode)); + return new DeclarationExpressionSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationPatternSyntaxWrapper.g.cs similarity index 83% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationPatternSyntaxWrapper.g.cs index 0d4a76ff93..f0dee0a3e3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DeclarationPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DeclarationPatternSyntaxWrapper.g.cs @@ -4,11 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct DeclarationPatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct DeclarationPatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationPatternSyntax"; private static readonly Type WrappedType; @@ -22,7 +23,7 @@ internal struct DeclarationPatternSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(Type)); DesignationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Designation)); WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); @@ -57,6 +58,11 @@ public static explicit operator DeclarationPatternSyntaxWrapper(PatternSyntaxWra return (DeclarationPatternSyntaxWrapper)node.SyntaxNode; } + public static explicit operator DeclarationPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (DeclarationPatternSyntaxWrapper)node.SyntaxNode; + } + public static explicit operator DeclarationPatternSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -77,6 +83,11 @@ public static implicit operator PatternSyntaxWrapper(DeclarationPatternSyntaxWra return PatternSyntaxWrapper.FromUpcast(wrapper.node); } + public static implicit operator ExpressionOrPatternSyntaxWrapper(DeclarationPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + public static implicit operator CSharpSyntaxNode(DeclarationPatternSyntaxWrapper wrapper) { return wrapper.node; @@ -94,7 +105,7 @@ public DeclarationPatternSyntaxWrapper WithType(TypeSyntax type) public DeclarationPatternSyntaxWrapper WithDesignation(VariableDesignationSyntaxWrapper designation) { - return new DeclarationPatternSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation.SyntaxNode)); + return new DeclarationPatternSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DefaultConstraintSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DefaultConstraintSyntaxWrapper.g.cs new file mode 100644 index 0000000000..905714e838 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DefaultConstraintSyntaxWrapper.g.cs @@ -0,0 +1,74 @@ +// 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 DefaultConstraintSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.DefaultConstraintSyntax"; + private static readonly Type WrappedType; + + private static readonly Func DefaultKeywordAccessor; + private static readonly Func WithDefaultKeywordAccessor; + + private readonly TypeParameterConstraintSyntax node; + + static DefaultConstraintSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(DefaultConstraintSyntaxWrapper)); + DefaultKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(DefaultKeyword)); + WithDefaultKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(DefaultKeyword)); + } + + private DefaultConstraintSyntaxWrapper(TypeParameterConstraintSyntax node) + { + this.node = node; + } + + public TypeParameterConstraintSyntax SyntaxNode => this.node; + + public SyntaxToken DefaultKeyword + { + get + { + return DefaultKeywordAccessor(this.SyntaxNode); + } + } + + public static explicit operator DefaultConstraintSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new DefaultConstraintSyntaxWrapper((TypeParameterConstraintSyntax)node); + } + + public static implicit operator TypeParameterConstraintSyntax(DefaultConstraintSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public DefaultConstraintSyntaxWrapper WithDefaultKeyword(SyntaxToken defaultKeyword) + { + return new DefaultConstraintSyntaxWrapper(WithDefaultKeywordAccessor(this.SyntaxNode, defaultKeyword)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardDesignationSyntaxWrapper.g.cs similarity index 88% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardDesignationSyntaxWrapper.g.cs index 5b892aa2e4..c2a8eb70bb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardDesignationSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct DiscardDesignationSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct DiscardDesignationSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.DiscardDesignationSyntax"; private static readonly Type WrappedType; @@ -19,7 +21,7 @@ internal struct DiscardDesignationSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(UnderscoreToken)); WithUnderscoreTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(UnderscoreToken)); } @@ -74,9 +76,9 @@ public static bool IsInstance(SyntaxNode node) return node != null && LightupHelpers.CanWrapNode(node, WrappedType); } - public DiscardDesignationSyntaxWrapper WithUnderscoreToken(SyntaxToken identifier) + public DiscardDesignationSyntaxWrapper WithUnderscoreToken(SyntaxToken underscoreToken) { - return new DiscardDesignationSyntaxWrapper(WithUnderscoreTokenAccessor(this.SyntaxNode, identifier)); + return new DiscardDesignationSyntaxWrapper(WithUnderscoreTokenAccessor(this.SyntaxNode, underscoreToken)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardPatternSyntaxWrapper.g.cs similarity index 78% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardPatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardPatternSyntaxWrapper.g.cs index c05388c5e3..992c06ae67 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/DiscardPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/DiscardPatternSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct DiscardPatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct DiscardPatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.DiscardPatternSyntax"; private static readonly Type WrappedType; @@ -19,7 +21,7 @@ internal struct DiscardPatternSyntaxWrapper : ISyntaxWrapper static DiscardPatternSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(DiscardPatternSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(DiscardPatternSyntaxWrapper)); UnderscoreTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(UnderscoreToken)); WithUnderscoreTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(UnderscoreToken)); } @@ -44,6 +46,11 @@ public static explicit operator DiscardPatternSyntaxWrapper(PatternSyntaxWrapper return (DiscardPatternSyntaxWrapper)node.SyntaxNode; } + public static explicit operator DiscardPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (DiscardPatternSyntaxWrapper)node.SyntaxNode; + } + public static explicit operator DiscardPatternSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -64,6 +71,11 @@ public static implicit operator PatternSyntaxWrapper(DiscardPatternSyntaxWrapper return PatternSyntaxWrapper.FromUpcast(wrapper.node); } + public static implicit operator ExpressionOrPatternSyntaxWrapper(DiscardPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + public static implicit operator CSharpSyntaxNode(DiscardPatternSyntaxWrapper wrapper) { return wrapper.node; @@ -74,9 +86,9 @@ public static bool IsInstance(SyntaxNode node) return node != null && LightupHelpers.CanWrapNode(node, WrappedType); } - public DiscardPatternSyntaxWrapper WithUnderscoreToken(SyntaxToken identifier) + public DiscardPatternSyntaxWrapper WithUnderscoreToken(SyntaxToken underscoreToken) { - return new DiscardPatternSyntaxWrapper(WithUnderscoreTokenAccessor(this.SyntaxNode, identifier)); + return new DiscardPatternSyntaxWrapper(WithUnderscoreTokenAccessor(this.SyntaxNode, underscoreToken)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionOrPatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionOrPatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..5c4ae69d79 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ExpressionOrPatternSyntaxWrapper.g.cs @@ -0,0 +1,61 @@ +// 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 ExpressionOrPatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionOrPatternSyntax"; + private static readonly Type WrappedType; + + private readonly CSharpSyntaxNode node; + + static ExpressionOrPatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ExpressionOrPatternSyntaxWrapper)); + } + + private ExpressionOrPatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public static explicit operator ExpressionOrPatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ExpressionOrPatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(ExpressionOrPatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + internal static ExpressionOrPatternSyntaxWrapper FromUpcast(CSharpSyntaxNode node) + { + return new ExpressionOrPatternSyntaxWrapper(node); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ForEachVariableStatementSyntaxWrapper.g.cs similarity index 88% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ForEachVariableStatementSyntaxWrapper.g.cs index 5a9b76af71..49c71ed604 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ForEachVariableStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ForEachVariableStatementSyntaxWrapper.g.cs @@ -4,16 +4,18 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct ForEachVariableStatementSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct ForEachVariableStatementSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ForEachVariableStatementSyntax"; private static readonly Type WrappedType; private static readonly Func VariableAccessor; - + private static readonly Func, StatementSyntax> WithAttributeListsAccessor; private static readonly Func WithAwaitKeywordAccessor; private static readonly Func WithForEachKeywordAccessor; private static readonly Func WithOpenParenTokenAccessor; @@ -27,9 +29,9 @@ internal struct ForEachVariableStatementSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(Variable)); - + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); WithAwaitKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(AwaitKeyword)); WithForEachKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ForEachKeyword)); WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); @@ -47,6 +49,14 @@ private ForEachVariableStatementSyntaxWrapper(StatementSyntax node) public StatementSyntax SyntaxNode => this.node; + public SyntaxList AttributeLists + { + get + { + return this.SyntaxNode.AttributeLists(); + } + } + public SyntaxToken AwaitKeyword { get @@ -146,6 +156,11 @@ public static bool IsInstance(SyntaxNode node) return node != null && LightupHelpers.CanWrapNode(node, WrappedType); } + public ForEachVariableStatementSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new ForEachVariableStatementSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + public ForEachVariableStatementSyntaxWrapper WithAwaitKeyword(SyntaxToken awaitKeyword) { return new ForEachVariableStatementSyntaxWrapper(WithAwaitKeywordAccessor(this.SyntaxNode, awaitKeyword)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerCallingConventionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerCallingConventionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..99b4ba222c --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerCallingConventionSyntaxWrapper.g.cs @@ -0,0 +1,91 @@ +// 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 FunctionPointerCallingConventionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerCallingConventionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func ManagedOrUnmanagedKeywordAccessor; + private static readonly Func UnmanagedCallingConventionListAccessor; + private static readonly Func WithManagedOrUnmanagedKeywordAccessor; + private static readonly Func WithUnmanagedCallingConventionListAccessor; + + private readonly CSharpSyntaxNode node; + + static FunctionPointerCallingConventionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerCallingConventionSyntaxWrapper)); + ManagedOrUnmanagedKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ManagedOrUnmanagedKeyword)); + UnmanagedCallingConventionListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(UnmanagedCallingConventionList)); + WithManagedOrUnmanagedKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ManagedOrUnmanagedKeyword)); + WithUnmanagedCallingConventionListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(UnmanagedCallingConventionList)); + } + + private FunctionPointerCallingConventionSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken ManagedOrUnmanagedKeyword + { + get + { + return ManagedOrUnmanagedKeywordAccessor(this.SyntaxNode); + } + } + + public FunctionPointerUnmanagedCallingConventionListSyntaxWrapper UnmanagedCallingConventionList + { + get + { + return (FunctionPointerUnmanagedCallingConventionListSyntaxWrapper)UnmanagedCallingConventionListAccessor(this.SyntaxNode); + } + } + + public static explicit operator FunctionPointerCallingConventionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerCallingConventionSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(FunctionPointerCallingConventionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerCallingConventionSyntaxWrapper WithManagedOrUnmanagedKeyword(SyntaxToken managedOrUnmanagedKeyword) + { + return new FunctionPointerCallingConventionSyntaxWrapper(WithManagedOrUnmanagedKeywordAccessor(this.SyntaxNode, managedOrUnmanagedKeyword)); + } + + public FunctionPointerCallingConventionSyntaxWrapper WithUnmanagedCallingConventionList(FunctionPointerUnmanagedCallingConventionListSyntaxWrapper unmanagedCallingConventionList) + { + return new FunctionPointerCallingConventionSyntaxWrapper(WithUnmanagedCallingConventionListAccessor(this.SyntaxNode, unmanagedCallingConventionList)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterListSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterListSyntaxWrapper.g.cs new file mode 100644 index 0000000000..f20723c867 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterListSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 FunctionPointerParameterListSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerParameterListSyntax"; + private static readonly Type WrappedType; + + private static readonly Func LessThanTokenAccessor; + private static readonly Func> ParametersAccessor; + private static readonly Func GreaterThanTokenAccessor; + private static readonly Func WithLessThanTokenAccessor; + private static readonly Func, CSharpSyntaxNode> WithParametersAccessor; + private static readonly Func WithGreaterThanTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static FunctionPointerParameterListSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerParameterListSyntaxWrapper)); + LessThanTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(LessThanToken)); + ParametersAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Parameters)); + GreaterThanTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(GreaterThanToken)); + WithLessThanTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(LessThanToken)); + WithParametersAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Parameters)); + WithGreaterThanTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(GreaterThanToken)); + } + + private FunctionPointerParameterListSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken LessThanToken + { + get + { + return LessThanTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Parameters + { + get + { + return ParametersAccessor(this.SyntaxNode); + } + } + + public SyntaxToken GreaterThanToken + { + get + { + return GreaterThanTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator FunctionPointerParameterListSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerParameterListSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(FunctionPointerParameterListSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerParameterListSyntaxWrapper WithLessThanToken(SyntaxToken lessThanToken) + { + return new FunctionPointerParameterListSyntaxWrapper(WithLessThanTokenAccessor(this.SyntaxNode, lessThanToken)); + } + + public FunctionPointerParameterListSyntaxWrapper WithParameters(SeparatedSyntaxListWrapper parameters) + { + return new FunctionPointerParameterListSyntaxWrapper(WithParametersAccessor(this.SyntaxNode, parameters)); + } + + public FunctionPointerParameterListSyntaxWrapper WithGreaterThanToken(SyntaxToken greaterThanToken) + { + return new FunctionPointerParameterListSyntaxWrapper(WithGreaterThanTokenAccessor(this.SyntaxNode, greaterThanToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterSyntaxWrapper.g.cs new file mode 100644 index 0000000000..46968ca701 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerParameterSyntaxWrapper.g.cs @@ -0,0 +1,111 @@ +// 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 FunctionPointerParameterSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerParameterSyntax"; + private static readonly Type WrappedType; + private static readonly Func, CSharpSyntaxNode> WithAttributeListsAccessor; + private static readonly Func WithModifiersAccessor; + private static readonly Func WithTypeAccessor; + + private readonly CSharpSyntaxNode node; + + static FunctionPointerParameterSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerParameterSyntaxWrapper)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); + WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + } + + private FunctionPointerParameterSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxList AttributeLists + { + get + { + return ((BaseParameterSyntaxWrapper)this).AttributeLists; + } + } + + public SyntaxTokenList Modifiers + { + get + { + return ((BaseParameterSyntaxWrapper)this).Modifiers; + } + } + + public TypeSyntax Type + { + get + { + return ((BaseParameterSyntaxWrapper)this).Type; + } + } + + public static explicit operator FunctionPointerParameterSyntaxWrapper(BaseParameterSyntaxWrapper node) + { + return (FunctionPointerParameterSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator FunctionPointerParameterSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerParameterSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator BaseParameterSyntaxWrapper(FunctionPointerParameterSyntaxWrapper wrapper) + { + return BaseParameterSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(FunctionPointerParameterSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerParameterSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new FunctionPointerParameterSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + + public FunctionPointerParameterSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) + { + return new FunctionPointerParameterSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); + } + + public FunctionPointerParameterSyntaxWrapper WithType(TypeSyntax type) + { + return new FunctionPointerParameterSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerTypeSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerTypeSyntaxWrapper.g.cs new file mode 100644 index 0000000000..5d1cb86b55 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerTypeSyntaxWrapper.g.cs @@ -0,0 +1,125 @@ +// 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 FunctionPointerTypeSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerTypeSyntax"; + private static readonly Type WrappedType; + + private static readonly Func DelegateKeywordAccessor; + private static readonly Func AsteriskTokenAccessor; + private static readonly Func CallingConventionAccessor; + private static readonly Func ParameterListAccessor; + private static readonly Func WithDelegateKeywordAccessor; + private static readonly Func WithAsteriskTokenAccessor; + private static readonly Func WithCallingConventionAccessor; + private static readonly Func WithParameterListAccessor; + + private readonly TypeSyntax node; + + static FunctionPointerTypeSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerTypeSyntaxWrapper)); + DelegateKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(DelegateKeyword)); + AsteriskTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(AsteriskToken)); + CallingConventionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CallingConvention)); + ParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ParameterList)); + WithDelegateKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(DelegateKeyword)); + WithAsteriskTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(AsteriskToken)); + WithCallingConventionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CallingConvention)); + WithParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ParameterList)); + } + + private FunctionPointerTypeSyntaxWrapper(TypeSyntax node) + { + this.node = node; + } + + public TypeSyntax SyntaxNode => this.node; + + public SyntaxToken DelegateKeyword + { + get + { + return DelegateKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken AsteriskToken + { + get + { + return AsteriskTokenAccessor(this.SyntaxNode); + } + } + + public FunctionPointerCallingConventionSyntaxWrapper CallingConvention + { + get + { + return (FunctionPointerCallingConventionSyntaxWrapper)CallingConventionAccessor(this.SyntaxNode); + } + } + + public FunctionPointerParameterListSyntaxWrapper ParameterList + { + get + { + return (FunctionPointerParameterListSyntaxWrapper)ParameterListAccessor(this.SyntaxNode); + } + } + + public static explicit operator FunctionPointerTypeSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerTypeSyntaxWrapper((TypeSyntax)node); + } + + public static implicit operator TypeSyntax(FunctionPointerTypeSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerTypeSyntaxWrapper WithDelegateKeyword(SyntaxToken delegateKeyword) + { + return new FunctionPointerTypeSyntaxWrapper(WithDelegateKeywordAccessor(this.SyntaxNode, delegateKeyword)); + } + + public FunctionPointerTypeSyntaxWrapper WithAsteriskToken(SyntaxToken asteriskToken) + { + return new FunctionPointerTypeSyntaxWrapper(WithAsteriskTokenAccessor(this.SyntaxNode, asteriskToken)); + } + + public FunctionPointerTypeSyntaxWrapper WithCallingConvention(FunctionPointerCallingConventionSyntaxWrapper callingConvention) + { + return new FunctionPointerTypeSyntaxWrapper(WithCallingConventionAccessor(this.SyntaxNode, callingConvention)); + } + + public FunctionPointerTypeSyntaxWrapper WithParameterList(FunctionPointerParameterListSyntaxWrapper parameterList) + { + return new FunctionPointerTypeSyntaxWrapper(WithParameterListAccessor(this.SyntaxNode, parameterList)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs new file mode 100644 index 0000000000..d4660617e3 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 FunctionPointerUnmanagedCallingConventionListSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerUnmanagedCallingConventionListSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenBracketTokenAccessor; + private static readonly Func> CallingConventionsAccessor; + private static readonly Func CloseBracketTokenAccessor; + private static readonly Func WithOpenBracketTokenAccessor; + private static readonly Func, CSharpSyntaxNode> WithCallingConventionsAccessor; + private static readonly Func WithCloseBracketTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static FunctionPointerUnmanagedCallingConventionListSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerUnmanagedCallingConventionListSyntaxWrapper)); + OpenBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBracketToken)); + CallingConventionsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(CallingConventions)); + CloseBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBracketToken)); + WithOpenBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBracketToken)); + WithCallingConventionsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(CallingConventions)); + WithCloseBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBracketToken)); + } + + private FunctionPointerUnmanagedCallingConventionListSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenBracketToken + { + get + { + return OpenBracketTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper CallingConventions + { + get + { + return CallingConventionsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseBracketToken + { + get + { + return CloseBracketTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator FunctionPointerUnmanagedCallingConventionListSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerUnmanagedCallingConventionListSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(FunctionPointerUnmanagedCallingConventionListSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerUnmanagedCallingConventionListSyntaxWrapper WithOpenBracketToken(SyntaxToken openBracketToken) + { + return new FunctionPointerUnmanagedCallingConventionListSyntaxWrapper(WithOpenBracketTokenAccessor(this.SyntaxNode, openBracketToken)); + } + + public FunctionPointerUnmanagedCallingConventionListSyntaxWrapper WithCallingConventions(SeparatedSyntaxListWrapper callingConventions) + { + return new FunctionPointerUnmanagedCallingConventionListSyntaxWrapper(WithCallingConventionsAccessor(this.SyntaxNode, callingConventions)); + } + + public FunctionPointerUnmanagedCallingConventionListSyntaxWrapper WithCloseBracketToken(SyntaxToken closeBracketToken) + { + return new FunctionPointerUnmanagedCallingConventionListSyntaxWrapper(WithCloseBracketTokenAccessor(this.SyntaxNode, closeBracketToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..da6a24f7fe --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/FunctionPointerUnmanagedCallingConventionSyntaxWrapper.g.cs @@ -0,0 +1,74 @@ +// 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 FunctionPointerUnmanagedCallingConventionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.FunctionPointerUnmanagedCallingConventionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func NameAccessor; + private static readonly Func WithNameAccessor; + + private readonly CSharpSyntaxNode node; + + static FunctionPointerUnmanagedCallingConventionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(FunctionPointerUnmanagedCallingConventionSyntaxWrapper)); + NameAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Name)); + WithNameAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Name)); + } + + private FunctionPointerUnmanagedCallingConventionSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken Name + { + get + { + return NameAccessor(this.SyntaxNode); + } + } + + public static explicit operator FunctionPointerUnmanagedCallingConventionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new FunctionPointerUnmanagedCallingConventionSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(FunctionPointerUnmanagedCallingConventionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public FunctionPointerUnmanagedCallingConventionSyntaxWrapper WithName(SyntaxToken name) + { + return new FunctionPointerUnmanagedCallingConventionSyntaxWrapper(WithNameAccessor(this.SyntaxNode, name)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitObjectCreationExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitObjectCreationExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..a5c2dab625 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitObjectCreationExpressionSyntaxWrapper.g.cs @@ -0,0 +1,111 @@ +// 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 ImplicitObjectCreationExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax"; + private static readonly Type WrappedType; + private static readonly Func WithNewKeywordAccessor; + private static readonly Func WithArgumentListAccessor; + private static readonly Func WithInitializerAccessor; + + private readonly ExpressionSyntax node; + + static ImplicitObjectCreationExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ImplicitObjectCreationExpressionSyntaxWrapper)); + WithNewKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NewKeyword)); + WithArgumentListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ArgumentList)); + WithInitializerAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Initializer)); + } + + private ImplicitObjectCreationExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public SyntaxToken NewKeyword + { + get + { + return ((BaseObjectCreationExpressionSyntaxWrapper)this).NewKeyword; + } + } + + public ArgumentListSyntax ArgumentList + { + get + { + return ((BaseObjectCreationExpressionSyntaxWrapper)this).ArgumentList; + } + } + + public InitializerExpressionSyntax Initializer + { + get + { + return ((BaseObjectCreationExpressionSyntaxWrapper)this).Initializer; + } + } + + public static explicit operator ImplicitObjectCreationExpressionSyntaxWrapper(BaseObjectCreationExpressionSyntaxWrapper node) + { + return (ImplicitObjectCreationExpressionSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator ImplicitObjectCreationExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ImplicitObjectCreationExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator BaseObjectCreationExpressionSyntaxWrapper(ImplicitObjectCreationExpressionSyntaxWrapper wrapper) + { + return BaseObjectCreationExpressionSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionSyntax(ImplicitObjectCreationExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public ImplicitObjectCreationExpressionSyntaxWrapper WithNewKeyword(SyntaxToken newKeyword) + { + return new ImplicitObjectCreationExpressionSyntaxWrapper(WithNewKeywordAccessor(this.SyntaxNode, newKeyword)); + } + + public ImplicitObjectCreationExpressionSyntaxWrapper WithArgumentList(ArgumentListSyntax argumentList) + { + return new ImplicitObjectCreationExpressionSyntaxWrapper(WithArgumentListAccessor(this.SyntaxNode, argumentList)); + } + + public ImplicitObjectCreationExpressionSyntaxWrapper WithInitializer(InitializerExpressionSyntax initializer) + { + return new ImplicitObjectCreationExpressionSyntaxWrapper(WithInitializerAccessor(this.SyntaxNode, initializer)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..0cdf569f2b --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.g.cs @@ -0,0 +1,125 @@ +// 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 ImplicitStackAllocArrayCreationExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitStackAllocArrayCreationExpressionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func StackAllocKeywordAccessor; + private static readonly Func OpenBracketTokenAccessor; + private static readonly Func CloseBracketTokenAccessor; + private static readonly Func InitializerAccessor; + private static readonly Func WithStackAllocKeywordAccessor; + private static readonly Func WithOpenBracketTokenAccessor; + private static readonly Func WithCloseBracketTokenAccessor; + private static readonly Func WithInitializerAccessor; + + private readonly ExpressionSyntax node; + + static ImplicitStackAllocArrayCreationExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper)); + StackAllocKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(StackAllocKeyword)); + OpenBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBracketToken)); + CloseBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBracketToken)); + InitializerAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Initializer)); + WithStackAllocKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(StackAllocKeyword)); + WithOpenBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBracketToken)); + WithCloseBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBracketToken)); + WithInitializerAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Initializer)); + } + + private ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public SyntaxToken StackAllocKeyword + { + get + { + return StackAllocKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken OpenBracketToken + { + get + { + return OpenBracketTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseBracketToken + { + get + { + return CloseBracketTokenAccessor(this.SyntaxNode); + } + } + + public InitializerExpressionSyntax Initializer + { + get + { + return InitializerAccessor(this.SyntaxNode); + } + } + + public static explicit operator ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator ExpressionSyntax(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithStackAllocKeyword(SyntaxToken stackAllocKeyword) + { + return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithStackAllocKeywordAccessor(this.SyntaxNode, stackAllocKeyword)); + } + + public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithOpenBracketToken(SyntaxToken openBracketToken) + { + return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithOpenBracketTokenAccessor(this.SyntaxNode, openBracketToken)); + } + + public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithCloseBracketToken(SyntaxToken closeBracketToken) + { + return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithCloseBracketTokenAccessor(this.SyntaxNode, closeBracketToken)); + } + + public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithInitializer(InitializerExpressionSyntax initializer) + { + return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithInitializerAccessor(this.SyntaxNode, initializer)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/IsPatternExpressionSyntaxWrapper.g.cs similarity index 93% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/IsPatternExpressionSyntaxWrapper.g.cs index 9012268d7e..d71a757a35 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/IsPatternExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/IsPatternExpressionSyntaxWrapper.g.cs @@ -4,11 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct IsPatternExpressionSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct IsPatternExpressionSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax"; private static readonly Type WrappedType; @@ -24,7 +25,7 @@ internal struct IsPatternExpressionSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(Expression)); IsKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(IsKeyword)); PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); @@ -101,7 +102,7 @@ public IsPatternExpressionSyntaxWrapper WithIsKeyword(SyntaxToken isKeyword) public IsPatternExpressionSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) { - return new IsPatternExpressionSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern.SyntaxNode)); + return new IsPatternExpressionSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LocalFunctionStatementSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LocalFunctionStatementSyntaxWrapper.g.cs new file mode 100644 index 0000000000..e1940b11cc --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/LocalFunctionStatementSyntaxWrapper.g.cs @@ -0,0 +1,225 @@ +// 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 LocalFunctionStatementSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.LocalFunctionStatementSyntax"; + private static readonly Type WrappedType; + + private static readonly Func ModifiersAccessor; + private static readonly Func ReturnTypeAccessor; + private static readonly Func IdentifierAccessor; + private static readonly Func TypeParameterListAccessor; + private static readonly Func ParameterListAccessor; + private static readonly Func> ConstraintClausesAccessor; + private static readonly Func BodyAccessor; + private static readonly Func ExpressionBodyAccessor; + private static readonly Func SemicolonTokenAccessor; + private static readonly Func, StatementSyntax> WithAttributeListsAccessor; + private static readonly Func WithModifiersAccessor; + private static readonly Func WithReturnTypeAccessor; + private static readonly Func WithIdentifierAccessor; + private static readonly Func WithTypeParameterListAccessor; + private static readonly Func WithParameterListAccessor; + private static readonly Func, StatementSyntax> WithConstraintClausesAccessor; + private static readonly Func WithBodyAccessor; + private static readonly Func WithExpressionBodyAccessor; + private static readonly Func WithSemicolonTokenAccessor; + + private readonly StatementSyntax node; + + static LocalFunctionStatementSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(LocalFunctionStatementSyntaxWrapper)); + ModifiersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Modifiers)); + ReturnTypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ReturnType)); + IdentifierAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Identifier)); + TypeParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(TypeParameterList)); + ParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ParameterList)); + ConstraintClausesAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(ConstraintClauses)); + BodyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Body)); + ExpressionBodyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ExpressionBody)); + SemicolonTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SemicolonToken)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); + WithReturnTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ReturnType)); + WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); + WithTypeParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(TypeParameterList)); + WithParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ParameterList)); + WithConstraintClausesAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(ConstraintClauses)); + WithBodyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Body)); + WithExpressionBodyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ExpressionBody)); + WithSemicolonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SemicolonToken)); + } + + private LocalFunctionStatementSyntaxWrapper(StatementSyntax node) + { + this.node = node; + } + + public StatementSyntax SyntaxNode => this.node; + + public SyntaxList AttributeLists + { + get + { + return this.SyntaxNode.AttributeLists(); + } + } + + public SyntaxTokenList Modifiers + { + get + { + return ModifiersAccessor(this.SyntaxNode); + } + } + + public TypeSyntax ReturnType + { + get + { + return ReturnTypeAccessor(this.SyntaxNode); + } + } + + public SyntaxToken Identifier + { + get + { + return IdentifierAccessor(this.SyntaxNode); + } + } + + public TypeParameterListSyntax TypeParameterList + { + get + { + return TypeParameterListAccessor(this.SyntaxNode); + } + } + + public ParameterListSyntax ParameterList + { + get + { + return ParameterListAccessor(this.SyntaxNode); + } + } + + public SyntaxList ConstraintClauses + { + get + { + return ConstraintClausesAccessor(this.SyntaxNode); + } + } + + public BlockSyntax Body + { + get + { + return BodyAccessor(this.SyntaxNode); + } + } + + public ArrowExpressionClauseSyntax ExpressionBody + { + get + { + return ExpressionBodyAccessor(this.SyntaxNode); + } + } + + public SyntaxToken SemicolonToken + { + get + { + return SemicolonTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator LocalFunctionStatementSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new LocalFunctionStatementSyntaxWrapper((StatementSyntax)node); + } + + public static implicit operator StatementSyntax(LocalFunctionStatementSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public LocalFunctionStatementSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new LocalFunctionStatementSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + + public LocalFunctionStatementSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) + { + return new LocalFunctionStatementSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); + } + + public LocalFunctionStatementSyntaxWrapper WithReturnType(TypeSyntax returnType) + { + return new LocalFunctionStatementSyntaxWrapper(WithReturnTypeAccessor(this.SyntaxNode, returnType)); + } + + public LocalFunctionStatementSyntaxWrapper WithIdentifier(SyntaxToken identifier) + { + return new LocalFunctionStatementSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); + } + + public LocalFunctionStatementSyntaxWrapper WithTypeParameterList(TypeParameterListSyntax typeParameterList) + { + return new LocalFunctionStatementSyntaxWrapper(WithTypeParameterListAccessor(this.SyntaxNode, typeParameterList)); + } + + public LocalFunctionStatementSyntaxWrapper WithParameterList(ParameterListSyntax parameterList) + { + return new LocalFunctionStatementSyntaxWrapper(WithParameterListAccessor(this.SyntaxNode, parameterList)); + } + + public LocalFunctionStatementSyntaxWrapper WithConstraintClauses(SyntaxList constraintClauses) + { + return new LocalFunctionStatementSyntaxWrapper(WithConstraintClausesAccessor(this.SyntaxNode, constraintClauses)); + } + + public LocalFunctionStatementSyntaxWrapper WithBody(BlockSyntax body) + { + return new LocalFunctionStatementSyntaxWrapper(WithBodyAccessor(this.SyntaxNode, body)); + } + + public LocalFunctionStatementSyntaxWrapper WithExpressionBody(ArrowExpressionClauseSyntax expressionBody) + { + return new LocalFunctionStatementSyntaxWrapper(WithExpressionBodyAccessor(this.SyntaxNode, expressionBody)); + } + + public LocalFunctionStatementSyntaxWrapper WithSemicolonToken(SyntaxToken semicolonToken) + { + return new LocalFunctionStatementSyntaxWrapper(WithSemicolonTokenAccessor(this.SyntaxNode, semicolonToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/NullableDirectiveTriviaSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/NullableDirectiveTriviaSyntaxWrapper.g.cs new file mode 100644 index 0000000000..5c6bfd9d7e --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/NullableDirectiveTriviaSyntaxWrapper.g.cs @@ -0,0 +1,153 @@ +// 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 NullableDirectiveTriviaSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.NullableDirectiveTriviaSyntax"; + private static readonly Type WrappedType; + + private static readonly Func NullableKeywordAccessor; + private static readonly Func SettingTokenAccessor; + private static readonly Func TargetTokenAccessor; + private static readonly Func WithHashTokenAccessor; + private static readonly Func WithNullableKeywordAccessor; + private static readonly Func WithSettingTokenAccessor; + private static readonly Func WithTargetTokenAccessor; + private static readonly Func WithEndOfDirectiveTokenAccessor; + private static readonly Func WithIsActiveAccessor; + + private readonly DirectiveTriviaSyntax node; + + static NullableDirectiveTriviaSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(NullableDirectiveTriviaSyntaxWrapper)); + NullableKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(NullableKeyword)); + SettingTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SettingToken)); + TargetTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(TargetToken)); + WithHashTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(HashToken)); + WithNullableKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NullableKeyword)); + WithSettingTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SettingToken)); + WithTargetTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(TargetToken)); + WithEndOfDirectiveTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(EndOfDirectiveToken)); + WithIsActiveAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(IsActive)); + } + + private NullableDirectiveTriviaSyntaxWrapper(DirectiveTriviaSyntax node) + { + this.node = node; + } + + public DirectiveTriviaSyntax SyntaxNode => this.node; + + public SyntaxToken HashToken + { + get + { + return this.SyntaxNode.HashToken; + } + } + + public SyntaxToken NullableKeyword + { + get + { + return NullableKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken SettingToken + { + get + { + return SettingTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken TargetToken + { + get + { + return TargetTokenAccessor(this.SyntaxNode); + } + } + + public SyntaxToken EndOfDirectiveToken + { + get + { + return this.SyntaxNode.EndOfDirectiveToken; + } + } + + public bool IsActive + { + get + { + return this.SyntaxNode.IsActive; + } + } + + public static explicit operator NullableDirectiveTriviaSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new NullableDirectiveTriviaSyntaxWrapper((DirectiveTriviaSyntax)node); + } + + public static implicit operator DirectiveTriviaSyntax(NullableDirectiveTriviaSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public NullableDirectiveTriviaSyntaxWrapper WithHashToken(SyntaxToken hashToken) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithHashTokenAccessor(this.SyntaxNode, hashToken)); + } + + public NullableDirectiveTriviaSyntaxWrapper WithNullableKeyword(SyntaxToken nullableKeyword) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithNullableKeywordAccessor(this.SyntaxNode, nullableKeyword)); + } + + public NullableDirectiveTriviaSyntaxWrapper WithSettingToken(SyntaxToken settingToken) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithSettingTokenAccessor(this.SyntaxNode, settingToken)); + } + + public NullableDirectiveTriviaSyntaxWrapper WithTargetToken(SyntaxToken targetToken) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithTargetTokenAccessor(this.SyntaxNode, targetToken)); + } + + public NullableDirectiveTriviaSyntaxWrapper WithEndOfDirectiveToken(SyntaxToken endOfDirectiveToken) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithEndOfDirectiveTokenAccessor(this.SyntaxNode, endOfDirectiveToken)); + } + + public NullableDirectiveTriviaSyntaxWrapper WithIsActive(bool isActive) + { + return new NullableDirectiveTriviaSyntaxWrapper(WithIsActiveAccessor(this.SyntaxNode, isActive)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedPatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedPatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..2ebc2af84f --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedPatternSyntaxWrapper.g.cs @@ -0,0 +1,128 @@ +// 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 ParenthesizedPatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedPatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func PatternAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func WithPatternAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static ParenthesizedPatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ParenthesizedPatternSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private ParenthesizedPatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public PatternSyntaxWrapper Pattern + { + get + { + return (PatternSyntaxWrapper)PatternAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator ParenthesizedPatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (ParenthesizedPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator ParenthesizedPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (ParenthesizedPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator ParenthesizedPatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ParenthesizedPatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(ParenthesizedPatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(ParenthesizedPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(ParenthesizedPatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public ParenthesizedPatternSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new ParenthesizedPatternSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public ParenthesizedPatternSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) + { + return new ParenthesizedPatternSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern)); + } + + public ParenthesizedPatternSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new ParenthesizedPatternSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedVariableDesignationSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedVariableDesignationSyntaxWrapper.g.cs new file mode 100644 index 0000000000..d0b4aff675 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ParenthesizedVariableDesignationSyntaxWrapper.g.cs @@ -0,0 +1,118 @@ +// 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 ParenthesizedVariableDesignationSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedVariableDesignationSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func> VariablesAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func, CSharpSyntaxNode> WithVariablesAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static ParenthesizedVariableDesignationSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ParenthesizedVariableDesignationSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + VariablesAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Variables)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithVariablesAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Variables)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private ParenthesizedVariableDesignationSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Variables + { + get + { + return VariablesAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator ParenthesizedVariableDesignationSyntaxWrapper(VariableDesignationSyntaxWrapper node) + { + return (ParenthesizedVariableDesignationSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator ParenthesizedVariableDesignationSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new ParenthesizedVariableDesignationSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator VariableDesignationSyntaxWrapper(ParenthesizedVariableDesignationSyntaxWrapper wrapper) + { + return VariableDesignationSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(ParenthesizedVariableDesignationSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public ParenthesizedVariableDesignationSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new ParenthesizedVariableDesignationSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public ParenthesizedVariableDesignationSyntaxWrapper WithVariables(SeparatedSyntaxListWrapper variables) + { + return new ParenthesizedVariableDesignationSyntaxWrapper(WithVariablesAccessor(this.SyntaxNode, variables)); + } + + public ParenthesizedVariableDesignationSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new ParenthesizedVariableDesignationSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PatternSyntaxWrapper.g.cs similarity index 71% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PatternSyntaxWrapper.g.cs index 48bb37822a..4b52b4bfe8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PatternSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct PatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct PatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax"; private static readonly Type WrappedType; @@ -16,7 +18,7 @@ internal struct PatternSyntaxWrapper : ISyntaxWrapper static PatternSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(PatternSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(PatternSyntaxWrapper)); } private PatternSyntaxWrapper(CSharpSyntaxNode node) @@ -26,6 +28,11 @@ private PatternSyntaxWrapper(CSharpSyntaxNode node) public CSharpSyntaxNode SyntaxNode => this.node; + public static explicit operator PatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (PatternSyntaxWrapper)node.SyntaxNode; + } + public static explicit operator PatternSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -41,6 +48,11 @@ public static explicit operator PatternSyntaxWrapper(SyntaxNode node) return new PatternSyntaxWrapper((CSharpSyntaxNode)node); } + public static implicit operator ExpressionOrPatternSyntaxWrapper(PatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + public static implicit operator CSharpSyntaxNode(PatternSyntaxWrapper wrapper) { return wrapper.node; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PositionalPatternClauseSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PositionalPatternClauseSyntaxWrapper.g.cs new file mode 100644 index 0000000000..d69bd45bfa --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PositionalPatternClauseSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 PositionalPatternClauseSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PositionalPatternClauseSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func> SubpatternsAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func, CSharpSyntaxNode> WithSubpatternsAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static PositionalPatternClauseSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(PositionalPatternClauseSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + SubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Subpatterns)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithSubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Subpatterns)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private PositionalPatternClauseSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Subpatterns + { + get + { + return SubpatternsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator PositionalPatternClauseSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new PositionalPatternClauseSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(PositionalPatternClauseSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public PositionalPatternClauseSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new PositionalPatternClauseSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public PositionalPatternClauseSyntaxWrapper WithSubpatterns(SeparatedSyntaxListWrapper subpatterns) + { + return new PositionalPatternClauseSyntaxWrapper(WithSubpatternsAccessor(this.SyntaxNode, subpatterns)); + } + + public PositionalPatternClauseSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new PositionalPatternClauseSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PrimaryConstructorBaseTypeSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PrimaryConstructorBaseTypeSyntaxWrapper.g.cs new file mode 100644 index 0000000000..5d04961fc9 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PrimaryConstructorBaseTypeSyntaxWrapper.g.cs @@ -0,0 +1,89 @@ +// 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 PrimaryConstructorBaseTypeSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PrimaryConstructorBaseTypeSyntax"; + private static readonly Type WrappedType; + + private static readonly Func ArgumentListAccessor; + private static readonly Func WithTypeAccessor; + private static readonly Func WithArgumentListAccessor; + + private readonly BaseTypeSyntax node; + + static PrimaryConstructorBaseTypeSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(PrimaryConstructorBaseTypeSyntaxWrapper)); + ArgumentListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ArgumentList)); + WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + WithArgumentListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ArgumentList)); + } + + private PrimaryConstructorBaseTypeSyntaxWrapper(BaseTypeSyntax node) + { + this.node = node; + } + + public BaseTypeSyntax SyntaxNode => this.node; + + public TypeSyntax Type + { + get + { + return this.SyntaxNode.Type; + } + } + + public ArgumentListSyntax ArgumentList + { + get + { + return ArgumentListAccessor(this.SyntaxNode); + } + } + + public static explicit operator PrimaryConstructorBaseTypeSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new PrimaryConstructorBaseTypeSyntaxWrapper((BaseTypeSyntax)node); + } + + public static implicit operator BaseTypeSyntax(PrimaryConstructorBaseTypeSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public PrimaryConstructorBaseTypeSyntaxWrapper WithType(TypeSyntax type) + { + return new PrimaryConstructorBaseTypeSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + } + + public PrimaryConstructorBaseTypeSyntaxWrapper WithArgumentList(ArgumentListSyntax argumentList) + { + return new PrimaryConstructorBaseTypeSyntaxWrapper(WithArgumentListAccessor(this.SyntaxNode, argumentList)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PropertyPatternClauseSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PropertyPatternClauseSyntaxWrapper.g.cs new file mode 100644 index 0000000000..7d27a3d08a --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/PropertyPatternClauseSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 PropertyPatternClauseSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PropertyPatternClauseSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenBraceTokenAccessor; + private static readonly Func> SubpatternsAccessor; + private static readonly Func CloseBraceTokenAccessor; + private static readonly Func WithOpenBraceTokenAccessor; + private static readonly Func, CSharpSyntaxNode> WithSubpatternsAccessor; + private static readonly Func WithCloseBraceTokenAccessor; + + private readonly CSharpSyntaxNode node; + + static PropertyPatternClauseSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(PropertyPatternClauseSyntaxWrapper)); + OpenBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBraceToken)); + SubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Subpatterns)); + CloseBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBraceToken)); + WithOpenBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBraceToken)); + WithSubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Subpatterns)); + WithCloseBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBraceToken)); + } + + private PropertyPatternClauseSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OpenBraceToken + { + get + { + return OpenBraceTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Subpatterns + { + get + { + return SubpatternsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseBraceToken + { + get + { + return CloseBraceTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator PropertyPatternClauseSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new PropertyPatternClauseSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator CSharpSyntaxNode(PropertyPatternClauseSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public PropertyPatternClauseSyntaxWrapper WithOpenBraceToken(SyntaxToken openBraceToken) + { + return new PropertyPatternClauseSyntaxWrapper(WithOpenBraceTokenAccessor(this.SyntaxNode, openBraceToken)); + } + + public PropertyPatternClauseSyntaxWrapper WithSubpatterns(SeparatedSyntaxListWrapper subpatterns) + { + return new PropertyPatternClauseSyntaxWrapper(WithSubpatternsAccessor(this.SyntaxNode, subpatterns)); + } + + public PropertyPatternClauseSyntaxWrapper WithCloseBraceToken(SyntaxToken closeBraceToken) + { + return new PropertyPatternClauseSyntaxWrapper(WithCloseBraceTokenAccessor(this.SyntaxNode, closeBraceToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RangeExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RangeExpressionSyntaxWrapper.g.cs similarity index 93% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RangeExpressionSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RangeExpressionSyntaxWrapper.g.cs index 32afcde4eb..97dd7d9311 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RangeExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RangeExpressionSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct RangeExpressionSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct RangeExpressionSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RangeExpressionSyntax"; private static readonly Type WrappedType; @@ -15,7 +17,6 @@ internal struct RangeExpressionSyntaxWrapper : ISyntaxWrapper private static readonly Func LeftOperandAccessor; private static readonly Func OperatorTokenAccessor; private static readonly Func RightOperandAccessor; - private static readonly Func WithLeftOperandAccessor; private static readonly Func WithOperatorTokenAccessor; private static readonly Func WithRightOperandAccessor; @@ -24,11 +25,10 @@ internal struct RangeExpressionSyntaxWrapper : ISyntaxWrapper static RangeExpressionSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(RangeExpressionSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RangeExpressionSyntaxWrapper)); LeftOperandAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(LeftOperand)); OperatorTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OperatorToken)); RightOperandAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(RightOperand)); - WithLeftOperandAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(LeftOperand)); WithOperatorTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OperatorToken)); WithRightOperandAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(RightOperand)); @@ -65,7 +65,7 @@ public ExpressionSyntax RightOperand } } - public static explicit operator RangeExpressionSyntaxWrapper(ExpressionSyntax node) + public static explicit operator RangeExpressionSyntaxWrapper(SyntaxNode node) { if (node == null) { 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 new file mode 100644 index 0000000000..bbcfc89a42 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecordDeclarationSyntaxWrapper.g.cs @@ -0,0 +1,239 @@ +// 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 RecordDeclarationSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RecordDeclarationSyntax"; + private static readonly Type WrappedType; + + 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 WithIdentifierAccessor; + private static readonly Func WithTypeParameterListAccessor; + private static readonly Func WithParameterListAccessor; + private static readonly Func WithBaseListAccessor; + private static readonly Func, TypeDeclarationSyntax> WithConstraintClausesAccessor; + private static readonly Func WithOpenBraceTokenAccessor; + private static readonly Func, TypeDeclarationSyntax> WithMembersAccessor; + private static readonly Func WithCloseBraceTokenAccessor; + private static readonly Func WithSemicolonTokenAccessor; + + private readonly TypeDeclarationSyntax node; + + static RecordDeclarationSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RecordDeclarationSyntaxWrapper)); + ParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ParameterList)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); + WithKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Keyword)); + WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); + WithTypeParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(TypeParameterList)); + WithParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ParameterList)); + WithBaseListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(BaseList)); + WithConstraintClausesAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(ConstraintClauses)); + WithOpenBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBraceToken)); + WithMembersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Members)); + WithCloseBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBraceToken)); + WithSemicolonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SemicolonToken)); + } + + private RecordDeclarationSyntaxWrapper(TypeDeclarationSyntax node) + { + this.node = node; + } + + public TypeDeclarationSyntax SyntaxNode => this.node; + + public SyntaxList AttributeLists + { + get + { + return this.SyntaxNode.AttributeLists(); + } + } + + public SyntaxTokenList Modifiers + { + get + { + return this.SyntaxNode.Modifiers(); + } + } + + public SyntaxToken Keyword + { + get + { + return this.SyntaxNode.Keyword; + } + } + + public SyntaxToken Identifier + { + get + { + return this.SyntaxNode.Identifier; + } + } + + public TypeParameterListSyntax TypeParameterList + { + get + { + return this.SyntaxNode.TypeParameterList; + } + } + + public ParameterListSyntax ParameterList + { + get + { + return ParameterListAccessor(this.SyntaxNode); + } + } + + public BaseListSyntax BaseList + { + get + { + return this.SyntaxNode.BaseList; + } + } + + public SyntaxList ConstraintClauses + { + get + { + return this.SyntaxNode.ConstraintClauses; + } + } + + public SyntaxToken OpenBraceToken + { + get + { + return this.SyntaxNode.OpenBraceToken; + } + } + + public SyntaxList Members + { + get + { + return this.SyntaxNode.Members; + } + } + + public SyntaxToken CloseBraceToken + { + get + { + return this.SyntaxNode.CloseBraceToken; + } + } + + public SyntaxToken SemicolonToken + { + get + { + return this.SyntaxNode.SemicolonToken; + } + } + + public static explicit operator RecordDeclarationSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new RecordDeclarationSyntaxWrapper((TypeDeclarationSyntax)node); + } + + public static implicit operator TypeDeclarationSyntax(RecordDeclarationSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public RecordDeclarationSyntaxWrapper WithAttributeLists(SyntaxList attributeLists) + { + return new RecordDeclarationSyntaxWrapper(WithAttributeListsAccessor(this.SyntaxNode, attributeLists)); + } + + public RecordDeclarationSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) + { + return new RecordDeclarationSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); + } + + public RecordDeclarationSyntaxWrapper WithKeyword(SyntaxToken keyword) + { + return new RecordDeclarationSyntaxWrapper(WithKeywordAccessor(this.SyntaxNode, keyword)); + } + + public RecordDeclarationSyntaxWrapper WithIdentifier(SyntaxToken identifier) + { + return new RecordDeclarationSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); + } + + public RecordDeclarationSyntaxWrapper WithTypeParameterList(TypeParameterListSyntax typeParameterList) + { + return new RecordDeclarationSyntaxWrapper(WithTypeParameterListAccessor(this.SyntaxNode, typeParameterList)); + } + + public RecordDeclarationSyntaxWrapper WithParameterList(ParameterListSyntax parameterList) + { + return new RecordDeclarationSyntaxWrapper(WithParameterListAccessor(this.SyntaxNode, parameterList)); + } + + public RecordDeclarationSyntaxWrapper WithBaseList(BaseListSyntax baseList) + { + return new RecordDeclarationSyntaxWrapper(WithBaseListAccessor(this.SyntaxNode, baseList)); + } + + public RecordDeclarationSyntaxWrapper WithConstraintClauses(SyntaxList constraintClauses) + { + return new RecordDeclarationSyntaxWrapper(WithConstraintClausesAccessor(this.SyntaxNode, constraintClauses)); + } + + public RecordDeclarationSyntaxWrapper WithOpenBraceToken(SyntaxToken openBraceToken) + { + return new RecordDeclarationSyntaxWrapper(WithOpenBraceTokenAccessor(this.SyntaxNode, openBraceToken)); + } + + public RecordDeclarationSyntaxWrapper WithMembers(SyntaxList members) + { + return new RecordDeclarationSyntaxWrapper(WithMembersAccessor(this.SyntaxNode, members)); + } + + public RecordDeclarationSyntaxWrapper WithCloseBraceToken(SyntaxToken closeBraceToken) + { + return new RecordDeclarationSyntaxWrapper(WithCloseBraceTokenAccessor(this.SyntaxNode, closeBraceToken)); + } + + public RecordDeclarationSyntaxWrapper WithSemicolonToken(SyntaxToken semicolonToken) + { + return new RecordDeclarationSyntaxWrapper(WithSemicolonTokenAccessor(this.SyntaxNode, semicolonToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecursivePatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecursivePatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..a805c3a82f --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RecursivePatternSyntaxWrapper.g.cs @@ -0,0 +1,145 @@ +// 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 RecursivePatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RecursivePatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func TypeAccessor; + private static readonly Func PositionalPatternClauseAccessor; + private static readonly Func PropertyPatternClauseAccessor; + private static readonly Func DesignationAccessor; + private static readonly Func WithTypeAccessor; + private static readonly Func WithPositionalPatternClauseAccessor; + private static readonly Func WithPropertyPatternClauseAccessor; + private static readonly Func WithDesignationAccessor; + + private readonly CSharpSyntaxNode node; + + static RecursivePatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RecursivePatternSyntaxWrapper)); + TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); + PositionalPatternClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(PositionalPatternClause)); + PropertyPatternClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(PropertyPatternClause)); + DesignationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Designation)); + WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + WithPositionalPatternClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(PositionalPatternClause)); + WithPropertyPatternClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(PropertyPatternClause)); + WithDesignationAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Designation)); + } + + private RecursivePatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public TypeSyntax Type + { + get + { + return TypeAccessor(this.SyntaxNode); + } + } + + public PositionalPatternClauseSyntaxWrapper PositionalPatternClause + { + get + { + return (PositionalPatternClauseSyntaxWrapper)PositionalPatternClauseAccessor(this.SyntaxNode); + } + } + + public PropertyPatternClauseSyntaxWrapper PropertyPatternClause + { + get + { + return (PropertyPatternClauseSyntaxWrapper)PropertyPatternClauseAccessor(this.SyntaxNode); + } + } + + public VariableDesignationSyntaxWrapper Designation + { + get + { + return (VariableDesignationSyntaxWrapper)DesignationAccessor(this.SyntaxNode); + } + } + + public static explicit operator RecursivePatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (RecursivePatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator RecursivePatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (RecursivePatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator RecursivePatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new RecursivePatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(RecursivePatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(RecursivePatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(RecursivePatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public RecursivePatternSyntaxWrapper WithType(TypeSyntax type) + { + return new RecursivePatternSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + } + + public RecursivePatternSyntaxWrapper WithPositionalPatternClause(PositionalPatternClauseSyntaxWrapper positionalPatternClause) + { + return new RecursivePatternSyntaxWrapper(WithPositionalPatternClauseAccessor(this.SyntaxNode, positionalPatternClause)); + } + + public RecursivePatternSyntaxWrapper WithPropertyPatternClause(PropertyPatternClauseSyntaxWrapper propertyPatternClause) + { + return new RecursivePatternSyntaxWrapper(WithPropertyPatternClauseAccessor(this.SyntaxNode, propertyPatternClause)); + } + + public RecursivePatternSyntaxWrapper WithDesignation(VariableDesignationSyntaxWrapper designation) + { + return new RecursivePatternSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefExpressionSyntaxWrapper.g.cs similarity index 92% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefExpressionSyntaxWrapper.g.cs index f85f9c3341..66ccf75292 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefExpressionSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct RefExpressionSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct RefExpressionSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RefExpressionSyntax"; private static readonly Type WrappedType; @@ -21,7 +23,7 @@ internal struct RefExpressionSyntaxWrapper : ISyntaxWrapper static RefExpressionSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(RefExpressionSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RefExpressionSyntaxWrapper)); RefKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(RefKeyword)); ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); WithRefKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(RefKeyword)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefTypeSyntaxWrapper.g.cs similarity index 93% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefTypeSyntaxWrapper.g.cs index 356cb25e79..aa22346716 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RefTypeSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RefTypeSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct RefTypeSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct RefTypeSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax"; private static readonly Type WrappedType; @@ -23,7 +25,7 @@ internal struct RefTypeSyntaxWrapper : ISyntaxWrapper static RefTypeSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(RefTypeSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RefTypeSyntaxWrapper)); RefKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(RefKeyword)); ReadOnlyKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ReadOnlyKeyword)); TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RelationalPatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RelationalPatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..70d4ba4bce --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/RelationalPatternSyntaxWrapper.g.cs @@ -0,0 +1,111 @@ +// 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 RelationalPatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RelationalPatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OperatorTokenAccessor; + private static readonly Func ExpressionAccessor; + private static readonly Func WithOperatorTokenAccessor; + private static readonly Func WithExpressionAccessor; + + private readonly CSharpSyntaxNode node; + + static RelationalPatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(RelationalPatternSyntaxWrapper)); + OperatorTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OperatorToken)); + ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); + WithOperatorTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OperatorToken)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); + } + + private RelationalPatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OperatorToken + { + get + { + return OperatorTokenAccessor(this.SyntaxNode); + } + } + + public ExpressionSyntax Expression + { + get + { + return ExpressionAccessor(this.SyntaxNode); + } + } + + public static explicit operator RelationalPatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (RelationalPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator RelationalPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (RelationalPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator RelationalPatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new RelationalPatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(RelationalPatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(RelationalPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(RelationalPatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public RelationalPatternSyntaxWrapper WithOperatorToken(SyntaxToken operatorToken) + { + return new RelationalPatternSyntaxWrapper(WithOperatorTokenAccessor(this.SyntaxNode, operatorToken)); + } + + public RelationalPatternSyntaxWrapper WithExpression(ExpressionSyntax expression) + { + return new RelationalPatternSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SingleVariableDesignationSyntaxWrapper.g.cs similarity index 90% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SingleVariableDesignationSyntaxWrapper.g.cs index 518e4cea69..95bf87c9d9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SingleVariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SingleVariableDesignationSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct SingleVariableDesignationSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct SingleVariableDesignationSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SingleVariableDesignationSyntax"; private static readonly Type WrappedType; @@ -19,7 +21,7 @@ internal struct SingleVariableDesignationSyntaxWrapper : ISyntaxWrapper(WrappedType, nameof(Identifier)); WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SubpatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs similarity index 93% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SubpatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs index 4eb82a3431..d7beccbc3d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SubpatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SubpatternSyntaxWrapper.g.cs @@ -4,18 +4,18 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct SubpatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct SubpatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SubpatternSyntax"; private static readonly Type WrappedType; private static readonly Func NameColonAccessor; private static readonly Func PatternAccessor; - private static readonly Func WithNameColonAccessor; private static readonly Func WithPatternAccessor; @@ -23,10 +23,9 @@ internal struct SubpatternSyntaxWrapper : ISyntaxWrapper static SubpatternSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)); NameColonAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(NameColon)); PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); - WithNameColonAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(NameColon)); WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionArmSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionArmSyntaxWrapper.g.cs similarity index 94% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionArmSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionArmSyntaxWrapper.g.cs index b7464c006b..d7216f44bb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionArmSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionArmSyntaxWrapper.g.cs @@ -4,39 +4,38 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct SwitchExpressionArmSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct SwitchExpressionArmSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax"; - private static readonly Type WrappedType; + private static readonly Func PatternAccessor; private static readonly Func WhenClauseAccessor; - private static readonly Func ExpressionAccessor; private static readonly Func EqualsGreaterThanTokenAccessor; - + private static readonly Func ExpressionAccessor; private static readonly Func WithPatternAccessor; private static readonly Func WithWhenClauseAccessor; - private static readonly Func WithExpressionAccessor; private static readonly Func WithEqualsGreaterThanTokenAccessor; + private static readonly Func WithExpressionAccessor; private readonly CSharpSyntaxNode node; static SwitchExpressionArmSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(SwitchExpressionArmSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SwitchExpressionArmSyntaxWrapper)); PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); WhenClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(WhenClause)); - ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); EqualsGreaterThanTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(EqualsGreaterThanToken)); - + ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); WithWhenClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(WhenClause)); - WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); WithEqualsGreaterThanTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(EqualsGreaterThanToken)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); } private SwitchExpressionArmSyntaxWrapper(CSharpSyntaxNode node) @@ -62,19 +61,19 @@ public WhenClauseSyntaxWrapper WhenClause } } - public ExpressionSyntax Expression + public SyntaxToken EqualsGreaterThanToken { get { - return ExpressionAccessor(this.SyntaxNode); + return EqualsGreaterThanTokenAccessor(this.SyntaxNode); } } - public SyntaxToken EqualsGreaterThanToken + public ExpressionSyntax Expression { get { - return EqualsGreaterThanTokenAccessor(this.SyntaxNode); + return ExpressionAccessor(this.SyntaxNode); } } @@ -105,7 +104,7 @@ public static bool IsInstance(SyntaxNode node) public SwitchExpressionArmSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) { - return new SwitchExpressionArmSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern.SyntaxNode)); + return new SwitchExpressionArmSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern)); } public SwitchExpressionArmSyntaxWrapper WithWhenClause(WhenClauseSyntaxWrapper whenClause) @@ -113,14 +112,14 @@ public SwitchExpressionArmSyntaxWrapper WithWhenClause(WhenClauseSyntaxWrapper w return new SwitchExpressionArmSyntaxWrapper(WithWhenClauseAccessor(this.SyntaxNode, whenClause)); } - public SwitchExpressionArmSyntaxWrapper WithExpression(ExpressionSyntax expression) + public SwitchExpressionArmSyntaxWrapper WithEqualsGreaterThanToken(SyntaxToken equalsGreaterThanToken) { - return new SwitchExpressionArmSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + return new SwitchExpressionArmSyntaxWrapper(WithEqualsGreaterThanTokenAccessor(this.SyntaxNode, equalsGreaterThanToken)); } - public SwitchExpressionArmSyntaxWrapper WithEqualsGreaterThanToken(SyntaxToken equalsGreaterThanToken) + public SwitchExpressionArmSyntaxWrapper WithExpression(ExpressionSyntax expression) { - return new SwitchExpressionArmSyntaxWrapper(WithEqualsGreaterThanTokenAccessor(this.SyntaxNode, equalsGreaterThanToken)); + return new SwitchExpressionArmSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..85a737efb5 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SwitchExpressionSyntaxWrapper.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 SwitchExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func GoverningExpressionAccessor; + private static readonly Func SwitchKeywordAccessor; + private static readonly Func OpenBraceTokenAccessor; + private static readonly Func> ArmsAccessor; + private static readonly Func CloseBraceTokenAccessor; + private static readonly Func WithGoverningExpressionAccessor; + private static readonly Func WithSwitchKeywordAccessor; + private static readonly Func WithOpenBraceTokenAccessor; + private static readonly Func, ExpressionSyntax> WithArmsAccessor; + private static readonly Func WithCloseBraceTokenAccessor; + + private readonly ExpressionSyntax node; + + static SwitchExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(SwitchExpressionSyntaxWrapper)); + GoverningExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(GoverningExpression)); + SwitchKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SwitchKeyword)); + OpenBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBraceToken)); + ArmsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Arms)); + CloseBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBraceToken)); + WithGoverningExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(GoverningExpression)); + WithSwitchKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SwitchKeyword)); + WithOpenBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBraceToken)); + WithArmsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Arms)); + WithCloseBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBraceToken)); + } + + private SwitchExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public ExpressionSyntax GoverningExpression + { + get + { + return GoverningExpressionAccessor(this.SyntaxNode); + } + } + + public SyntaxToken SwitchKeyword + { + get + { + return SwitchKeywordAccessor(this.SyntaxNode); + } + } + + public SyntaxToken OpenBraceToken + { + get + { + return OpenBraceTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Arms + { + get + { + return ArmsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseBraceToken + { + get + { + return CloseBraceTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator SwitchExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new SwitchExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator ExpressionSyntax(SwitchExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public SwitchExpressionSyntaxWrapper WithGoverningExpression(ExpressionSyntax governingExpression) + { + return new SwitchExpressionSyntaxWrapper(WithGoverningExpressionAccessor(this.SyntaxNode, governingExpression)); + } + + public SwitchExpressionSyntaxWrapper WithSwitchKeyword(SyntaxToken switchKeyword) + { + return new SwitchExpressionSyntaxWrapper(WithSwitchKeywordAccessor(this.SyntaxNode, switchKeyword)); + } + + public SwitchExpressionSyntaxWrapper WithOpenBraceToken(SyntaxToken openBraceToken) + { + return new SwitchExpressionSyntaxWrapper(WithOpenBraceTokenAccessor(this.SyntaxNode, openBraceToken)); + } + + public SwitchExpressionSyntaxWrapper WithArms(SeparatedSyntaxListWrapper arms) + { + return new SwitchExpressionSyntaxWrapper(WithArmsAccessor(this.SyntaxNode, arms)); + } + + public SwitchExpressionSyntaxWrapper WithCloseBraceToken(SyntaxToken closeBraceToken) + { + return new SwitchExpressionSyntaxWrapper(WithCloseBraceTokenAccessor(this.SyntaxNode, closeBraceToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WrapperHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs similarity index 61% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WrapperHelper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs index 52e110c4ed..85f0161731 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/WrapperHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/SyntaxWrapperHelper.g.cs @@ -9,40 +9,52 @@ namespace StyleCop.Analyzers.Lightup using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; - internal static class WrapperHelper + internal static class SyntaxWrapperHelper { private static readonly ImmutableDictionary WrappedTypes; - static WrapperHelper() + static SyntaxWrapperHelper() { var csharpCodeAnalysisAssembly = typeof(CSharpSyntaxNode).GetTypeInfo().Assembly; var builder = ImmutableDictionary.CreateBuilder(); + builder.Add(typeof(BaseObjectCreationExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(BaseObjectCreationExpressionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(BaseParameterSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(BaseParameterSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(BinaryPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(BinaryPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(CasePatternSwitchLabelSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(CasePatternSwitchLabelSyntaxWrapper.WrappedTypeName)); - - // Prior to C# 7, ForEachStatementSyntax was the base type for all foreach statements. If - // the CommonForEachStatementSyntax type isn't found at runtime, we fall back to using this type instead. - var forEachStatementSyntaxType = csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.WrappedTypeName) - ?? csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.FallbackWrappedTypeName); + var forEachStatementSyntaxType = csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.WrappedTypeName) ?? csharpCodeAnalysisAssembly.GetType(CommonForEachStatementSyntaxWrapper.FallbackWrappedTypeName); builder.Add(typeof(CommonForEachStatementSyntaxWrapper), forEachStatementSyntaxType); - builder.Add(typeof(ConstantPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ConstantPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(DeclarationExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(DeclarationExpressionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(DeclarationPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(DeclarationPatternSyntaxWrapper.WrappedTypeName)); + 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(ExpressionOrPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ExpressionOrPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ForEachVariableStatementSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ForEachVariableStatementSyntaxWrapper.WrappedTypeName)); - builder.Add(typeof(IsPatternExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(IsPatternExpressionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerCallingConventionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerCallingConventionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerParameterListSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerParameterListSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerParameterSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerParameterSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerTypeSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerTypeSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerUnmanagedCallingConventionListSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(FunctionPointerUnmanagedCallingConventionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(FunctionPointerUnmanagedCallingConventionSyntaxWrapper.WrappedTypeName)); + 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(LocalFunctionStatementSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(LocalFunctionStatementSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(NullableDirectiveTriviaSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(NullableDirectiveTriviaSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(ParenthesizedPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ParenthesizedPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(ParenthesizedVariableDesignationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(ParenthesizedVariableDesignationSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(PatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(PatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(PositionalPatternClauseSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(PositionalPatternClauseSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(PrimaryConstructorBaseTypeSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(PrimaryConstructorBaseTypeSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(PropertyPatternClauseSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(PropertyPatternClauseSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(RangeExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RangeExpressionSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(RecordDeclarationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RecordDeclarationSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(RecursivePatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RecursivePatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(RefExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RefExpressionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(RefTypeSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RefTypeSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(RelationalPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(RelationalPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(SingleVariableDesignationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(SingleVariableDesignationSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(SubpatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(SubpatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(SwitchExpressionArmSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(SwitchExpressionArmSyntaxWrapper.WrappedTypeName)); @@ -51,9 +63,12 @@ static WrapperHelper() builder.Add(typeof(TupleElementSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(TupleElementSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(TupleExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(TupleExpressionSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(TupleTypeSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(TupleTypeSyntaxWrapper.WrappedTypeName)); - builder.Add(typeof(VarPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(VarPatternSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(TypePatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(TypePatternSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(UnaryPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(UnaryPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(VariableDesignationSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(VariableDesignationSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(VarPatternSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(VarPatternSyntaxWrapper.WrappedTypeName)); builder.Add(typeof(WhenClauseSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(WhenClauseSyntaxWrapper.WrappedTypeName)); + builder.Add(typeof(WithExpressionSyntaxWrapper), csharpCodeAnalysisAssembly.GetType(WithExpressionSyntaxWrapper.WrappedTypeName)); WrappedTypes = builder.ToImmutable(); } @@ -61,12 +76,11 @@ static WrapperHelper() /// /// Gets the type that is wrapped by the given wrapper. /// - /// Type of the wrapper for which the wrapped type should be retrieved. + /// Type of the wrapper for which the wrapped type should be retrieved. /// The wrapped type, or null if there is no info. internal static Type GetWrappedType(Type wrapperType) { - Type wrappedType; - if (WrappedTypes.TryGetValue(wrapperType, out wrappedType)) + if (WrappedTypes.TryGetValue(wrapperType, out Type wrappedType)) { return wrappedType; } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ThrowExpressionSyntaxWrapper.g.cs similarity index 92% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ThrowExpressionSyntaxWrapper.g.cs index 50e5eeb93b..d85d4613ea 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ThrowExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/ThrowExpressionSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct ThrowExpressionSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct ThrowExpressionSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ThrowExpressionSyntax"; private static readonly Type WrappedType; @@ -21,7 +23,7 @@ internal struct ThrowExpressionSyntaxWrapper : ISyntaxWrapper static ThrowExpressionSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(ThrowExpressionSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(ThrowExpressionSyntaxWrapper)); ThrowKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ThrowKeyword)); ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); WithThrowKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ThrowKeyword)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleElementSyntaxWrapper.g.cs similarity index 93% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleElementSyntaxWrapper.g.cs index 1b7fcf7b5c..508c25cf4d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleElementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleElementSyntaxWrapper.g.cs @@ -4,29 +4,30 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct TupleElementSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct TupleElementSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TupleElementSyntax"; private static readonly Type WrappedType; - private static readonly Func IdentifierAccessor; private static readonly Func TypeAccessor; - private static readonly Func WithIdentifierAccessor; + private static readonly Func IdentifierAccessor; private static readonly Func WithTypeAccessor; + private static readonly Func WithIdentifierAccessor; private readonly CSharpSyntaxNode node; static TupleElementSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)); - IdentifierAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Identifier)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)); TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); - WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); + IdentifierAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Identifier)); WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); } private TupleElementSyntaxWrapper(CSharpSyntaxNode node) @@ -36,19 +37,19 @@ private TupleElementSyntaxWrapper(CSharpSyntaxNode node) public CSharpSyntaxNode SyntaxNode => this.node; - public SyntaxToken Identifier + public TypeSyntax Type { get { - return IdentifierAccessor(this.SyntaxNode); + return TypeAccessor(this.SyntaxNode); } } - public TypeSyntax Type + public SyntaxToken Identifier { get { - return TypeAccessor(this.SyntaxNode); + return IdentifierAccessor(this.SyntaxNode); } } @@ -77,14 +78,14 @@ public static bool IsInstance(SyntaxNode node) return node != null && LightupHelpers.CanWrapNode(node, WrappedType); } - public TupleElementSyntaxWrapper WithIdentifier(SyntaxToken identifier) + public TupleElementSyntaxWrapper WithType(TypeSyntax type) { - return new TupleElementSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); + return new TupleElementSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); } - public TupleElementSyntaxWrapper WithType(TypeSyntax type) + public TupleElementSyntaxWrapper WithIdentifier(SyntaxToken identifier) { - return new TupleElementSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + return new TupleElementSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..e05a152c98 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleExpressionSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 TupleExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TupleExpressionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func> ArgumentsAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func, ExpressionSyntax> WithArgumentsAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly ExpressionSyntax node; + + static TupleExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(TupleExpressionSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + ArgumentsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(Arguments)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithArgumentsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Arguments)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private TupleExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxList Arguments + { + get + { + return ArgumentsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator TupleExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new TupleExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator ExpressionSyntax(TupleExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public TupleExpressionSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new TupleExpressionSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public TupleExpressionSyntaxWrapper WithArguments(SeparatedSyntaxList arguments) + { + return new TupleExpressionSyntaxWrapper(WithArgumentsAccessor(this.SyntaxNode, arguments)); + } + + public TupleExpressionSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new TupleExpressionSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleTypeSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleTypeSyntaxWrapper.g.cs new file mode 100644 index 0000000000..d0117fc618 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TupleTypeSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 TupleTypeSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TupleTypeSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OpenParenTokenAccessor; + private static readonly Func> ElementsAccessor; + private static readonly Func CloseParenTokenAccessor; + private static readonly Func WithOpenParenTokenAccessor; + private static readonly Func, TypeSyntax> WithElementsAccessor; + private static readonly Func WithCloseParenTokenAccessor; + + private readonly TypeSyntax node; + + static TupleTypeSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(TupleTypeSyntaxWrapper)); + OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); + ElementsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Elements)); + CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); + WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); + WithElementsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Elements)); + WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); + } + + private TupleTypeSyntaxWrapper(TypeSyntax node) + { + this.node = node; + } + + public TypeSyntax SyntaxNode => this.node; + + public SyntaxToken OpenParenToken + { + get + { + return OpenParenTokenAccessor(this.SyntaxNode); + } + } + + public SeparatedSyntaxListWrapper Elements + { + get + { + return ElementsAccessor(this.SyntaxNode); + } + } + + public SyntaxToken CloseParenToken + { + get + { + return CloseParenTokenAccessor(this.SyntaxNode); + } + } + + public static explicit operator TupleTypeSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new TupleTypeSyntaxWrapper((TypeSyntax)node); + } + + public static implicit operator TypeSyntax(TupleTypeSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public TupleTypeSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) + { + return new TupleTypeSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); + } + + public TupleTypeSyntaxWrapper WithElements(SeparatedSyntaxListWrapper elements) + { + return new TupleTypeSyntaxWrapper(WithElementsAccessor(this.SyntaxNode, elements)); + } + + public TupleTypeSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) + { + return new TupleTypeSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TypePatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TypePatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..4bf6195c23 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/TypePatternSyntaxWrapper.g.cs @@ -0,0 +1,94 @@ +// 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 TypePatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TypePatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func TypeAccessor; + private static readonly Func WithTypeAccessor; + + private readonly CSharpSyntaxNode node; + + static TypePatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(TypePatternSyntaxWrapper)); + TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); + WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); + } + + private TypePatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public TypeSyntax Type + { + get + { + return TypeAccessor(this.SyntaxNode); + } + } + + public static explicit operator TypePatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (TypePatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator TypePatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (TypePatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator TypePatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new TypePatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(TypePatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(TypePatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(TypePatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public TypePatternSyntaxWrapper WithType(TypeSyntax type) + { + return new TypePatternSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/UnaryPatternSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/UnaryPatternSyntaxWrapper.g.cs new file mode 100644 index 0000000000..51d2560c16 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/UnaryPatternSyntaxWrapper.g.cs @@ -0,0 +1,111 @@ +// 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 UnaryPatternSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.UnaryPatternSyntax"; + private static readonly Type WrappedType; + + private static readonly Func OperatorTokenAccessor; + private static readonly Func PatternAccessor; + private static readonly Func WithOperatorTokenAccessor; + private static readonly Func WithPatternAccessor; + + private readonly CSharpSyntaxNode node; + + static UnaryPatternSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(UnaryPatternSyntaxWrapper)); + OperatorTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OperatorToken)); + PatternAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Pattern)); + WithOperatorTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OperatorToken)); + WithPatternAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Pattern)); + } + + private UnaryPatternSyntaxWrapper(CSharpSyntaxNode node) + { + this.node = node; + } + + public CSharpSyntaxNode SyntaxNode => this.node; + + public SyntaxToken OperatorToken + { + get + { + return OperatorTokenAccessor(this.SyntaxNode); + } + } + + public PatternSyntaxWrapper Pattern + { + get + { + return (PatternSyntaxWrapper)PatternAccessor(this.SyntaxNode); + } + } + + public static explicit operator UnaryPatternSyntaxWrapper(PatternSyntaxWrapper node) + { + return (UnaryPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator UnaryPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (UnaryPatternSyntaxWrapper)node.SyntaxNode; + } + + public static explicit operator UnaryPatternSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new UnaryPatternSyntaxWrapper((CSharpSyntaxNode)node); + } + + public static implicit operator PatternSyntaxWrapper(UnaryPatternSyntaxWrapper wrapper) + { + return PatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator ExpressionOrPatternSyntaxWrapper(UnaryPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + + public static implicit operator CSharpSyntaxNode(UnaryPatternSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public UnaryPatternSyntaxWrapper WithOperatorToken(SyntaxToken operatorToken) + { + return new UnaryPatternSyntaxWrapper(WithOperatorTokenAccessor(this.SyntaxNode, operatorToken)); + } + + public UnaryPatternSyntaxWrapper WithPattern(PatternSyntaxWrapper pattern) + { + return new UnaryPatternSyntaxWrapper(WithPatternAccessor(this.SyntaxNode, pattern)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VarPatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VarPatternSyntaxWrapper.g.cs similarity index 84% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VarPatternSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VarPatternSyntaxWrapper.g.cs index 23e74c92b3..13784a24aa 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VarPatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VarPatternSyntaxWrapper.g.cs @@ -4,17 +4,18 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct VarPatternSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct VarPatternSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax"; private static readonly Type WrappedType; private static readonly Func VarKeywordAccessor; private static readonly Func DesignationAccessor; - private static readonly Func WithVarKeywordAccessor; private static readonly Func WithDesignationAccessor; @@ -22,10 +23,9 @@ internal struct VarPatternSyntaxWrapper : ISyntaxWrapper static VarPatternSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(VarPatternSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(VarPatternSyntaxWrapper)); VarKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(VarKeyword)); DesignationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Designation)); - WithVarKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(VarKeyword)); WithDesignationAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Designation)); } @@ -58,6 +58,11 @@ public static explicit operator VarPatternSyntaxWrapper(PatternSyntaxWrapper nod return (VarPatternSyntaxWrapper)node.SyntaxNode; } + public static explicit operator VarPatternSyntaxWrapper(ExpressionOrPatternSyntaxWrapper node) + { + return (VarPatternSyntaxWrapper)node.SyntaxNode; + } + public static explicit operator VarPatternSyntaxWrapper(SyntaxNode node) { if (node == null) @@ -78,6 +83,11 @@ public static implicit operator PatternSyntaxWrapper(VarPatternSyntaxWrapper wra return PatternSyntaxWrapper.FromUpcast(wrapper.node); } + public static implicit operator ExpressionOrPatternSyntaxWrapper(VarPatternSyntaxWrapper wrapper) + { + return ExpressionOrPatternSyntaxWrapper.FromUpcast(wrapper.node); + } + public static implicit operator CSharpSyntaxNode(VarPatternSyntaxWrapper wrapper) { return wrapper.node; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VariableDesignationSyntaxWrapper.g.cs similarity index 85% rename from StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs rename to StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VariableDesignationSyntaxWrapper.g.cs index 443c126e98..0cf306f9b5 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/VariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/VariableDesignationSyntaxWrapper.g.cs @@ -4,10 +4,12 @@ namespace StyleCop.Analyzers.Lightup { using System; + using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct VariableDesignationSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct VariableDesignationSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax"; private static readonly Type WrappedType; @@ -16,7 +18,7 @@ internal struct VariableDesignationSyntaxWrapper : ISyntaxWrapper + internal readonly partial struct WhenClauseSyntaxWrapper : ISyntaxWrapper { internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax"; private static readonly Type WrappedType; @@ -22,7 +23,7 @@ internal struct WhenClauseSyntaxWrapper : ISyntaxWrapper static WhenClauseSyntaxWrapper() { - WrappedType = WrapperHelper.GetWrappedType(typeof(WhenClauseSyntaxWrapper)); + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(WhenClauseSyntaxWrapper)); WhenKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(WhenKeyword)); ConditionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Condition)); WithWhenKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(WhenKeyword)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/WithExpressionSyntaxWrapper.g.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/WithExpressionSyntaxWrapper.g.cs new file mode 100644 index 0000000000..ec72fe6813 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/StyleCop.Analyzers.CodeGeneration/StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/WithExpressionSyntaxWrapper.g.cs @@ -0,0 +1,108 @@ +// 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 WithExpressionSyntaxWrapper : ISyntaxWrapper + { + internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.WithExpressionSyntax"; + private static readonly Type WrappedType; + + private static readonly Func ExpressionAccessor; + private static readonly Func WithKeywordAccessor; + private static readonly Func InitializerAccessor; + private static readonly Func WithExpressionAccessor; + private static readonly Func WithWithKeywordAccessor; + private static readonly Func WithInitializerAccessor; + + private readonly ExpressionSyntax node; + + static WithExpressionSyntaxWrapper() + { + WrappedType = SyntaxWrapperHelper.GetWrappedType(typeof(WithExpressionSyntaxWrapper)); + ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); + WithKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(WithKeyword)); + InitializerAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Initializer)); + WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); + WithWithKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(WithKeyword)); + WithInitializerAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Initializer)); + } + + private WithExpressionSyntaxWrapper(ExpressionSyntax node) + { + this.node = node; + } + + public ExpressionSyntax SyntaxNode => this.node; + + public ExpressionSyntax Expression + { + get + { + return ExpressionAccessor(this.SyntaxNode); + } + } + + public SyntaxToken WithKeyword + { + get + { + return WithKeywordAccessor(this.SyntaxNode); + } + } + + public InitializerExpressionSyntax Initializer + { + get + { + return InitializerAccessor(this.SyntaxNode); + } + } + + public static explicit operator WithExpressionSyntaxWrapper(SyntaxNode node) + { + if (node == null) + { + return default; + } + + if (!IsInstance(node)) + { + throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); + } + + return new WithExpressionSyntaxWrapper((ExpressionSyntax)node); + } + + public static implicit operator ExpressionSyntax(WithExpressionSyntaxWrapper wrapper) + { + return wrapper.node; + } + + public static bool IsInstance(SyntaxNode node) + { + return node != null && LightupHelpers.CanWrapNode(node, WrappedType); + } + + public WithExpressionSyntaxWrapper WithExpression(ExpressionSyntax expression) + { + return new WithExpressionSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); + } + + public WithExpressionSyntaxWrapper WithWithKeyword(SyntaxToken withKeyword) + { + return new WithExpressionSyntaxWrapper(WithWithKeywordAccessor(this.SyntaxNode, withKeyword)); + } + + public WithExpressionSyntaxWrapper WithInitializer(InitializerExpressionSyntax initializer) + { + return new WithExpressionSyntaxWrapper(WithInitializerAccessor(this.SyntaxNode, initializer)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs index b7ccd1f6b8..b025d8637d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/CommonForEachStatementSyntaxWrapper.cs @@ -3,185 +3,15 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct CommonForEachStatementSyntaxWrapper : ISyntaxWrapper + internal partial struct CommonForEachStatementSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax"; internal const string FallbackWrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ForEachStatementSyntax"; - private static readonly Type WrappedType; - - private static readonly Func AwaitKeywordAccessor; - private static readonly Func ForEachKeywordAccessor; - private static readonly Func OpenParenTokenAccessor; - private static readonly Func InKeywordAccessor; - private static readonly Func ExpressionAccessor; - private static readonly Func CloseParenTokenAccessor; - private static readonly Func StatementAccessor; - - private static readonly Func WithAwaitKeywordAccessor; - private static readonly Func WithForEachKeywordAccessor; - private static readonly Func WithOpenParenTokenAccessor; - private static readonly Func WithInKeywordAccessor; - private static readonly Func WithExpressionAccessor; - private static readonly Func WithCloseParenTokenAccessor; - private static readonly Func WithStatementAccessor; - - private readonly StatementSyntax node; - - static CommonForEachStatementSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(CommonForEachStatementSyntaxWrapper)); - AwaitKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(AwaitKeyword)); - ForEachKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ForEachKeyword)); - OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); - InKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(InKeyword)); - ExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Expression)); - CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); - StatementAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Statement)); - - WithAwaitKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(AwaitKeyword)); - WithForEachKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ForEachKeyword)); - WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); - WithInKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(InKeyword)); - WithExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Expression)); - WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); - WithStatementAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Statement)); - } - - private CommonForEachStatementSyntaxWrapper(StatementSyntax node) - { - this.node = node; - } - - public StatementSyntax SyntaxNode => this.node; - - public SyntaxToken AwaitKeyword - { - get - { - return AwaitKeywordAccessor(this.SyntaxNode); - } - } - - public SyntaxToken ForEachKeyword - { - get - { - return ForEachKeywordAccessor(this.SyntaxNode); - } - } - - public SyntaxToken OpenParenToken - { - get - { - return OpenParenTokenAccessor(this.SyntaxNode); - } - } - - public SyntaxToken InKeyword - { - get - { - return InKeywordAccessor(this.SyntaxNode); - } - } - - public ExpressionSyntax Expression - { - get - { - return ExpressionAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseParenToken - { - get - { - return CloseParenTokenAccessor(this.SyntaxNode); - } - } - - public StatementSyntax Statement - { - get - { - return StatementAccessor(this.SyntaxNode); - } - } public static implicit operator CommonForEachStatementSyntaxWrapper(ForEachStatementSyntax node) { return new CommonForEachStatementSyntaxWrapper(node); } - - public static explicit operator CommonForEachStatementSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new CommonForEachStatementSyntaxWrapper((StatementSyntax)node); - } - - public static implicit operator StatementSyntax(CommonForEachStatementSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - - public CommonForEachStatementSyntaxWrapper WithAwaitKeyword(SyntaxToken awaitKeyword) - { - return new CommonForEachStatementSyntaxWrapper(WithAwaitKeywordAccessor(this.SyntaxNode, awaitKeyword)); - } - - public CommonForEachStatementSyntaxWrapper WithForEachKeyword(SyntaxToken forEachKeyword) - { - return new CommonForEachStatementSyntaxWrapper(WithForEachKeywordAccessor(this.SyntaxNode, forEachKeyword)); - } - - public CommonForEachStatementSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) - { - return new CommonForEachStatementSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); - } - - public CommonForEachStatementSyntaxWrapper WithInKeyword(SyntaxToken inKeyword) - { - return new CommonForEachStatementSyntaxWrapper(WithInKeywordAccessor(this.SyntaxNode, inKeyword)); - } - - public CommonForEachStatementSyntaxWrapper WithExpression(ExpressionSyntax expression) - { - return new CommonForEachStatementSyntaxWrapper(WithExpressionAccessor(this.SyntaxNode, expression)); - } - - public CommonForEachStatementSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) - { - return new CommonForEachStatementSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); - } - - public CommonForEachStatementSyntaxWrapper WithStatement(StatementSyntax statement) - { - return new CommonForEachStatementSyntaxWrapper(WithStatementAccessor(this.SyntaxNode, statement)); - } - - internal static CommonForEachStatementSyntaxWrapper FromUpcast(StatementSyntax node) - { - return new CommonForEachStatementSyntaxWrapper(node); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs index 952809c559..b220383f43 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.cs @@ -3,123 +3,10 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct ImplicitStackAllocArrayCreationExpressionSyntaxWrapper : ISyntaxWrapper + internal partial struct ImplicitStackAllocArrayCreationExpressionSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitStackAllocArrayCreationExpressionSyntax"; - private static readonly Type WrappedType; - - private static readonly Func StackAllocKeywordAccessor; - private static readonly Func OpenBracketTokenAccessor; - private static readonly Func CloseBracketTokenAccessor; - private static readonly Func InitializerAccessor; - private static readonly Func WithStackAllocKeywordAccessor; - private static readonly Func WithOpenBracketTokenAccessor; - private static readonly Func WithCloseBracketTokenAccessor; - private static readonly Func WithInitializerAccessor; - - private readonly ExpressionSyntax node; - - static ImplicitStackAllocArrayCreationExpressionSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper)); - StackAllocKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(StackAllocKeyword)); - OpenBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBracketToken)); - CloseBracketTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBracketToken)); - InitializerAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Initializer)); - WithStackAllocKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(StackAllocKeyword)); - WithOpenBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBracketToken)); - WithCloseBracketTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBracketToken)); - WithInitializerAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Initializer)); - } - - private ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(ExpressionSyntax node) - { - this.node = node; - } - - public ExpressionSyntax SyntaxNode => this.node; - - public SyntaxToken StackAllocKeyword - { - get - { - return StackAllocKeywordAccessor(this.SyntaxNode); - } - } - - public SyntaxToken OpenBracketToken - { - get - { - return OpenBracketTokenAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseBracketToken - { - get - { - return CloseBracketTokenAccessor(this.SyntaxNode); - } - } - - public InitializerExpressionSyntax Initializer - { - get - { - return InitializerAccessor(this.SyntaxNode); - } - } - - public static explicit operator ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper((ExpressionSyntax)node); - } - - public static implicit operator ExpressionSyntax(ImplicitStackAllocArrayCreationExpressionSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - - public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithStackAllocKeyword(SyntaxToken stackAllocKeyword) - { - return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithStackAllocKeywordAccessor(this.SyntaxNode, stackAllocKeyword)); - } - - public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithOpenBracketToken(SyntaxToken openBracketToken) - { - return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithOpenBracketTokenAccessor(this.SyntaxNode, openBracketToken)); - } - - public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithCloseBracketToken(SyntaxToken closeBracketToken) - { - return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithCloseBracketTokenAccessor(this.SyntaxNode, closeBracketToken)); - } - - public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper WithInitializer(InitializerExpressionSyntax initializer) - { - return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(WithInitializerAccessor(this.SyntaxNode, initializer)); - } - public ImplicitStackAllocArrayCreationExpressionSyntaxWrapper AddInitializerExpressions(params ExpressionSyntax[] items) { return new ImplicitStackAllocArrayCreationExpressionSyntaxWrapper(this.WithInitializer(this.Initializer.AddExpressions(items))); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs index b3af495843..a2bfc224b6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs @@ -449,7 +449,7 @@ TSyntax FallbackAccessor(TSyntax syntax, SeparatedSyntaxListWrapper n private static bool ValidatePropertyType(Type returnType, Type actualType) { - var requiredType = WrapperHelper.GetWrappedType(returnType) ?? returnType; + var requiredType = SyntaxWrapperHelper.GetWrappedType(returnType) ?? returnType; return requiredType == actualType; } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs index f431d185e8..4fdaf3f7b8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LocalFunctionStatementSyntaxWrapper.cs @@ -3,209 +3,12 @@ namespace StyleCop.Analyzers.Lightup { - using System; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct LocalFunctionStatementSyntaxWrapper : ISyntaxWrapper + internal partial struct LocalFunctionStatementSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.LocalFunctionStatementSyntax"; - private static readonly Type WrappedType; - - private static readonly Func ModifiersAccessor; - private static readonly Func ReturnTypeAccessor; - private static readonly Func IdentifierAccessor; - private static readonly Func TypeParameterListAccessor; - private static readonly Func ParameterListAccessor; - private static readonly Func> ConstraintClausesAccessor; - private static readonly Func BodyAccessor; - private static readonly Func ExpressionBodyAccessor; - private static readonly Func SemicolonTokenAccessor; - private static readonly Func WithModifiersAccessor; - private static readonly Func WithReturnTypeAccessor; - private static readonly Func WithIdentifierAccessor; - private static readonly Func WithTypeParameterListAccessor; - private static readonly Func WithParameterListAccessor; - private static readonly Func, StatementSyntax> WithConstraintClausesAccessor; - private static readonly Func WithBodyAccessor; - private static readonly Func WithExpressionBodyAccessor; - private static readonly Func WithSemicolonTokenAccessor; - - private readonly StatementSyntax node; - - static LocalFunctionStatementSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(LocalFunctionStatementSyntaxWrapper)); - ModifiersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Modifiers)); - ReturnTypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ReturnType)); - IdentifierAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Identifier)); - TypeParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(TypeParameterList)); - ParameterListAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ParameterList)); - ConstraintClausesAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(ConstraintClauses)); - BodyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Body)); - ExpressionBodyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(ExpressionBody)); - SemicolonTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SemicolonToken)); - WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Modifiers)); - WithReturnTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ReturnType)); - WithIdentifierAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Identifier)); - WithTypeParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(TypeParameterList)); - WithParameterListAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ParameterList)); - WithConstraintClausesAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(ConstraintClauses)); - WithBodyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Body)); - WithExpressionBodyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(ExpressionBody)); - WithSemicolonTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SemicolonToken)); - } - - private LocalFunctionStatementSyntaxWrapper(StatementSyntax node) - { - this.node = node; - } - - public StatementSyntax SyntaxNode => this.node; - - public SyntaxTokenList Modifiers - { - get - { - return ModifiersAccessor(this.SyntaxNode); - } - } - - public TypeSyntax ReturnType - { - get - { - return ReturnTypeAccessor(this.SyntaxNode); - } - } - - public SyntaxToken Identifier - { - get - { - return IdentifierAccessor(this.SyntaxNode); - } - } - - public TypeParameterListSyntax TypeParameterList - { - get - { - return TypeParameterListAccessor(this.SyntaxNode); - } - } - - public ParameterListSyntax ParameterList - { - get - { - return ParameterListAccessor(this.SyntaxNode); - } - } - - public SyntaxList ConstraintClauses - { - get - { - return ConstraintClausesAccessor(this.SyntaxNode); - } - } - - public BlockSyntax Body - { - get - { - return BodyAccessor(this.SyntaxNode); - } - } - - public ArrowExpressionClauseSyntax ExpressionBody - { - get - { - return ExpressionBodyAccessor(this.SyntaxNode); - } - } - - public SyntaxToken SemicolonToken - { - get - { - return SemicolonTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator LocalFunctionStatementSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new LocalFunctionStatementSyntaxWrapper((StatementSyntax)node); - } - - public static implicit operator StatementSyntax(LocalFunctionStatementSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - - public LocalFunctionStatementSyntaxWrapper WithModifiers(SyntaxTokenList modifiers) - { - return new LocalFunctionStatementSyntaxWrapper(WithModifiersAccessor(this.SyntaxNode, modifiers)); - } - - public LocalFunctionStatementSyntaxWrapper WithReturnType(TypeSyntax returnType) - { - return new LocalFunctionStatementSyntaxWrapper(WithReturnTypeAccessor(this.SyntaxNode, returnType)); - } - - public LocalFunctionStatementSyntaxWrapper WithIdentifier(SyntaxToken identifier) - { - return new LocalFunctionStatementSyntaxWrapper(WithIdentifierAccessor(this.SyntaxNode, identifier)); - } - - public LocalFunctionStatementSyntaxWrapper WithTypeParameterList(TypeParameterListSyntax typeParameterList) - { - return new LocalFunctionStatementSyntaxWrapper(WithTypeParameterListAccessor(this.SyntaxNode, typeParameterList)); - } - - public LocalFunctionStatementSyntaxWrapper WithParameterList(ParameterListSyntax parameterList) - { - return new LocalFunctionStatementSyntaxWrapper(WithParameterListAccessor(this.SyntaxNode, parameterList)); - } - - public LocalFunctionStatementSyntaxWrapper WithConstraintClauses(SyntaxList constraintClauses) - { - return new LocalFunctionStatementSyntaxWrapper(WithConstraintClausesAccessor(this.SyntaxNode, constraintClauses)); - } - - public LocalFunctionStatementSyntaxWrapper WithBody(BlockSyntax body) - { - return new LocalFunctionStatementSyntaxWrapper(WithBodyAccessor(this.SyntaxNode, body)); - } - - public LocalFunctionStatementSyntaxWrapper WithExpressionBody(ArrowExpressionClauseSyntax expressionBody) - { - return new LocalFunctionStatementSyntaxWrapper(WithExpressionBodyAccessor(this.SyntaxNode, expressionBody)); - } - - public LocalFunctionStatementSyntaxWrapper WithSemicolonToken(SyntaxToken semicolonToken) - { - return new LocalFunctionStatementSyntaxWrapper(WithSemicolonTokenAccessor(this.SyntaxNode, semicolonToken)); - } - public LocalFunctionStatementSyntaxWrapper AddModifiers(params SyntaxToken[] items) { return this.WithModifiers(this.Modifiers.AddRange(items)); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/MemberDeclarationSyntaxExtensions.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/MemberDeclarationSyntaxExtensions.cs new file mode 100644 index 0000000000..3d195490be --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/MemberDeclarationSyntaxExtensions.cs @@ -0,0 +1,55 @@ +// 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 Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal static class MemberDeclarationSyntaxExtensions + { + private static readonly Func> AttributeListsAccessor; + private static readonly Func ModifiersAccessor; + private static readonly Func, MemberDeclarationSyntax> WithAttributeListsAccessor; + private static readonly Func WithModifiersAccessor; + + static MemberDeclarationSyntaxExtensions() + { + AttributeListsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(typeof(MemberDeclarationSyntax), nameof(AttributeLists)); + ModifiersAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(typeof(MemberDeclarationSyntax), nameof(Modifiers)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(typeof(MemberDeclarationSyntax), nameof(AttributeLists)); + WithModifiersAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(typeof(MemberDeclarationSyntax), nameof(Modifiers)); + } + + public static SyntaxList AttributeLists(this MemberDeclarationSyntax syntax) + { + return AttributeListsAccessor(syntax); + } + + public static SyntaxTokenList Modifiers(this MemberDeclarationSyntax syntax) + { + return ModifiersAccessor(syntax); + } + + public static MemberDeclarationSyntax WithAttributeLists(this MemberDeclarationSyntax syntax, SyntaxList attributeLists) + { + return WithAttributeListsAccessor(syntax, attributeLists); + } + + public static MemberDeclarationSyntax WithModifiers(this MemberDeclarationSyntax syntax, SyntaxTokenList modifiers) + { + return WithModifiersAccessor(syntax, modifiers); + } + + public static MemberDeclarationSyntax AddAttributeLists(this MemberDeclarationSyntax syntax, params AttributeListSyntax[] items) + { + return syntax.WithAttributeLists(syntax.AttributeLists().AddRange(items)); + } + + public static MemberDeclarationSyntax AddModifiers(this MemberDeclarationSyntax syntax, params SyntaxToken[] items) + { + return syntax.WithModifiers(syntax.Modifiers().AddRange(items)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs index 0507883e83..ee3f285d5c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/ParenthesizedVariableDesignationSyntaxWrapper.cs @@ -3,119 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; - internal struct ParenthesizedVariableDesignationSyntaxWrapper : ISyntaxWrapper + internal partial struct ParenthesizedVariableDesignationSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedVariableDesignationSyntax"; - private static readonly Type WrappedType; - - private static readonly Func OpenParenTokenAccessor; - private static readonly Func> VariablesAccessor; - private static readonly Func CloseParenTokenAccessor; - private static readonly Func WithOpenParenTokenAccessor; - private static readonly Func, CSharpSyntaxNode> WithVariablesAccessor; - private static readonly Func WithCloseParenTokenAccessor; - - private readonly CSharpSyntaxNode node; - - static ParenthesizedVariableDesignationSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(ParenthesizedVariableDesignationSyntaxWrapper)); - OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); - VariablesAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Variables)); - CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); - WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); - WithVariablesAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Variables)); - WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); - } - - private ParenthesizedVariableDesignationSyntaxWrapper(CSharpSyntaxNode node) - { - this.node = node; - } - - public CSharpSyntaxNode SyntaxNode => this.node; - - public SyntaxToken OpenParenToken - { - get - { - return OpenParenTokenAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxListWrapper Variables - { - get - { - return VariablesAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseParenToken - { - get - { - return CloseParenTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator ParenthesizedVariableDesignationSyntaxWrapper(VariableDesignationSyntaxWrapper node) - { - return (ParenthesizedVariableDesignationSyntaxWrapper)node.SyntaxNode; - } - - public static explicit operator ParenthesizedVariableDesignationSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new ParenthesizedVariableDesignationSyntaxWrapper((CSharpSyntaxNode)node); - } - - public static implicit operator VariableDesignationSyntaxWrapper(ParenthesizedVariableDesignationSyntaxWrapper wrapper) - { - return VariableDesignationSyntaxWrapper.FromUpcast(wrapper.node); - } - - public static implicit operator CSharpSyntaxNode(ParenthesizedVariableDesignationSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public ParenthesizedVariableDesignationSyntaxWrapper AddVariables(params VariableDesignationSyntaxWrapper[] items) { return new ParenthesizedVariableDesignationSyntaxWrapper(this.WithVariables(this.Variables.AddRange(items))); } - - public ParenthesizedVariableDesignationSyntaxWrapper WithOpenParenToken(SyntaxToken identifier) - { - return new ParenthesizedVariableDesignationSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, identifier)); - } - - public ParenthesizedVariableDesignationSyntaxWrapper WithVariables(SeparatedSyntaxListWrapper variables) - { - return new ParenthesizedVariableDesignationSyntaxWrapper(WithVariablesAccessor(this.SyntaxNode, variables)); - } - - public ParenthesizedVariableDesignationSyntaxWrapper WithCloseParenToken(SyntaxToken identifier) - { - return new ParenthesizedVariableDesignationSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, identifier)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PositionalPatternClauseSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PositionalPatternClauseSyntaxWrapper.cs index 5b715af41d..5c26c17942 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PositionalPatternClauseSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PositionalPatternClauseSyntaxWrapper.cs @@ -3,111 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; - internal struct PositionalPatternClauseSyntaxWrapper : ISyntaxWrapper + internal partial struct PositionalPatternClauseSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PositionalPatternClauseSyntax"; - private static readonly Type WrappedType; - - private static readonly Func OpenParenTokenAccessor; - private static readonly Func> SubpatternsAccessor; - private static readonly Func CloseParenTokenAccessor; - - private static readonly Func WithOpenParenTokenAccessor; - private static readonly Func, CSharpSyntaxNode> WithSubpatternsAccessor; - private static readonly Func WithCloseParenTokenAccessor; - - private readonly CSharpSyntaxNode node; - - static PositionalPatternClauseSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(PositionalPatternClauseSyntaxWrapper)); - OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); - SubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Subpatterns)); - CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); - - WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); - WithSubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Subpatterns)); - WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); - } - - private PositionalPatternClauseSyntaxWrapper(CSharpSyntaxNode node) - { - this.node = node; - } - - public CSharpSyntaxNode SyntaxNode => this.node; - - public SyntaxToken OpenParenToken - { - get - { - return OpenParenTokenAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxListWrapper Subpatterns - { - get - { - return SubpatternsAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseParenToken - { - get - { - return CloseParenTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator PositionalPatternClauseSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new PositionalPatternClauseSyntaxWrapper((CSharpSyntaxNode)node); - } - - public static implicit operator CSharpSyntaxNode(PositionalPatternClauseSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public PositionalPatternClauseSyntaxWrapper AddSubpatterns(params SubpatternSyntaxWrapper[] items) { return new PositionalPatternClauseSyntaxWrapper(this.WithSubpatterns(this.Subpatterns.AddRange(items))); } - - public PositionalPatternClauseSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) - { - return new PositionalPatternClauseSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); - } - - public PositionalPatternClauseSyntaxWrapper WithSubpatterns(SeparatedSyntaxListWrapper subpatterns) - { - return new PositionalPatternClauseSyntaxWrapper(WithSubpatternsAccessor(this.SyntaxNode, subpatterns)); - } - - public PositionalPatternClauseSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) - { - return new PositionalPatternClauseSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PropertyPatternClauseSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PropertyPatternClauseSyntaxWrapper.cs index 00ed4c895a..76e450d284 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PropertyPatternClauseSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/PropertyPatternClauseSyntaxWrapper.cs @@ -3,111 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; - internal struct PropertyPatternClauseSyntaxWrapper : ISyntaxWrapper + internal partial struct PropertyPatternClauseSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.PropertyPatternClauseSyntax"; - private static readonly Type WrappedType; - - private static readonly Func OpenBraceTokenAccessor; - private static readonly Func> SubpatternsAccessor; - private static readonly Func CloseBraceTokenAccessor; - - private static readonly Func WithOpenBraceTokenAccessor; - private static readonly Func, CSharpSyntaxNode> WithSubpatternsAccessor; - private static readonly Func WithCloseBraceTokenAccessor; - - private readonly CSharpSyntaxNode node; - - static PropertyPatternClauseSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(PropertyPatternClauseSyntaxWrapper)); - OpenBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBraceToken)); - SubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Subpatterns)); - CloseBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBraceToken)); - - WithOpenBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBraceToken)); - WithSubpatternsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Subpatterns)); - WithCloseBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBraceToken)); - } - - private PropertyPatternClauseSyntaxWrapper(CSharpSyntaxNode node) - { - this.node = node; - } - - public CSharpSyntaxNode SyntaxNode => this.node; - - public SyntaxToken OpenBraceToken - { - get - { - return OpenBraceTokenAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxListWrapper Subpatterns - { - get - { - return SubpatternsAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseBraceToken - { - get - { - return CloseBraceTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator PropertyPatternClauseSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new PropertyPatternClauseSyntaxWrapper((CSharpSyntaxNode)node); - } - - public static implicit operator CSharpSyntaxNode(PropertyPatternClauseSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public PropertyPatternClauseSyntaxWrapper AddSubpatterns(params SubpatternSyntaxWrapper[] items) { return new PropertyPatternClauseSyntaxWrapper(this.WithSubpatterns(this.Subpatterns.AddRange(items))); } - - public PropertyPatternClauseSyntaxWrapper WithOpenBraceToken(SyntaxToken openBraceToken) - { - return new PropertyPatternClauseSyntaxWrapper(WithOpenBraceTokenAccessor(this.SyntaxNode, openBraceToken)); - } - - public PropertyPatternClauseSyntaxWrapper WithSubpatterns(SeparatedSyntaxListWrapper subpatterns) - { - return new PropertyPatternClauseSyntaxWrapper(WithSubpatternsAccessor(this.SyntaxNode, subpatterns)); - } - - public PropertyPatternClauseSyntaxWrapper WithCloseBraceToken(SyntaxToken closeBraceToken) - { - return new PropertyPatternClauseSyntaxWrapper(WithCloseBraceTokenAccessor(this.SyntaxNode, closeBraceToken)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RecursivePatternSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RecursivePatternSyntaxWrapper.cs index 2a3f695db9..6937995123 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RecursivePatternSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/RecursivePatternSyntaxWrapper.cs @@ -3,116 +3,10 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; - using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct RecursivePatternSyntaxWrapper : ISyntaxWrapper + internal partial struct RecursivePatternSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.RecursivePatternSyntax"; - private static readonly Type WrappedType; - - private static readonly Func TypeAccessor; - private static readonly Func PositionalPatternClauseAccessor; - private static readonly Func PropertyPatternClauseAccessor; - private static readonly Func DesignationAccessor; - - private static readonly Func WithTypeAccessor; - private static readonly Func WithPositionalPatternClauseAccessor; - private static readonly Func WithPropertyPatternClauseAccessor; - private static readonly Func WithDesignationAccessor; - - private readonly CSharpSyntaxNode node; - - static RecursivePatternSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(RecursivePatternSyntaxWrapper)); - TypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Type)); - PositionalPatternClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(PositionalPatternClause)); - PropertyPatternClauseAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(PropertyPatternClause)); - DesignationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(Designation)); - - WithTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Type)); - WithPositionalPatternClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(PositionalPatternClause)); - WithPropertyPatternClauseAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(PropertyPatternClause)); - WithDesignationAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(Designation)); - } - - private RecursivePatternSyntaxWrapper(CSharpSyntaxNode node) - { - this.node = node; - } - - public CSharpSyntaxNode SyntaxNode => this.node; - - public TypeSyntax Type - { - get - { - return TypeAccessor(this.SyntaxNode); - } - } - - public PositionalPatternClauseSyntaxWrapper PositionalPatternClause - { - get - { - return (PositionalPatternClauseSyntaxWrapper)PositionalPatternClauseAccessor(this.SyntaxNode); - } - } - - public PropertyPatternClauseSyntaxWrapper PropertyPatternClause - { - get - { - return (PropertyPatternClauseSyntaxWrapper)PropertyPatternClauseAccessor(this.SyntaxNode); - } - } - - public VariableDesignationSyntaxWrapper Designation - { - get - { - return (VariableDesignationSyntaxWrapper)DesignationAccessor(this.SyntaxNode); - } - } - - public static explicit operator RecursivePatternSyntaxWrapper(PatternSyntaxWrapper node) - { - return (RecursivePatternSyntaxWrapper)node.SyntaxNode; - } - - public static explicit operator RecursivePatternSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new RecursivePatternSyntaxWrapper((CSharpSyntaxNode)node); - } - - public static implicit operator PatternSyntaxWrapper(RecursivePatternSyntaxWrapper wrapper) - { - return PatternSyntaxWrapper.FromUpcast(wrapper.node); - } - - public static implicit operator CSharpSyntaxNode(RecursivePatternSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public RecursivePatternSyntaxWrapper AddPositionalPatternClauseSubpatterns(params SubpatternSyntaxWrapper[] items) { var positionalPatternClause = this.PositionalPatternClause; @@ -134,25 +28,5 @@ public RecursivePatternSyntaxWrapper AddPropertyPatternClauseSubpatterns(params return this.WithPropertyPatternClause(propertyPatternClause.WithSubpatterns(propertyPatternClause.Subpatterns.AddRange(items))); } - - public RecursivePatternSyntaxWrapper WithType(TypeSyntax type) - { - return new RecursivePatternSyntaxWrapper(WithTypeAccessor(this.SyntaxNode, type)); - } - - public RecursivePatternSyntaxWrapper WithPositionalPatternClause(PositionalPatternClauseSyntaxWrapper positionalPatternClause) - { - return new RecursivePatternSyntaxWrapper(WithPositionalPatternClauseAccessor(this.SyntaxNode, positionalPatternClause)); - } - - public RecursivePatternSyntaxWrapper WithPropertyPatternClause(PropertyPatternClauseSyntaxWrapper propertyPatternClause) - { - return new RecursivePatternSyntaxWrapper(WithPropertyPatternClauseAccessor(this.SyntaxNode, propertyPatternClause)); - } - - public RecursivePatternSyntaxWrapper WithDesignation(VariableDesignationSyntaxWrapper designation) - { - return new RecursivePatternSyntaxWrapper(WithDesignationAccessor(this.SyntaxNode, designation)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/StatementSyntaxExtensions.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/StatementSyntaxExtensions.cs new file mode 100644 index 0000000000..ec95388a97 --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/StatementSyntaxExtensions.cs @@ -0,0 +1,36 @@ +// 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 Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp.Syntax; + + internal static class StatementSyntaxExtensions + { + private static readonly Func> AttributeListsAccessor; + private static readonly Func, StatementSyntax> WithAttributeListsAccessor; + + static StatementSyntaxExtensions() + { + AttributeListsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(typeof(StatementSyntax), nameof(AttributeLists)); + WithAttributeListsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(typeof(StatementSyntax), nameof(AttributeLists)); + } + + public static SyntaxList AttributeLists(this StatementSyntax syntax) + { + return AttributeListsAccessor(syntax); + } + + public static StatementSyntax WithAttributeLists(this StatementSyntax syntax, SyntaxList attributeLists) + { + return WithAttributeListsAccessor(syntax, attributeLists); + } + + public static StatementSyntax AddAttributeLists(this StatementSyntax syntax, params AttributeListSyntax[] items) + { + return syntax.WithAttributeLists(syntax.AttributeLists().AddRange(items)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionSyntaxWrapper.cs index a0cc138414..984eccef53 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SwitchExpressionSyntaxWrapper.cs @@ -3,145 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct SwitchExpressionSyntaxWrapper : ISyntaxWrapper + internal partial struct SwitchExpressionSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax"; - - private static readonly Type WrappedType; - private static readonly Func> ArmsAccessor; - private static readonly Func GoverningExpressionAccessor; - private static readonly Func OpenBraceTokenAccessor; - private static readonly Func SwitchKeywordAccessor; - private static readonly Func CloseBraceTokenAccessor; - - private static readonly Func, ExpressionSyntax> WithArmsAccessor; - private static readonly Func WithGoverningExpressionAccessor; - private static readonly Func WithOpenBraceTokenAccessor; - private static readonly Func WithSwitchKeywordAccessor; - private static readonly Func WithCloseBraceTokenAccessor; - - private readonly ExpressionSyntax node; - - static SwitchExpressionSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(SwitchExpressionSyntaxWrapper)); - ArmsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Arms)); - GoverningExpressionAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(GoverningExpression)); - OpenBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenBraceToken)); - SwitchKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(SwitchKeyword)); - CloseBraceTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseBraceToken)); - - WithArmsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Arms)); - WithGoverningExpressionAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(GoverningExpression)); - WithOpenBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenBraceToken)); - WithSwitchKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(SwitchKeyword)); - WithCloseBraceTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseBraceToken)); - } - - private SwitchExpressionSyntaxWrapper(ExpressionSyntax node) - { - this.node = node; - } - - public ExpressionSyntax SyntaxNode => this.node; - - public ExpressionSyntax GoverningExpression - { - get - { - return GoverningExpressionAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxListWrapper Arms - { - get - { - return ArmsAccessor(this.SyntaxNode); - } - } - - public SyntaxToken OpenBraceToken - { - get - { - return OpenBraceTokenAccessor(this.SyntaxNode); - } - } - - public SyntaxToken SwitchKeyword - { - get - { - return SwitchKeywordAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseBraceToken - { - get - { - return CloseBraceTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator SwitchExpressionSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new SwitchExpressionSyntaxWrapper((ExpressionSyntax)node); - } - - public static implicit operator ExpressionSyntax(SwitchExpressionSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public SwitchExpressionSyntaxWrapper AddArms(params SwitchExpressionArmSyntaxWrapper[] arms) { return new SwitchExpressionSyntaxWrapper(this.WithArms(this.Arms.AddRange(arms))); } - - public SwitchExpressionSyntaxWrapper WithArms(SeparatedSyntaxListWrapper arms) - { - return new SwitchExpressionSyntaxWrapper(WithArmsAccessor(this.SyntaxNode, arms)); - } - - public SwitchExpressionSyntaxWrapper WithCloseBraceToken(SyntaxToken closeBraceToken) - { - return new SwitchExpressionSyntaxWrapper(WithCloseBraceTokenAccessor(this.SyntaxNode, closeBraceToken)); - } - - public SwitchExpressionSyntaxWrapper WithGoverningExpression(ExpressionSyntax expression) - { - return new SwitchExpressionSyntaxWrapper(WithGoverningExpressionAccessor(this.SyntaxNode, expression)); - } - - public SwitchExpressionSyntaxWrapper WithOpenBraceToken(SyntaxToken openBraceToken) - { - return new SwitchExpressionSyntaxWrapper(WithOpenBraceTokenAccessor(this.SyntaxNode, openBraceToken)); - } - - public SwitchExpressionSyntaxWrapper WithSwitchKeyword(SyntaxToken switchKeyword) - { - return new SwitchExpressionSyntaxWrapper(WithSwitchKeywordAccessor(this.SyntaxNode, switchKeyword)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml new file mode 100644 index 0000000000..f24059e17a --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/Syntax.xml @@ -0,0 +1,4848 @@ + + + + + + + + + + + + + Provides the base class from which the classes that represent name syntax nodes are derived. This is an abstract class. + + + + + + SyntaxToken representing the identifier of the simple name. + + + + + Provides the base class from which the classes that represent simple name syntax nodes are derived. This is an abstract class. + + + + + + + + + SyntaxToken representing the keyword for the kind of the identifier name. + + + + Class which represents the syntax node for identifier name. + + + Creates an IdentifierNameSyntax node. + + + + + + + NameSyntax node representing the name on the left side of the dot token of the qualified name. + + + + + + SyntaxToken representing the dot. + + + + + SimpleNameSyntax node representing the name on the right side of the dot token of the qualified name. + + + + Class which represents the syntax node for qualified name. + + + Creates a QualifiedNameSyntax node. + + + + + + + + SyntaxToken representing the name of the identifier of the generic name. + + + + + TypeArgumentListSyntax node representing the list of type arguments of the generic name. + + + + Class which represents the syntax node for generic name. + + + Creates a GenericNameSyntax node. + + + + + + + + SyntaxToken representing less than. + + + + + SeparatedSyntaxList of TypeSyntax node representing the type arguments. + + + + + + SyntaxToken representing greater than. + + + + Class which represents the syntax node for type argument list. + + + Creates a TypeArgumentListSyntax node. + + + + + + + IdentifierNameSyntax node representing the name of the alias + + + + + + SyntaxToken representing colon colon. + + + + + SimpleNameSyntax node representing the name that is being alias qualified. + + + + Class which represents the syntax node for alias qualified name. + + + Creates an AliasQualifiedNameSyntax node. + + + + + + Provides the base class from which the classes that represent type syntax nodes are derived. This is an abstract class. + + + + + + + + + + + + + + + + + + + + + + + SyntaxToken which represents the keyword corresponding to the predefined type. + + + + Class which represents the syntax node for predefined types. + + + Creates a PredefinedTypeSyntax node. + + + + + + + TypeSyntax node representing the type of the element of the array. + + + + + SyntaxList of ArrayRankSpecifierSyntax nodes representing the list of rank specifiers for the array. + + + + Class which represents the syntax node for the array type. + + + Creates an ArrayTypeSyntax node. + + + + + + + + + + + + + + + + + TypeSyntax node that represents the element type of the pointer. + + + + + + SyntaxToken representing the asterisk. + + + + Class which represents the syntax node for pointer type. + + + Creates a PointerTypeSyntax node. + + + + + + + + SyntaxToken representing the delegate keyword. + + + + + + SyntaxToken representing the asterisk. + + + + + Node representing the optional calling convention. + + + + + List of the parameter types and return type of the function pointer. + + + + + + Function pointer parameter list syntax. + + + + + + SyntaxToken representing the less than token. + + + + + SeparatedSyntaxList of ParameterSyntaxes representing the list of parameters and return type. + + + + + + SyntaxToken representing the greater than token. + + + + + + Function pointer calling convention syntax. + + + + + + + SyntaxToken representing whether the calling convention is managed or unmanaged. + + + + + Optional list of identifiers that will contribute to an unmanaged calling convention. + + + + + + Function pointer calling convention syntax. + + + + + + SyntaxToken representing open bracket. + + + + + SeparatedSyntaxList of calling convention identifiers. + + + + + + SyntaxToken representing close bracket. + + + + + + Individual function pointer unmanaged calling convention. + + + + + + SyntaxToken representing the calling convention identifier. + + + + + + + + TypeSyntax node representing the type of the element. + + + + + + SyntaxToken representing the question mark. + + + + Class which represents the syntax node for a nullable type. + + + Creates a NullableTypeSyntax node. + + + + + + + + SyntaxToken representing the open parenthesis. + + + + + + + SyntaxToken representing the close parenthesis. + + + + Class which represents the syntax node for tuple type. + + + Creates a TupleTypeSyntax node. + + + + + Tuple type element. + + + + + Gets the type of the tuple element. + + + + + Gets the name of the tuple element. + + + + + + + + + + SyntaxToken representing the omitted type argument. + + + + Class which represents a placeholder in the type argument list of an unbound generic type. + + + Creates an OmittedTypeArgumentSyntax node. + + + + + The ref modifier of a method's return value or a local. + + + + + + + + + Gets the optional "readonly" keyword. + + + + + + + + + Provides the base class from which the classes that represent expression syntax nodes are derived. This is an abstract class. + + + + + + + + SyntaxToken representing the open parenthesis. + + + + + ExpressionSyntax node representing the expression enclosed within the parenthesis. + + + + + + SyntaxToken representing the close parenthesis. + + + + Class which represents the syntax node for parenthesized expression. + + + Creates a ParenthesizedExpressionSyntax node. + + + + + + + + SyntaxToken representing the open parenthesis. + + + + + SeparatedSyntaxList of ArgumentSyntax representing the list of arguments. + + + + + + SyntaxToken representing the close parenthesis. + + + + Class which represents the syntax node for tuple expression. + + + Creates a TupleExpressionSyntax node. + + + + + + + + + + + + + + + + + + + + + + " + + SyntaxToken representing the kind of the operator of the prefix unary expression. + + + + + ExpressionSyntax representing the operand of the prefix unary expression. + + + + Class which represents the syntax node for prefix unary expression. + + + Creates a PrefixUnaryExpressionSyntax node. + + + + + + + + SyntaxToken representing the kind "await" keyword. + + + + + ExpressionSyntax representing the operand of the "await" operator. + + + + Class which represents the syntax node for an "await" expression. + + + Creates an AwaitExpressionSyntax node. + + + + + + + + + ExpressionSyntax representing the operand of the postfix unary expression. + + + + + + + + SyntaxToken representing the kind of the operator of the postfix unary expression. + + + + Class which represents the syntax node for postfix unary expression. + + + Creates a PostfixUnaryExpressionSyntax node. + + + + + + + + ExpressionSyntax node representing the object that the member belongs to. + + + + + + + SyntaxToken representing the kind of the operator in the member access expression. + + + + + SimpleNameSyntax node representing the member being accessed. + + + + Class which represents the syntax node for member access expression. + + + Creates a MemberAccessExpressionSyntax node. + + + + + + + ExpressionSyntax node representing the object conditionally accessed. + + + + + + SyntaxToken representing the question mark. + + + + + ExpressionSyntax node representing the access expression to be executed when the object is not null. + + + + Class which represents the syntax node for conditional access expression. + + + Creates a ConditionalAccessExpressionSyntax node. + + + + + + + + SyntaxToken representing dot. + + + + + SimpleNameSyntax node representing the member being bound to. + + + + Class which represents the syntax node for member binding expression. + + + Creates a MemberBindingExpressionSyntax node. + + + + + + + BracketedArgumentListSyntax node representing the list of arguments of the element binding expression. + + + + Class which represents the syntax node for element binding expression. + + + Creates an ElementBindingExpressionSyntax node. + + + + + + + ExpressionSyntax node representing the expression on the left of the range operator. + + + + + + SyntaxToken representing the operator of the range expression. + + + + + ExpressionSyntax node representing the expression on the right of the range operator. + + + + Class which represents the syntax node for a range expression. + + + Creates an RangeExpressionSyntax node. + + + + + + + BracketedArgumentListSyntax node representing the list of arguments of the implicit element access expression. + + + + Class which represents the syntax node for implicit element access expression. + + + Creates an ImplicitElementAccessSyntax node. + + + + + + + + + + + + + + + + + + + + + + + + + + + ExpressionSyntax node representing the expression on the left of the binary operator. + + + + + + + + + + + + + + + + + + + + + + + + + + SyntaxToken representing the operator of the binary expression. + + + + + ExpressionSyntax node representing the expression on the right of the binary operator. + + + + Class which represents an expression that has a binary operator. + + + Creates a BinaryExpressionSyntax node. + + + + + + + + + + + + + + + + + + ExpressionSyntax node representing the expression on the left of the assignment operator. + + + + + + + + + + + + + + + + + SyntaxToken representing the operator of the assignment expression. + + + + + ExpressionSyntax node representing the expression on the right of the assignment operator. + + + + Class which represents an expression that has an assignment operator. + + + Creates an AssignmentExpressionSyntax node. + + + + + + + ExpressionSyntax node representing the condition of the conditional expression. + + + + + + SyntaxToken representing the question mark. + + + + + ExpressionSyntax node representing the expression to be executed when the condition is true. + + + + + + SyntaxToken representing the colon. + + + + + ExpressionSyntax node representing the expression to be executed when the condition is false. + + + + Class which represents the syntax node for conditional expression. + + + Creates a ConditionalExpressionSyntax node. + + + + + Provides the base class from which the classes that represent instance expression syntax nodes are derived. This is an abstract class. + + + + + + + + SyntaxToken representing the this keyword. + + + + Class which represents the syntax node for a this expression. + + + Creates a ThisExpressionSyntax node. + + + + + + + + SyntaxToken representing the base keyword. + + + + Class which represents the syntax node for a base expression. + + + Creates a BaseExpressionSyntax node. + + + + + + + + + + + + + + + + + + + + + + SyntaxToken representing the keyword corresponding to the kind of the literal expression. + + + + Class which represents the syntax node for a literal expression. + + + Creates a LiteralExpressionSyntax node. + + + + + + + + SyntaxToken representing the MakeRefKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Argument of the primary function. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for MakeRef expression. + + + Creates a MakeRefExpressionSyntax node. + + + + + + + + SyntaxToken representing the RefTypeKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Argument of the primary function. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for RefType expression. + + + Creates a RefTypeExpressionSyntax node. + + + + + + + + SyntaxToken representing the RefValueKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Typed reference expression. + + + + + + Comma separating the arguments. + + + + + The type of the value. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for RefValue expression. + + + Creates a RefValueExpressionSyntax node. + + + + + + + + + + SyntaxToken representing the checked or unchecked keyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Argument of the primary function. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for Checked or Unchecked expression. + + + Creates a CheckedExpressionSyntax node. + + + + + + + + SyntaxToken representing the DefaultKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Argument of the primary function. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for Default expression. + + + Creates a DefaultExpressionSyntax node. + + + + + + + + SyntaxToken representing the TypeOfKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + The expression to return type of. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for TypeOf expression. + + + Creates a TypeOfExpressionSyntax node. + + + + + + + + SyntaxToken representing the SizeOfKeyword. + + + + + + SyntaxToken representing open parenthesis. + + + + + Argument of the primary function. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for SizeOf expression. + + + Creates a SizeOfExpressionSyntax node. + + + + + + + ExpressionSyntax node representing the expression part of the invocation. + + + + + ArgumentListSyntax node representing the list of arguments of the invocation expression. + + + + Class which represents the syntax node for invocation expression. + + + Creates an InvocationExpressionSyntax node. + + + + + + + ExpressionSyntax node representing the expression which is accessing the element. + + + + + BracketedArgumentListSyntax node representing the list of arguments of the element access expression. + + + + Class which represents the syntax node for element access expression. + + + Creates an ElementAccessExpressionSyntax node. + + + + + + SeparatedSyntaxList of ArgumentSyntax nodes representing the list of arguments. + + + + Provides the base class from which the classes that represent argument list syntax nodes are derived. This is an abstract class. + + + + + + + + SyntaxToken representing open parenthesis. + + + + + SeparatedSyntaxList of ArgumentSyntax representing the list of arguments. + + + + + + SyntaxToken representing close parenthesis. + + + + Class which represents the syntax node for the list of arguments. + + + Creates an ArgumentListSyntax node. + + + + + + + + SyntaxToken representing open bracket. + + + + + SeparatedSyntaxList of ArgumentSyntax representing the list of arguments. + + + + + + SyntaxToken representing close bracket. + + + + Class which represents the syntax node for bracketed argument list. + + + Creates a BracketedArgumentListSyntax node. + + + + + + + NameColonSyntax node representing the optional name arguments. + + + + + + + + SyntaxToken representing the optional ref or out keyword. + + + + + ExpressionSyntax node representing the argument. + + + + Class which represents the syntax node for argument. + + + Creates an ArgumentSyntax node. + + + + + + + + IdentifierNameSyntax representing the identifier name. + + + + + + SyntaxToken representing colon. + + + + Class which represents the syntax node for name colon syntax. + + + Creates a NameColonSyntax node. + + + + + + + + Declaration representing the variable declared in an out parameter or deconstruction. + + + + Class which represents the syntax node for the variable declaration in an out var declaration or a deconstruction declaration. + + + Creates a DeclarationExpression node. + + + + + + + + SyntaxToken representing the open parenthesis. + + + + + TypeSyntax node representing the type to which the expression is being cast. + + + + + + SyntaxToken representing the close parenthesis. + + + + + ExpressionSyntax node representing the expression that is being casted. + + + + Class which represents the syntax node for cast expression. + + + Creates a CastExpressionSyntax node. + + + + + Provides the base class from which the classes that represent anonymous function expressions are derived. + + + + + + + BlockSyntax node representing the body of the anonymous function. + Only one of Block or ExpressionBody will be non-null. + + + + + + + ExpressionSyntax node representing the body of the anonymous function. + Only one of Block or ExpressionBody will be non-null. + + + + + + + + + + + + SyntaxToken representing the delegate keyword. + + + + + List of parameters of the anonymous method expression, or null if there no parameters are specified. + + + + + + BlockSyntax node representing the body of the anonymous function. + This will never be null. + + + + + + + Inherited from AnonymousFunctionExpressionSyntax, but not used for + AnonymousMethodExpressionSyntax. This will always be null. + + + + + Class which represents the syntax node for anonymous method expression. + + + Creates an AnonymousMethodExpressionSyntax node. + + + + + Provides the base class from which the classes that represent lambda expressions are derived. + + + + + + SyntaxToken representing equals greater than. + + + + + + + + + + ParameterSyntax node representing the parameter of the lambda expression. + + + + + + + SyntaxToken representing equals greater than. + + + + + + + BlockSyntax node representing the body of the lambda. + Only one of Block or ExpressionBody will be non-null. + + + + + + + ExpressionSyntax node representing the body of the lambda. + Only one of Block or ExpressionBody will be non-null. + + + + + + Class which represents the syntax node for a simple lambda expression. + + + Creates a SimpleLambdaExpressionSyntax node. + + + + + + + + + + + + + + + ParameterListSyntax node representing the list of parameters for the lambda expression. + + + + + + + SyntaxToken representing equals greater than. + + + + + + + BlockSyntax node representing the body of the lambda. + Only one of Block or ExpressionBody will be non-null. + + + + + + + ExpressionSyntax node representing the body of the lambda. + Only one of Block or ExpressionBody will be non-null. + + + + + + Class which represents the syntax node for parenthesized lambda expression. + + + Creates a ParenthesizedLambdaExpressionSyntax node. + + + + + + + + + + + + SyntaxToken representing the open brace. + + + + + SeparatedSyntaxList of ExpressionSyntax representing the list of expressions in the initializer expression. + + + + + + SyntaxToken representing the close brace. + + + + Class which represents the syntax node for initializer expression. + + + Creates an InitializerExpressionSyntax node. + + + + + + + SyntaxToken representing the new keyword. + + + + + ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. + + + + + InitializerExpressionSyntax representing the initializer expression for the object being created. + + + + + + + + + SyntaxToken representing the new keyword. + + + + + ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. + + + + + InitializerExpressionSyntax representing the initializer expression for the object being created. + + + + Class which represents the syntax node for implicit object creation expression. + + + Creates an ImplicitObjectCreationExpressionSyntax node. + + + + + + + + SyntaxToken representing the new keyword. + + + + + TypeSyntax representing the type of the object being created. + + + + + ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. + + + + + InitializerExpressionSyntax representing the initializer expression for the object being created. + + + + Class which represents the syntax node for object creation expression. + + + Creates an ObjectCreationExpressionSyntax node. + + + + + + + + + + + InitializerExpressionSyntax representing the initializer expression for the with expression. + + + + + + + + NameEqualsSyntax representing the optional name of the member being initialized. + + + + + ExpressionSyntax representing the value the member is initialized with. + + + + Creates an AnonymousObjectMemberDeclaratorSyntax node. + + + + + + + + SyntaxToken representing the new keyword. + + + + + + SyntaxToken representing the open brace. + + + + + SeparatedSyntaxList of AnonymousObjectMemberDeclaratorSyntax representing the list of object member initializers. + + + + + + SyntaxToken representing the close brace. + + + + Class which represents the syntax node for anonymous object creation expression. + + + Creates an AnonymousObjectCreationExpressionSyntax node. + + + + + + + + SyntaxToken representing the new keyword. + + + + + ArrayTypeSyntax node representing the type of the array. + + + + + InitializerExpressionSyntax node representing the initializer of the array creation expression. + + + + Class which represents the syntax node for array creation expression. + + + Creates an ArrayCreationExpressionSyntax node. + + + + + + + + SyntaxToken representing the new keyword. + + + + + + SyntaxToken representing the open bracket. + + + + + SyntaxList of SyntaxToken representing the commas in the implicit array creation expression. + + + + + + SyntaxToken representing the close bracket. + + + + + InitializerExpressionSyntax representing the initializer expression of the implicit array creation expression. + + + + Class which represents the syntax node for implicit array creation expression. + + + Creates an ImplicitArrayCreationExpressionSyntax node. + + + + + + + + SyntaxToken representing the stackalloc keyword. + + + + + TypeSyntax node representing the type of the stackalloc array. + + + + + InitializerExpressionSyntax node representing the initializer of the stackalloc array creation expression. + + + + Class which represents the syntax node for stackalloc array creation expression. + + + Creates a StackAllocArrayCreationExpressionSyntax node. + + + + + + + + SyntaxToken representing the stackalloc keyword. + + + + + + SyntaxToken representing the open bracket. + + + + + + SyntaxToken representing the close bracket. + + + + + InitializerExpressionSyntax representing the initializer expression of the implicit stackalloc array creation expression. + + + + Class which represents the syntax node for implicit stackalloc array creation expression. + + + Creates an ImplicitStackAllocArrayCreationExpressionSyntax node. + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + SyntaxToken representing the omitted array size expression. + + + + Class which represents a placeholder in an array size list. + + + Creates an OmittedArraySizeExpressionSyntax node. + + + + + + + + + The first part of an interpolated string, $" or $@" + + + + + List of parts of the interpolated string, each one is either a literal part or an interpolation. + + + + + + The closing quote of the interpolated string. + + + + + + + + ExpressionSyntax node representing the expression on the left of the "is" operator. + + + + + + + + PatternSyntax node representing the pattern on the right of the "is" operator. + + + + Class which represents a simple pattern-matching expression using the "is" keyword. + + + Creates an IsPatternExpressionSyntax node. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ExpressionSyntax node representing the constant expression. + + + + + + + + + + + + + + + + + + + + + + + + + + SyntaxToken representing the operator of the relational pattern. + + + + + + + + + The type for the type pattern. + + + + + + + + + + + + + + + + + + + + + + + + + + + + The text contents of a part of the interpolated string. + + + + + + + + + + + + + + + + + + + + + + + + + + + The text contents of the format specifier for an interpolation. + + + + + + + + Always empty on a global statement. + + + Always empty on a global statement. + + + + + + Represents the base class for all statements syntax classes. + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + + + + + + + + + + + Gets the modifier list. + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + Gets a SyntaxToken that represents the colon following the statement's label. + + + + + Represents a labeled statement syntax. + + + Creates a LabeledStatementSyntax node + + + + + + + + + + + + Gets a SyntaxToken that represents the goto keyword. + + + + + + + + + Gets a SyntaxToken that represents the case or default keywords if any exists. + + + + + + + Gets a constant expression for a goto case statement. + + + + + + + + Gets a SyntaxToken that represents the semi-colon at the end of the statement. + + + + + + Represents a goto statement syntax + + + + + Creates a GotoStatementSyntax node. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The variable(s) of the loop. In correct code this is a tuple + literal, declaration expression with a tuple designator, or + a discard syntax in the form of a simple identifier. In broken + code it could be something else. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets a SyntaxToken that represents the if keyword. + + + + + + + + Gets a SyntaxToken that represents the open parenthesis before the if statement's condition expression. + + + + + + + Gets an ExpressionSyntax that represents the condition of the if statement. + + + + + + + + Gets a SyntaxToken that represents the close parenthesis after the if statement's condition expression. + + + + + + + Gets a StatementSyntax the represents the statement to be executed when the condition is true. + + + + + + + Gets an ElseClauseSyntax that represents the statement to be executed when the condition is false if such statement exists. + + + + + + Represents an if statement syntax. + + + + Creates an IfStatementSyntax node + + + + + + + + + Gets a syntax token + + + + + + Represents an else statement syntax. + + + Creates a ElseClauseSyntax node + + + + + + + + + + + Gets a SyntaxToken that represents the switch keyword. + + + + + + + + Gets a SyntaxToken that represents the open parenthesis preceding the switch governing expression. + + + + + + + Gets an ExpressionSyntax representing the expression of the switch statement. + + + + + + + + Gets a SyntaxToken that represents the close parenthesis following the switch governing expression. + + + + + + + + Gets a SyntaxToken that represents the open braces preceding the switch sections. + + + + + + + Gets a SyntaxList of SwitchSectionSyntax's that represents the switch sections of the switch statement. + + + + + + + + Gets a SyntaxToken that represents the open braces following the switch sections. + + + + + Represents a switch statement syntax. + + + Creates a SwitchStatementSyntax node. + + + + + + + + Gets a SyntaxList of SwitchLabelSyntax's the represents the possible labels that control can transfer to within the section. + + + + + + + Gets a SyntaxList of StatementSyntax's the represents the statements to be executed when control transfer to a label the belongs to the section. + + + + + Represents a switch section syntax of a switch statement. + + + Creates a SwitchSectionSyntax node. + + + + + + + Gets a SyntaxToken that represents a case or default keyword that belongs to a switch label. + + + + + + + + Gets a SyntaxToken that represents the colon that terminates the switch label. + + + + + Represents a switch label within a switch statement. + + + + + + + + Gets the case keyword token. + + + + + + Gets a PatternSyntax that represents the pattern that gets matched for the case label. + + + + + + + Represents a case label within a switch statement. + + + Creates a CaseMatchLabelSyntax node. + + + + + + + + Gets the case keyword token. + + + + + + Gets an ExpressionSyntax that represents the constant expression that gets matched for the case label. + + + + + + Represents a case label within a switch statement. + + + Creates a CaseSwitchLabelSyntax node. + + + + + + + + Gets the default keyword token. + + + + + Represents a default label within a switch statement. + + + Creates a DefaultSwitchLabelSyntax node. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the attribute declaration list. + + + + + + + + + + + + + SyntaxToken representing the extern keyword. + + + + + + SyntaxToken representing the alias keyword. + + + + + Gets the identifier. + + + + + + + SyntaxToken representing the semicolon token. + + + + + Represents an ExternAlias directive syntax, e.g. "extern alias MyAlias;" with specifying "/r:MyAlias=SomeAssembly.dll " on the compiler command line. + + + + Creates an ExternAliasDirectiveSyntax node + + + + + + + + + + + + + + + + + + + Member declaration syntax. + + + + Gets the attribute declaration list. + + + + + Gets the modifier list. + + + + + + + + + + + + + + + + + + + + + + + Gets the optional semicolon token. + + + + + + + Class representing one or more attributes applied to a language construct. + + + + + + Gets the open bracket token. + + + + + Gets the optional construct targeted by the attribute. + + + + + Gets the attribute declaration list. + + + + + + Gets the close bracket token. + + + + + + Class representing what language construct an attribute targets. + + + + + Gets the identifier. + + + + + + Gets the colon token. + + + + + + Attribute syntax. + + + + + Gets the name. + + + + + + + Attribute argument list syntax. + + + + + Gets the open paren token. + + + + + + Gets the arguments syntax list. + + + + + Gets the close paren token. + + + + + + + Attribute argument syntax. + + + + + + + + + Gets the expression. + + + + + + Class representing an identifier name followed by an equals token. + + + + + Gets the identifier name. + + + + + + + + + + Type parameter list syntax. + + + + + Gets the < token. + + + + + + Gets the parameter list. + + + + + Gets the > token. + + + + + + + Type parameter syntax. + + + + + Gets the attribute declaration list. + + + + + + + + + Gets the identifier. + + + + + + + Base class for type declaration syntax. + + + + Gets the identifier. + + + + + + Gets the base type list. + + + + + Gets the open brace token. + + + + + + Gets the close brace token. + + + + + + Gets the optional semicolon token. + + + + + + + Base class for type declaration syntax (class, struct, interface, record). + + + + Gets the type keyword token ("class", "struct", "interface", "record"). + + + + + + Gets the type constraint list. + + + + + Gets the member declarations. + + + + + + Class type declaration syntax. + + + + + + + Gets the class keyword token. + + + + + + + + + + + + + + + + + + + + + + + Struct type declaration syntax. + + + + + + + Gets the struct keyword token. + + + + + + + + + + + + + + + + + + + + + + + Interface type declaration syntax. + + + + + + + Gets the interface keyword token. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Enum type declaration syntax. + + + + + + + Gets the enum keyword token. + + + + + + + + + + + + + + Gets the members declaration list. + + + + + + + + Gets the optional semicolon token. + + + + + + + Delegate declaration syntax. + + + + + + + Gets the "delegate" keyword. + + + + + + Gets the return type. + + + + + Gets the identifier. + + + + + + + Gets the parameter list. + + + + + Gets the constraint clause list. + + + + + Gets the semicolon token. + + + + + + + + + + + Gets the identifier. + + + + + + + + Base list syntax. + + + + + Gets the colon token. + + + + + + Gets the base type references. + + + + + + + Provides the base class from which the classes that represent base type syntax nodes are derived. This is an abstract class. + + + + + + + + + + + + + + + + + + + + Type parameter constraint clause. + + + + + + + + Gets the identifier. + + + + + + Gets the colon token. + + + + + + Gets the constraints list. + + + + + + Base type for type parameter constraint syntax. + + + + + Constructor constraint syntax. + + + + + Gets the "new" keyword. + + + + + + Gets the open paren keyword. + + + + + + Gets the close paren keyword. + + + + + + + Class or struct constraint syntax. + + + + + + Gets the constraint keyword ("class" or "struct"). + + + + + + + + SyntaxToken representing the question mark. + + + + + + Type constraint syntax. + + + + + Gets the type syntax. + + + + + + Default constraint syntax. + + + + + Gets the "default" keyword. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Base type for method declaration syntax. + + + + Gets the parameter list. + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + Method declaration syntax. + + + + + + + Gets the return type syntax. + + + + + + Gets the identifier. + + + + + + + + Gets the constraint clause list. + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + + Operator declaration syntax. + + + + + + + Gets the return type. + + + + + Gets the "operator" keyword. + + + + + + Gets the operator token. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + + Conversion operator declaration syntax. + + + + + + + Gets the "implicit" or "explicit" token. + + + + + + + Gets the "operator" token. + + + + + + Gets the type. + + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + Constructor declaration syntax. + + + + + + + Gets the identifier. + + + + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + Constructor initializer syntax. + + + + + + Gets the colon token. + + + + + + Gets the "this" or "base" keyword. + + + + + + + + + Destructor declaration syntax. + + + + + + + Gets the tilde token. + + + + + + Gets the identifier. + + + + + + + + + + + Gets the optional semicolon token. + + + + + + + + + Base type for property declaration syntax. + + + + Gets the type syntax. + + + + + Gets the optional explicit interface specifier. + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + The syntax for the expression body of an expression-bodied member. + + + + + + + + + + + + + + + + + + + Gets the identifier. + + + + + + + + + + + + + + + + + + + + + + Gets the parameter list. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Gets the attribute declaration list. + + + + + Gets the modifier list. + + + + + + + + + + + Gets the keyword token, or identifier if an erroneous accessor declaration. + + + + + + Gets the optional body block which may be empty, but it is null if there are no braces. + + + + + + Gets the optional expression body. + + + + + Gets the optional semicolon token. + + + + + + + + + Base type for parameter list syntax. + + + + Gets the parameter list. + + + + + + Parameter list syntax. + + + + + Gets the open paren token. + + + + + + + Gets the close paren token. + + + + + + + Parameter list syntax with surrounding brackets. + + + + + Gets the open bracket token. + + + + + + + Gets the close bracket token. + + + + + + + Base parameter syntax. + + + + Gets the attribute declaration list. + + + + + Gets the modifier list. + + + + + + + Parameter syntax. + + + + + Gets the attribute declaration list. + + + + + Gets the modifier list. + + + + + + Gets the identifier. + + + + + + + + + Parameter syntax. + + + + + Gets the attribute declaration list. + + + + + Gets the modifier list. + + + + + + n + + + + + + + + + + + + + + + + + + + + + + + A symbol referenced by a cref attribute (e.g. in a <see> or <seealso> documentation comment tag). + For example, the M in <see cref="M" />. + + + + + + + A symbol reference that definitely refers to a type. + For example, "int", "A::B", "A.B", "A<T>", but not "M()" (has parameter list) or "this" (indexer). + NOTE: TypeCrefSyntax, QualifiedCrefSyntax, and MemberCrefSyntax overlap. The syntax in a TypeCrefSyntax + will always be bound as type, so it's safer to use QualifiedCrefSyntax or MemberCrefSyntax if the symbol + might be a non-type member. + + + + + + + + + A symbol reference to a type or non-type member that is qualified by an enclosing type or namespace. + For example, cref="System.String.ToString()". + NOTE: TypeCrefSyntax, QualifiedCrefSyntax, and MemberCrefSyntax overlap. The syntax in a TypeCrefSyntax + will always be bound as type, so it's safer to use QualifiedCrefSyntax or MemberCrefSyntax if the symbol + might be a non-type member. + + + + + + + + + + + + + The unqualified part of a CrefSyntax. + For example, "ToString()" in "object.ToString()". + NOTE: TypeCrefSyntax, QualifiedCrefSyntax, and MemberCrefSyntax overlap. The syntax in a TypeCrefSyntax + will always be bound as type, so it's safer to use QualifiedCrefSyntax or MemberCrefSyntax if the symbol + might be a non-type member. + + + + + + + A MemberCrefSyntax specified by a name (an identifier, predefined type keyword, or an alias-qualified name, + with an optional type parameter list) and an optional parameter list. + For example, "M", "M<T>" or "M(int)". + Also, "A::B()" or "string()". + + + + + + + + + + A MemberCrefSyntax specified by a this keyword and an optional parameter list. + For example, "this" or "this[int]". + + + + + + + + + + + + A MemberCrefSyntax specified by an operator keyword, an operator symbol and an optional parameter list. + For example, "operator +" or "operator -[int]". + NOTE: the operator must be overloadable. + + + + + + + + + Gets the operator token. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A MemberCrefSyntax specified by an implicit or explicit keyword, an operator keyword, a destination type, and an optional parameter list. + For example, "implicit operator int" or "explicit operator MyType(int)". + + + + + + + + + + + + + + + + + A list of cref parameters with surrounding punctuation. + Unlike regular parameters, cref parameters do not have names. + + + + + Gets the parameter list. + + + + + + + A parenthesized list of cref parameters. + + + + + + Gets the open paren token. + + + + + + + Gets the close paren token. + + + + + + + + A bracketed list of cref parameters. + + + + + + Gets the open bracket token. + + + + + + + Gets the close bracket token. + + + + + + + + An element of a BaseCrefParameterListSyntax. + Unlike a regular parameter, a cref parameter has only an optional ref or out keyword and a type - + there is no name and there are no attributes or other modifiers. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactoryEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactoryEx.cs index 4a1a8e35c8..e4999cb5a9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactoryEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxFactoryEx.cs @@ -27,7 +27,7 @@ internal static class SyntaxFactoryEx static SyntaxFactoryEx() { var positionalPatternClauseMethods = typeof(SyntaxFactory).GetTypeInfo().GetDeclaredMethods(nameof(PositionalPatternClause)); - var positionalPatternClauseMethod = positionalPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)))); + var positionalPatternClauseMethod = positionalPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)))); if (positionalPatternClauseMethod is object) { var subpatternsParameter = Expression.Parameter(typeof(SeparatedSyntaxListWrapper), "subpatterns"); @@ -49,7 +49,7 @@ static SyntaxFactoryEx() positionalPatternClauseMethod = positionalPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 3 && method.GetParameters()[0].ParameterType == typeof(SyntaxToken) - && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper))) + && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper))) && method.GetParameters()[2].ParameterType == typeof(SyntaxToken)); if (positionalPatternClauseMethod is object) { @@ -79,7 +79,7 @@ static SyntaxFactoryEx() } var propertyPatternClauseMethods = typeof(SyntaxFactory).GetTypeInfo().GetDeclaredMethods(nameof(PropertyPatternClause)); - var propertyPatternClauseMethod = propertyPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)))); + var propertyPatternClauseMethod = propertyPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper)))); if (propertyPatternClauseMethod is object) { var subpatternsParameter = Expression.Parameter(typeof(SeparatedSyntaxListWrapper), "subpatterns"); @@ -101,7 +101,7 @@ static SyntaxFactoryEx() propertyPatternClauseMethod = propertyPatternClauseMethods.FirstOrDefault(method => method.GetParameters().Length == 3 && method.GetParameters()[0].ParameterType == typeof(SyntaxToken) - && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper))) + && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(SubpatternSyntaxWrapper))) && method.GetParameters()[2].ParameterType == typeof(SyntaxToken)); if (propertyPatternClauseMethod is object) { @@ -202,7 +202,7 @@ static SyntaxFactoryEx() } var tupleTypeMethods = typeof(SyntaxFactory).GetTypeInfo().GetDeclaredMethods(nameof(TupleType)); - var tupleTypeMethod = tupleTypeMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)))); + var tupleTypeMethod = tupleTypeMethods.FirstOrDefault(method => method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper)))); if (tupleTypeMethod is object) { var elementsParameter = Expression.Parameter(typeof(SeparatedSyntaxListWrapper), "elements"); @@ -224,7 +224,7 @@ static SyntaxFactoryEx() tupleTypeMethod = tupleTypeMethods.FirstOrDefault(method => method.GetParameters().Length == 3 && method.GetParameters()[0].ParameterType == typeof(SyntaxToken) - && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(WrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper))) + && method.GetParameters()[1].ParameterType == typeof(SeparatedSyntaxList<>).MakeGenericType(SyntaxWrapperHelper.GetWrappedType(typeof(TupleElementSyntaxWrapper))) && method.GetParameters()[2].ParameterType == typeof(SyntaxToken)); if (tupleTypeMethod is object) { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs index a3278f1f4a..43a961d94b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleExpressionSyntaxWrapper.cs @@ -3,109 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct TupleExpressionSyntaxWrapper : ISyntaxWrapper + internal partial struct TupleExpressionSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TupleExpressionSyntax"; - private static readonly Type WrappedType; - - private static readonly Func OpenParenTokenAccessor; - private static readonly Func> ArgumentsAccessor; - private static readonly Func CloseParenTokenAccessor; - private static readonly Func WithOpenParenTokenAccessor; - private static readonly Func, ExpressionSyntax> WithArgumentsAccessor; - private static readonly Func WithCloseParenTokenAccessor; - - private readonly ExpressionSyntax node; - - static TupleExpressionSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(TupleExpressionSyntaxWrapper)); - OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); - ArgumentsAccessor = LightupHelpers.CreateSyntaxPropertyAccessor>(WrappedType, nameof(Arguments)); - CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); - WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); - WithArgumentsAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor>(WrappedType, nameof(Arguments)); - WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); - } - - private TupleExpressionSyntaxWrapper(ExpressionSyntax node) - { - this.node = node; - } - - public ExpressionSyntax SyntaxNode => this.node; - - public SyntaxToken OpenParenToken - { - get - { - return OpenParenTokenAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxList Arguments - { - get - { - return ArgumentsAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseParenToken - { - get - { - return CloseParenTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator TupleExpressionSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new TupleExpressionSyntaxWrapper((ExpressionSyntax)node); - } - - public static implicit operator ExpressionSyntax(TupleExpressionSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public TupleExpressionSyntaxWrapper AddArguments(params ArgumentSyntax[] items) { return new TupleExpressionSyntaxWrapper(this.WithArguments(this.Arguments.AddRange(items))); } - - public TupleExpressionSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) - { - return new TupleExpressionSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); - } - - public TupleExpressionSyntaxWrapper WithArguments(SeparatedSyntaxList arguments) - { - return new TupleExpressionSyntaxWrapper(WithArgumentsAccessor(this.SyntaxNode, arguments)); - } - - public TupleExpressionSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) - { - return new TupleExpressionSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs index 1fa39b5214..bef163710c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/TupleTypeSyntaxWrapper.cs @@ -3,109 +3,13 @@ namespace StyleCop.Analyzers.Lightup { - using System; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; - internal struct TupleTypeSyntaxWrapper : ISyntaxWrapper + internal partial struct TupleTypeSyntaxWrapper : ISyntaxWrapper { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.CSharp.Syntax.TupleTypeSyntax"; - private static readonly Type WrappedType; - - private static readonly Func OpenParenTokenAccessor; - private static readonly Func> ElementsAccessor; - private static readonly Func CloseParenTokenAccessor; - private static readonly Func WithOpenParenTokenAccessor; - private static readonly Func, TypeSyntax> WithElementsAccessor; - private static readonly Func WithCloseParenTokenAccessor; - - private readonly TypeSyntax node; - - static TupleTypeSyntaxWrapper() - { - WrappedType = WrapperHelper.GetWrappedType(typeof(TupleTypeSyntaxWrapper)); - OpenParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(OpenParenToken)); - ElementsAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor(WrappedType, nameof(Elements)); - CloseParenTokenAccessor = LightupHelpers.CreateSyntaxPropertyAccessor(WrappedType, nameof(CloseParenToken)); - WithOpenParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(OpenParenToken)); - WithElementsAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor(WrappedType, nameof(Elements)); - WithCloseParenTokenAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor(WrappedType, nameof(CloseParenToken)); - } - - private TupleTypeSyntaxWrapper(TypeSyntax node) - { - this.node = node; - } - - public TypeSyntax SyntaxNode => this.node; - - public SyntaxToken OpenParenToken - { - get - { - return OpenParenTokenAccessor(this.SyntaxNode); - } - } - - public SeparatedSyntaxListWrapper Elements - { - get - { - return ElementsAccessor(this.SyntaxNode); - } - } - - public SyntaxToken CloseParenToken - { - get - { - return CloseParenTokenAccessor(this.SyntaxNode); - } - } - - public static explicit operator TupleTypeSyntaxWrapper(SyntaxNode node) - { - if (node == null) - { - return default; - } - - if (!IsInstance(node)) - { - throw new InvalidCastException($"Cannot cast '{node.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new TupleTypeSyntaxWrapper((TypeSyntax)node); - } - - public static implicit operator TypeSyntax(TupleTypeSyntaxWrapper wrapper) - { - return wrapper.node; - } - - public static bool IsInstance(SyntaxNode node) - { - return node != null && LightupHelpers.CanWrapNode(node, WrappedType); - } - public TupleTypeSyntaxWrapper AddElements(params TupleElementSyntaxWrapper[] items) { return new TupleTypeSyntaxWrapper(this.WithElements(this.Elements.AddRange(items))); } - - public TupleTypeSyntaxWrapper WithOpenParenToken(SyntaxToken openParenToken) - { - return new TupleTypeSyntaxWrapper(WithOpenParenTokenAccessor(this.SyntaxNode, openParenToken)); - } - - public TupleTypeSyntaxWrapper WithElements(SeparatedSyntaxListWrapper elements) - { - return new TupleTypeSyntaxWrapper(WithElementsAccessor(this.SyntaxNode, elements)); - } - - public TupleTypeSyntaxWrapper WithCloseParenToken(SyntaxToken closeParenToken) - { - return new TupleTypeSyntaxWrapper(WithCloseParenTokenAccessor(this.SyntaxNode, closeParenToken)); - } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj b/StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj index b71878104c..bafb2794e8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj +++ b/StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj @@ -34,6 +34,7 @@ +