\n \n Add 'this.'\n Agregar \"this.\"\n \n \n \n Convert 'typeof' to 'nameof'\n Convertir \"typeof\" en \"nameof\"\n \n \n \n Pass in captured variables as arguments\n Pasar variables capturadas como argumentos\n \n \n \n Place colon on following line\n Colocar dos puntos en la línea siguiente\n \n \n \n Place statement on following line\n Instrucción de colocación en la línea siguiente\n \n \n \n Remove Unnecessary Usings\n Eliminar instrucciones Using innecesarias\n \n \n \n Remove blank line between braces\n Quitar línea en blanco entre llaves\n \n \n \n Remove unreachable code\n Quitar código inaccesible\n \n \n \n Warning: Adding parameters to local function declaration may produce invalid code.\n Advertencia: Agregar parámetros a la declaración de función local puede generar código no válido.\n \n \n
\n \n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":105,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56534,"string":"56,534"},"pr_title":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type"},"pr_description":{"kind":"string","value":"Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-19T23:12:22Z","string":"2021-09-19T23:12:22Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T15:06:55Z","string":"2021-09-24T15:06:55Z"},"previous_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"pr_commit":{"kind":"string","value":"27613724bd239da606824c33e94f52085993c041"},"query":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type. Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SuppressFormattingRule.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Formatting;\nusing Microsoft.CodeAnalysis.Formatting.Rules;\nusing Microsoft.CodeAnalysis.Text;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Formatting\n{\n internal class SuppressFormattingRule : BaseFormattingRule\n {\n internal const string Name = \"CSharp Suppress Formatting Rule\";\n\n public override void AddSuppressOperations(List list, SyntaxNode node, in NextSuppressOperationAction nextOperation)\n {\n nextOperation.Invoke();\n\n AddFormatSuppressOperations(list, node);\n\n AddInitializerSuppressOperations(list, node);\n\n AddBraceSuppressOperations(list, node);\n\n AddStatementExceptBlockSuppressOperations(list, node);\n\n AddSpecificNodesSuppressOperations(list, node);\n }\n\n private static void AddSpecificNodesSuppressOperations(List list, SyntaxNode node)\n {\n if (node is IfStatementSyntax ifStatementNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, ifStatementNode.IfKeyword, ifStatementNode.Statement.GetLastToken(includeZeroWidth: true));\n\n if (ifStatementNode.Else != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, ifStatementNode.Else.ElseKeyword, ifStatementNode.Else.Statement.GetLastToken(includeZeroWidth: true));\n }\n\n return;\n }\n\n // ex: `e is Type ( /* positional */ )`\n if (node.IsKind(SyntaxKind.RecursivePattern, out RecursivePatternSyntax? recursivePattern))\n {\n var positional = recursivePattern.PositionalPatternClause;\n var property = recursivePattern.PropertyPatternClause;\n if (positional != null)\n {\n var openParenToken = positional.OpenParenToken;\n var closeParenToken = positional.CloseParenToken;\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, openParenToken, closeParenToken);\n if (property != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, openParenToken, property.GetLastToken());\n }\n }\n\n // ex: `Property: ` inside a recursive pattern, such as `e is { Property: , ... }`\n else if (property != null)\n {\n var openBraceToken = property.OpenBraceToken;\n var closeBraceToken = property.CloseBraceToken;\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, openBraceToken, closeBraceToken);\n }\n\n return;\n }\n\n // ex: `: expression` inside a switch expression, such as `e switch { : expression, ... }`\n if (node.IsKind(SyntaxKind.SwitchExpressionArm))\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, node.GetFirstToken(), node.GetLastToken());\n return;\n }\n\n // ex: `e switch { : expression, ... }`\n if (node.IsKind(SyntaxKind.SwitchExpression))\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, node.GetFirstToken(), node.GetLastToken());\n return;\n }\n\n // ex: `case :` inside a switch statement\n if (node is CasePatternSwitchLabelSyntax casePattern)\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, casePattern.GetFirstToken(), casePattern.GetLastToken());\n return;\n }\n\n // ex: `expression is `\n if (node is IsPatternExpressionSyntax isPattern)\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, isPattern.GetFirstToken(), isPattern.GetLastToken());\n\n if (isPattern.Pattern.IsKind(SyntaxKind.RecursivePattern, out recursivePattern))\n {\n // ex:\n // ```\n // _ = expr is (1, 2) { }$$\n // M();\n // ```\n // or:\n // ```\n // _ = expr is { }$$\n // M();\n // ```\n var propertyPatternClause = recursivePattern.PropertyPatternClause;\n if (propertyPatternClause != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, isPattern.IsKeyword, propertyPatternClause.GetLastToken());\n }\n }\n\n return;\n }\n\n if (node is ConstructorInitializerSyntax constructorInitializerNode)\n {\n var constructorDeclarationNode = constructorInitializerNode.Parent as ConstructorDeclarationSyntax;\n if (constructorDeclarationNode?.Body != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, constructorInitializerNode.ColonToken, constructorDeclarationNode.Body.CloseBraceToken);\n }\n\n return;\n }\n\n if (node is DoStatementSyntax whileStatementNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, whileStatementNode.GetFirstToken(includeZeroWidth: true), whileStatementNode.Statement.GetLastToken(includeZeroWidth: true));\n return;\n }\n\n if (node is MemberDeclarationSyntax memberDeclNode)\n {\n // Attempt to keep the part of a member that follows the attributes on a single\n // line if that's how it's currently written.\n var (firstToken, lastToken) = memberDeclNode.GetFirstAndLastMemberDeclarationTokensAfterAttributes();\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n\n // Also, If the member is on single line with its attributes on it, then keep \n // it on a single line. This is for code like the following:\n //\n // [Import] public int Field1;\n // [Import] public int Field2;\n var attributes = memberDeclNode.GetAttributes();\n var endToken = node.GetLastToken(includeZeroWidth: true);\n for (var i = 0; i < attributes.Count; ++i)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list,\n attributes[i].GetFirstToken(includeZeroWidth: true),\n endToken);\n }\n\n var propertyDeclNode = node as PropertyDeclarationSyntax;\n if (propertyDeclNode?.Initializer != null && propertyDeclNode?.AccessorList != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, propertyDeclNode.AccessorList.GetLastToken());\n }\n\n return;\n }\n\n if (node is AccessorDeclarationSyntax accessorDeclNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, accessorDeclNode.Keyword, accessorDeclNode.GetLastToken(includeZeroWidth: true));\n return;\n }\n\n if (node is SwitchSectionSyntax switchSection)\n {\n if (switchSection.Labels.Count < 2)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true));\n return;\n }\n else\n {\n // Add Separate suppression for each Label and for the last label, add the <> \n for (var i = 0; i < switchSection.Labels.Count - 1; ++i)\n {\n if (switchSection.Labels[i] != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.Labels[i].GetFirstToken(includeZeroWidth: true), switchSection.Labels[i].GetLastToken(includeZeroWidth: true));\n }\n }\n\n // For the last label add the rest of the statements of the switch\n if (switchSection.Labels[switchSection.Labels.Count - 1] != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.Labels[switchSection.Labels.Count - 1].GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true));\n }\n\n return;\n }\n }\n\n if (node is AnonymousFunctionExpressionSyntax or\n LocalFunctionStatementSyntax)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list,\n node.GetFirstToken(includeZeroWidth: true),\n node.GetLastToken(includeZeroWidth: true),\n SuppressOption.IgnoreElasticWrapping);\n return;\n }\n\n if (node is ParameterSyntax parameterNode)\n {\n if (parameterNode.AttributeLists.Count != 0)\n {\n var anchorToken = parameterNode.AttributeLists.First().OpenBracketToken;\n AddSuppressAllOperationIfOnMultipleLine(list, anchorToken, parameterNode.GetLastToken());\n }\n }\n\n if (node is TryStatementSyntax tryStatement)\n {\n // Add a suppression operation if the try keyword and the block are in the same line\n if (!tryStatement.TryKeyword.IsMissing && tryStatement.Block != null && !tryStatement.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, tryStatement.TryKeyword, tryStatement.Block.CloseBraceToken);\n }\n }\n\n if (node is CatchClauseSyntax catchClause)\n {\n // Add a suppression operation if the catch keyword and the corresponding block are in the same line\n if (!catchClause.CatchKeyword.IsMissing && catchClause.Block != null && !catchClause.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, catchClause.CatchKeyword, catchClause.Block.CloseBraceToken);\n }\n }\n\n if (node is FinallyClauseSyntax finallyClause)\n {\n // Add a suppression operation if the finally keyword and the corresponding block are in the same line\n if (!finallyClause.FinallyKeyword.IsMissing && finallyClause.Block != null && !finallyClause.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, finallyClause.FinallyKeyword, finallyClause.Block.CloseBraceToken);\n }\n }\n\n if (node is InterpolatedStringExpressionSyntax interpolatedStringExpression)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, interpolatedStringExpression.StringStartToken, interpolatedStringExpression.StringEndToken);\n }\n }\n\n private static void AddStatementExceptBlockSuppressOperations(List list, SyntaxNode node)\n {\n if (node is not StatementSyntax statementNode || statementNode.Kind() == SyntaxKind.Block)\n {\n return;\n }\n\n var firstToken = statementNode.GetFirstToken(includeZeroWidth: true);\n var lastToken = statementNode.GetLastToken(includeZeroWidth: true);\n\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n }\n\n private static void AddFormatSuppressOperations(List list, SyntaxNode node)\n {\n if (!node.ContainsDirectives)\n {\n return;\n }\n\n foreach (var child in node.ChildNodesAndTokens())\n {\n if (!child.IsToken)\n {\n continue;\n }\n\n ProcessTriviaList(list, child.AsToken().LeadingTrivia);\n ProcessTriviaList(list, child.AsToken().TrailingTrivia);\n }\n\n return;\n\n // Local functions\n static void ProcessTriviaList(List list, SyntaxTriviaList triviaList)\n {\n foreach (var trivia in triviaList)\n {\n ProcessTrivia(list, trivia);\n }\n }\n\n static void ProcessTrivia(List list, SyntaxTrivia trivia)\n {\n if (!(trivia.HasStructure))\n {\n return;\n }\n\n ProcessStructuredTrivia(list, trivia.GetStructure()!);\n }\n\n static void ProcessStructuredTrivia(List list, SyntaxNode structure)\n {\n if (structure is not PragmaWarningDirectiveTriviaSyntax pragmaWarningDirectiveTrivia)\n {\n return;\n }\n\n if (!IsFormatDirective(pragmaWarningDirectiveTrivia, SyntaxKind.DisableKeyword))\n {\n return;\n }\n\n var startToken = pragmaWarningDirectiveTrivia.GetLastToken(includeZeroWidth: true, includeDirectives: true);\n\n var endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword));\n var endToken = endDirective is null\n ? ((CompilationUnitSyntax)structure.SyntaxTree.GetRoot(CancellationToken.None)).EndOfFileToken\n : endDirective.GetFirstToken(includeDirectives: true);\n\n Debug.Assert(!startToken.IsKind(SyntaxKind.None) && !endToken.IsKind(SyntaxKind.None));\n var textSpan = TextSpan.FromBounds(startToken.Span.End, endToken.SpanStart);\n list.Add(new SuppressOperation(startToken, endToken, textSpan, SuppressOption.DisableFormatting));\n }\n }\n\n private static bool IsFormatDirective(DirectiveTriviaSyntax? trivia, SyntaxKind disableOrRestoreKeyword)\n {\n if (trivia is not PragmaWarningDirectiveTriviaSyntax pragmaWarningDirectiveTrivia)\n {\n return false;\n }\n\n if (!pragmaWarningDirectiveTrivia.DisableOrRestoreKeyword.IsKind(disableOrRestoreKeyword))\n {\n return false;\n }\n\n foreach (var errorCode in pragmaWarningDirectiveTrivia.ErrorCodes)\n {\n if (errorCode is not IdentifierNameSyntax identifierName)\n {\n continue;\n }\n\n if (identifierName.Identifier.ValueText.Equals(FormattingDiagnosticIds.FormatDocumentControlDiagnosticId)\n || identifierName.Identifier.ValueText.Equals(FormattingDiagnosticIds.FormattingDiagnosticId))\n {\n return true;\n }\n }\n\n return false;\n }\n\n private static void AddInitializerSuppressOperations(List list, SyntaxNode node)\n {\n // array or collection initializer case\n if (node.IsInitializerForArrayOrCollectionCreationExpression())\n {\n var arrayOrCollectionInitializer = (InitializerExpressionSyntax)node;\n AddSuppressAllOperationIfOnMultipleLine(list, arrayOrCollectionInitializer.OpenBraceToken.GetPreviousToken(includeZeroWidth: true), arrayOrCollectionInitializer.CloseBraceToken);\n return;\n }\n\n var initializer = GetInitializerNode(node);\n if (initializer is { Parent: { } })\n {\n AddInitializerSuppressOperations(list, initializer.Parent, initializer.Expressions);\n return;\n }\n\n if (node is AnonymousObjectCreationExpressionSyntax anonymousCreationNode)\n {\n AddInitializerSuppressOperations(list, anonymousCreationNode, anonymousCreationNode.Initializers);\n return;\n }\n }\n\n private static void AddInitializerSuppressOperations(List list, SyntaxNode parent, IEnumerable items)\n {\n // make creation node itself to not break into multiple line, if it is on same line\n AddSuppressWrappingIfOnSingleLineOperation(list, parent.GetFirstToken(includeZeroWidth: true), parent.GetLastToken(includeZeroWidth: true));\n\n // make each initializer expression to not break into multiple line if it is on same line\n foreach (var item in items)\n {\n var firstToken = item.GetFirstToken(includeZeroWidth: true);\n var lastToken = item.GetLastToken(includeZeroWidth: true);\n\n if (!firstToken.Equals(lastToken))\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n }\n }\n }\n\n private static InitializerExpressionSyntax? GetInitializerNode(SyntaxNode node)\n => node switch\n {\n ObjectCreationExpressionSyntax objectCreationNode => objectCreationNode.Initializer,\n ArrayCreationExpressionSyntax arrayCreationNode => arrayCreationNode.Initializer,\n ImplicitArrayCreationExpressionSyntax implicitArrayNode => implicitArrayNode.Initializer,\n _ => null,\n };\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Formatting;\nusing Microsoft.CodeAnalysis.Formatting.Rules;\nusing Microsoft.CodeAnalysis.Text;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Formatting\n{\n internal class SuppressFormattingRule : BaseFormattingRule\n {\n internal const string Name = \"CSharp Suppress Formatting Rule\";\n\n public override void AddSuppressOperations(List list, SyntaxNode node, in NextSuppressOperationAction nextOperation)\n {\n nextOperation.Invoke();\n\n AddFormatSuppressOperations(list, node);\n\n AddInitializerSuppressOperations(list, node);\n\n AddBraceSuppressOperations(list, node);\n\n AddStatementExceptBlockSuppressOperations(list, node);\n\n AddSpecificNodesSuppressOperations(list, node);\n }\n\n private static void AddSpecificNodesSuppressOperations(List list, SyntaxNode node)\n {\n if (node is IfStatementSyntax ifStatementNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, ifStatementNode.IfKeyword, ifStatementNode.Statement.GetLastToken(includeZeroWidth: true));\n\n if (ifStatementNode.Else != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, ifStatementNode.Else.ElseKeyword, ifStatementNode.Else.Statement.GetLastToken(includeZeroWidth: true));\n }\n\n return;\n }\n\n // ex: `e is Type ( /* positional */ )`\n if (node.IsKind(SyntaxKind.RecursivePattern, out RecursivePatternSyntax? recursivePattern))\n {\n var positional = recursivePattern.PositionalPatternClause;\n var property = recursivePattern.PropertyPatternClause;\n if (positional != null)\n {\n var openParenToken = positional.OpenParenToken;\n var closeParenToken = positional.CloseParenToken;\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, openParenToken, closeParenToken);\n if (property != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, openParenToken, property.GetLastToken());\n }\n }\n\n // ex: `Property: ` inside a recursive pattern, such as `e is { Property: , ... }`\n else if (property != null)\n {\n var openBraceToken = property.OpenBraceToken;\n var closeBraceToken = property.CloseBraceToken;\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, openBraceToken, closeBraceToken);\n }\n\n return;\n }\n\n // ex: `: expression` inside a switch expression, such as `e switch { : expression, ... }`\n if (node.IsKind(SyntaxKind.SwitchExpressionArm))\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, node.GetFirstToken(), node.GetLastToken());\n return;\n }\n\n // ex: `e switch { : expression, ... }`\n if (node.IsKind(SyntaxKind.SwitchExpression))\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, node.GetFirstToken(), node.GetLastToken());\n return;\n }\n\n // ex: `case :` inside a switch statement\n if (node is CasePatternSwitchLabelSyntax casePattern)\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, casePattern.GetFirstToken(), casePattern.GetLastToken());\n return;\n }\n\n // ex: `expression is `\n if (node is IsPatternExpressionSyntax isPattern)\n {\n // Formatting should refrain from inserting new lines, unless the user already split across multiple lines\n AddSuppressWrappingIfOnSingleLineOperation(list, isPattern.GetFirstToken(), isPattern.GetLastToken());\n\n if (isPattern.Pattern.IsKind(SyntaxKind.RecursivePattern, out recursivePattern))\n {\n // ex:\n // ```\n // _ = expr is (1, 2) { }$$\n // M();\n // ```\n // or:\n // ```\n // _ = expr is { }$$\n // M();\n // ```\n var propertyPatternClause = recursivePattern.PropertyPatternClause;\n if (propertyPatternClause != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, isPattern.IsKeyword, propertyPatternClause.GetLastToken());\n }\n }\n\n return;\n }\n\n if (node is ConstructorInitializerSyntax constructorInitializerNode)\n {\n var constructorDeclarationNode = constructorInitializerNode.Parent as ConstructorDeclarationSyntax;\n if (constructorDeclarationNode?.Body != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, constructorInitializerNode.ColonToken, constructorDeclarationNode.Body.CloseBraceToken);\n }\n\n return;\n }\n\n if (node is DoStatementSyntax whileStatementNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, whileStatementNode.GetFirstToken(includeZeroWidth: true), whileStatementNode.Statement.GetLastToken(includeZeroWidth: true));\n return;\n }\n\n if (node is MemberDeclarationSyntax memberDeclNode)\n {\n // Attempt to keep the part of a member that follows the attributes on a single\n // line if that's how it's currently written.\n var (firstToken, lastToken) = memberDeclNode.GetFirstAndLastMemberDeclarationTokensAfterAttributes();\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n\n // Also, If the member is on single line with its attributes on it, then keep \n // it on a single line. This is for code like the following:\n //\n // [Import] public int Field1;\n // [Import] public int Field2;\n var attributes = memberDeclNode.GetAttributes();\n var endToken = node.GetLastToken(includeZeroWidth: true);\n for (var i = 0; i < attributes.Count; ++i)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list,\n attributes[i].GetFirstToken(includeZeroWidth: true),\n endToken);\n }\n\n var propertyDeclNode = node as PropertyDeclarationSyntax;\n if (propertyDeclNode?.Initializer != null && propertyDeclNode?.AccessorList != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, propertyDeclNode.AccessorList.GetLastToken());\n }\n\n return;\n }\n\n if (node is AccessorDeclarationSyntax accessorDeclNode)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, accessorDeclNode.Keyword, accessorDeclNode.GetLastToken(includeZeroWidth: true));\n return;\n }\n\n if (node is SwitchSectionSyntax switchSection)\n {\n if (switchSection.Labels.Count < 2)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true));\n return;\n }\n else\n {\n // Add Separate suppression for each Label and for the last label, add the <> \n for (var i = 0; i < switchSection.Labels.Count - 1; ++i)\n {\n if (switchSection.Labels[i] != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.Labels[i].GetFirstToken(includeZeroWidth: true), switchSection.Labels[i].GetLastToken(includeZeroWidth: true));\n }\n }\n\n // For the last label add the rest of the statements of the switch\n if (switchSection.Labels[switchSection.Labels.Count - 1] != null)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, switchSection.Labels[switchSection.Labels.Count - 1].GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true));\n }\n\n return;\n }\n }\n\n if (node is AnonymousFunctionExpressionSyntax or\n LocalFunctionStatementSyntax)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list,\n node.GetFirstToken(includeZeroWidth: true),\n node.GetLastToken(includeZeroWidth: true),\n SuppressOption.IgnoreElasticWrapping);\n return;\n }\n\n if (node is ParameterSyntax parameterNode)\n {\n if (parameterNode.AttributeLists.Count != 0)\n {\n var anchorToken = parameterNode.AttributeLists.First().OpenBracketToken;\n AddSuppressAllOperationIfOnMultipleLine(list, anchorToken, parameterNode.GetLastToken());\n }\n }\n\n if (node is TryStatementSyntax tryStatement)\n {\n // Add a suppression operation if the try keyword and the block are in the same line\n if (!tryStatement.TryKeyword.IsMissing && tryStatement.Block != null && !tryStatement.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, tryStatement.TryKeyword, tryStatement.Block.CloseBraceToken);\n }\n }\n\n if (node is CatchClauseSyntax catchClause)\n {\n // Add a suppression operation if the catch keyword and the corresponding block are in the same line\n if (!catchClause.CatchKeyword.IsMissing && catchClause.Block != null && !catchClause.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, catchClause.CatchKeyword, catchClause.Block.CloseBraceToken);\n }\n }\n\n if (node is FinallyClauseSyntax finallyClause)\n {\n // Add a suppression operation if the finally keyword and the corresponding block are in the same line\n if (!finallyClause.FinallyKeyword.IsMissing && finallyClause.Block != null && !finallyClause.Block.CloseBraceToken.IsMissing)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, finallyClause.FinallyKeyword, finallyClause.Block.CloseBraceToken);\n }\n }\n\n if (node is InterpolatedStringExpressionSyntax interpolatedStringExpression)\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, interpolatedStringExpression.StringStartToken, interpolatedStringExpression.StringEndToken);\n }\n }\n\n private static void AddStatementExceptBlockSuppressOperations(List list, SyntaxNode node)\n {\n if (node is not StatementSyntax statementNode || statementNode.Kind() == SyntaxKind.Block)\n {\n return;\n }\n\n var firstToken = statementNode.GetFirstToken(includeZeroWidth: true);\n var lastToken = statementNode.GetLastToken(includeZeroWidth: true);\n\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n }\n\n private static void AddFormatSuppressOperations(List list, SyntaxNode node)\n {\n if (!node.ContainsDirectives)\n {\n return;\n }\n\n foreach (var child in node.ChildNodesAndTokens())\n {\n if (!child.IsToken)\n {\n continue;\n }\n\n ProcessTriviaList(list, child.AsToken().LeadingTrivia);\n ProcessTriviaList(list, child.AsToken().TrailingTrivia);\n }\n\n return;\n\n // Local functions\n static void ProcessTriviaList(List list, SyntaxTriviaList triviaList)\n {\n foreach (var trivia in triviaList)\n {\n ProcessTrivia(list, trivia);\n }\n }\n\n static void ProcessTrivia(List list, SyntaxTrivia trivia)\n {\n if (!(trivia.HasStructure))\n {\n return;\n }\n\n ProcessStructuredTrivia(list, trivia.GetStructure()!);\n }\n\n static void ProcessStructuredTrivia(List list, SyntaxNode structure)\n {\n if (structure is not PragmaWarningDirectiveTriviaSyntax pragmaWarningDirectiveTrivia)\n {\n return;\n }\n\n if (!IsFormatDirective(pragmaWarningDirectiveTrivia, SyntaxKind.DisableKeyword))\n {\n return;\n }\n\n var startToken = pragmaWarningDirectiveTrivia.GetLastToken(includeZeroWidth: true, includeDirectives: true);\n\n var endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword));\n var endToken = endDirective is null\n ? ((CompilationUnitSyntax)structure.SyntaxTree.GetRoot(CancellationToken.None)).EndOfFileToken\n : endDirective.GetFirstToken(includeDirectives: true);\n\n Debug.Assert(!startToken.IsKind(SyntaxKind.None) && !endToken.IsKind(SyntaxKind.None));\n var textSpan = TextSpan.FromBounds(startToken.Span.End, endToken.SpanStart);\n list.Add(new SuppressOperation(startToken, endToken, textSpan, SuppressOption.DisableFormatting));\n }\n }\n\n private static bool IsFormatDirective(DirectiveTriviaSyntax? trivia, SyntaxKind disableOrRestoreKeyword)\n {\n if (trivia is not PragmaWarningDirectiveTriviaSyntax pragmaWarningDirectiveTrivia)\n {\n return false;\n }\n\n if (!pragmaWarningDirectiveTrivia.DisableOrRestoreKeyword.IsKind(disableOrRestoreKeyword))\n {\n return false;\n }\n\n foreach (var errorCode in pragmaWarningDirectiveTrivia.ErrorCodes)\n {\n if (errorCode is not IdentifierNameSyntax identifierName)\n {\n continue;\n }\n\n if (identifierName.Identifier.ValueText.Equals(FormattingDiagnosticIds.FormatDocumentControlDiagnosticId)\n || identifierName.Identifier.ValueText.Equals(FormattingDiagnosticIds.FormattingDiagnosticId))\n {\n return true;\n }\n }\n\n return false;\n }\n\n private static void AddInitializerSuppressOperations(List list, SyntaxNode node)\n {\n // array or collection initializer case\n if (node.IsInitializerForArrayOrCollectionCreationExpression())\n {\n var arrayOrCollectionInitializer = (InitializerExpressionSyntax)node;\n AddSuppressAllOperationIfOnMultipleLine(list, arrayOrCollectionInitializer.OpenBraceToken.GetPreviousToken(includeZeroWidth: true), arrayOrCollectionInitializer.CloseBraceToken);\n return;\n }\n\n var initializer = GetInitializerNode(node);\n if (initializer is { Parent: { } })\n {\n AddInitializerSuppressOperations(list, initializer.Parent, initializer.Expressions);\n return;\n }\n\n if (node is AnonymousObjectCreationExpressionSyntax anonymousCreationNode)\n {\n AddInitializerSuppressOperations(list, anonymousCreationNode, anonymousCreationNode.Initializers);\n return;\n }\n }\n\n private static void AddInitializerSuppressOperations(List list, SyntaxNode parent, IEnumerable items)\n {\n // make creation node itself to not break into multiple line, if it is on same line\n AddSuppressWrappingIfOnSingleLineOperation(list, parent.GetFirstToken(includeZeroWidth: true), parent.GetLastToken(includeZeroWidth: true));\n\n // make each initializer expression to not break into multiple line if it is on same line\n foreach (var item in items)\n {\n var firstToken = item.GetFirstToken(includeZeroWidth: true);\n var lastToken = item.GetLastToken(includeZeroWidth: true);\n\n if (!firstToken.Equals(lastToken))\n {\n AddSuppressWrappingIfOnSingleLineOperation(list, firstToken, lastToken);\n }\n }\n }\n\n private static InitializerExpressionSyntax? GetInitializerNode(SyntaxNode node)\n => node switch\n {\n ObjectCreationExpressionSyntax objectCreationNode => objectCreationNode.Initializer,\n ArrayCreationExpressionSyntax arrayCreationNode => arrayCreationNode.Initializer,\n ImplicitArrayCreationExpressionSyntax implicitArrayNode => implicitArrayNode.Initializer,\n _ => null,\n };\n }\n}\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":106,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56534,"string":"56,534"},"pr_title":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type"},"pr_description":{"kind":"string","value":"Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-19T23:12:22Z","string":"2021-09-19T23:12:22Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T15:06:55Z","string":"2021-09-24T15:06:55Z"},"previous_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"pr_commit":{"kind":"string","value":"27613724bd239da606824c33e94f52085993c041"},"query":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type. Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/Features/Core/Portable/CodeFixes/Iterator/AbstractIteratorCodeFixProvider.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.CodeAnalysis.CodeActions;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.Text;\n\nnamespace Microsoft.CodeAnalysis.CodeFixes.Iterator\n{\n internal abstract class AbstractIteratorCodeFixProvider : CodeFixProvider\n {\n public override FixAllProvider GetFixAllProvider()\n {\n // Fix All is not supported by this code fix\n return null;\n }\n\n protected abstract Task GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken);\n\n public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)\n {\n var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);\n if (!TryGetNode(root, context.Span, out var node))\n {\n return;\n }\n\n var diagnostic = context.Diagnostics.FirstOrDefault();\n\n var codeAction = await GetCodeFixAsync(root, node, context.Document, diagnostic, context.CancellationToken).ConfigureAwait(false);\n\n if (codeAction != null)\n {\n context.RegisterCodeFix(codeAction, diagnostic);\n }\n }\n\n protected virtual bool TryGetNode(SyntaxNode root, TextSpan span, out SyntaxNode node)\n {\n node = null;\n var ancestors = root.FindToken(span.Start).GetAncestors();\n if (!ancestors.Any())\n {\n return false;\n }\n\n node = ancestors.FirstOrDefault(n => n.Span.Contains(span) && n != root);\n return node != null;\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.CodeAnalysis.CodeActions;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.Text;\n\nnamespace Microsoft.CodeAnalysis.CodeFixes.Iterator\n{\n internal abstract class AbstractIteratorCodeFixProvider : CodeFixProvider\n {\n public override FixAllProvider GetFixAllProvider()\n {\n // Fix All is not supported by this code fix\n return null;\n }\n\n protected abstract Task GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken);\n\n public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)\n {\n var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);\n if (!TryGetNode(root, context.Span, out var node))\n {\n return;\n }\n\n var diagnostic = context.Diagnostics.FirstOrDefault();\n\n var codeAction = await GetCodeFixAsync(root, node, context.Document, diagnostic, context.CancellationToken).ConfigureAwait(false);\n\n if (codeAction != null)\n {\n context.RegisterCodeFix(codeAction, diagnostic);\n }\n }\n\n protected virtual bool TryGetNode(SyntaxNode root, TextSpan span, out SyntaxNode node)\n {\n node = null;\n var ancestors = root.FindToken(span.Start).GetAncestors();\n if (!ancestors.Any())\n {\n return false;\n }\n\n node = ancestors.FirstOrDefault(n => n.Span.Contains(span) && n != root);\n return node != null;\n }\n }\n}\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":107,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56534,"string":"56,534"},"pr_title":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type"},"pr_description":{"kind":"string","value":"Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-19T23:12:22Z","string":"2021-09-19T23:12:22Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T15:06:55Z","string":"2021-09-24T15:06:55Z"},"previous_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"pr_commit":{"kind":"string","value":"27613724bd239da606824c33e94f52085993c041"},"query":{"kind":"string","value":"Method type inference should make inference from explicit lambda return type. Update [\"type inference\"](https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#type-inference) to make an exact inference from an explicit lambda return type.\r\n\r\nProposed spec changes **in bold**:\r\n\r\n> #### The first phase\r\n> \r\n> For each of the method arguments `Ei`:\r\n> \r\n> * If `Ei` is an anonymous function and `Ti` is a delegate type or expression tree type, an *explicit parameter type inference* ([Explicit parameter type inferences](expressions.md#explicit-parameter-type-inferences)) is made from `Ei` to `Ti` **and an *explicit return type inference* is made from `Ei` to `Ti`.**\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a value parameter then a *lower-bound inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, if `Ei` has a type `U` and `xi` is a `ref` or `out` parameter then an *exact inference* is made *from* `U` *to* `Ti`.\r\n> * Otherwise, no inference is made for this argument.\r\n\r\n> #### **Explicit return type inference**\r\n> \r\n> **An *explicit return type inference* is made *from* an expression `E` *to* a type `T` in the following way:**\r\n> \r\n> * **If `E` is an anonymous function with explicit return type `Ur` and `T` is a delegate type or expression tree type with return type `Vr` then an *exact inference* ([Exact inferences](expressions.md#exact-inferences)) is made *from* `Ur` *to* `Vr`.**\r\n\r\nSee [LDM notes](https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md#method-type-inference-from-return-types).\r\n\r\nFixes #54257\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Test/Syntax/Parsing/ValueTupleTests.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing Xunit;\nusing System.Linq;\nusing Microsoft.CodeAnalysis.CSharp.Test.Utilities;\nusing Microsoft.CodeAnalysis.Test.Utilities;\nusing Roslyn.Test.Utilities;\nusing Xunit.Abstractions;\n\nnamespace Microsoft.CodeAnalysis.CSharp.UnitTests.Parsing\n{\n public class ValueTupleTests : ParsingTests\n {\n public ValueTupleTests(ITestOutputHelper output) : base(output) { }\n\n protected override SyntaxTree ParseTree(string text, CSharpParseOptions options)\n {\n return SyntaxFactory.ParseSyntaxTree(text, options: options);\n }\n\n [Fact]\n public void SimpleTuple()\n {\n var tree = UsingTree(@\"\nclass C\n{\n (int, string) Goo()\n {\n return (1, \"\"Alice\"\");\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.NumericLiteralExpression);\n {\n N(SyntaxKind.NumericLiteralToken);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.StringLiteralExpression);\n {\n N(SyntaxKind.StringLiteralToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void LongTuple()\n {\n var tree = UsingTree(@\"\nclass C\n{\n (int, int, int, string, string, string, int, int, int) Goo()\n {\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TuplesInLambda()\n {\n var tree = UsingTree(@\"\nclass C\n{\n var x = ((string, string) a, (int, int) b) => { };\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.ParenthesizedLambdaExpression);\n {\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.EqualsGreaterThanToken);\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TuplesWithNamesInLambda()\n {\n var tree = UsingTree(@\"\nclass C\n{\n var x = ((string a, string) a, (int, int b) b) => { };\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.ParenthesizedLambdaExpression);\n {\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.EqualsGreaterThanToken);\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleInParameters()\n {\n var tree = UsingTree(@\"\nclass C\n{\n void Goo((int, string) a)\n {\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.VoidKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleTypeWithTooFewElements()\n {\n var tree = UsingTree(@\"\nclass C\n{\n void M(int x, () y, (int a) z) { }\n}\", options: TestOptions.Regular);\n\n tree.GetDiagnostics().Verify(\n // (4,20): error CS8124: Tuple must contain at least two elements.\n // void M(int x, () y, (int a) z) { }\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 20),\n // (4,31): error CS8124: Tuple must contain at least two elements.\n // void M(int x, () y, (int a) z) { }\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 31)\n );\n\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken, \"C\");\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.VoidKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"M\");\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken, \"y\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken, \"z\");\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleExpressionWithTooFewElements()\n {\n var tree = UsingTree(@\"\nclass C\n{\n object x = ((Alice: 1), ());\n}\", options: TestOptions.Regular);\n\n tree.GetDiagnostics().Verify(\n // (4,26): error CS8124: Tuple must contain at least two elements.\n // object x = ((Alice: 1), ());\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 26),\n // (4,30): error CS1525: Invalid expression term ')'\n // object x = ((Alice: 1), ());\n Diagnostic(ErrorCode.ERR_InvalidExprTerm, \")\").WithArguments(\")\").WithLocation(4, 30)\n );\n\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken, \"C\");\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.ObjectKeyword);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.NameColon);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Alice\");\n }\n N(SyntaxKind.ColonToken);\n }\n N(SyntaxKind.NumericLiteralExpression);\n {\n N(SyntaxKind.NumericLiteralToken, \"1\");\n }\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.Argument);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ParenthesizedExpression);\n {\n N(SyntaxKind.OpenParenToken);\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(13667, \"https://github.com/dotnet/roslyn/issues/13667\")]\n public void MissingShortTupleErrorWhenWarningPresent()\n {\n // Diff errors\n var test = @\"\nclass Program\n{\n object a = (x: 3l);\n}\n\";\n ParseAndValidate(test,\n // (4,21): warning CS0078: The 'l' suffix is easily confused with the digit '1' -- use 'L' for clarity\n // object a = (x: 3l);\n Diagnostic(ErrorCode.WRN_LowercaseEllSuffix, \"l\").WithLocation(4, 21),\n // (4,22): error CS8124: Tuple must contain at least two elements.\n // object a = (x: 3l);\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 22)\n );\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_01()\n {\n UsingStatement(\"return (i, isValid ? Errors.IsValid : Errors.HasErrors);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ConditionalExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"isValid\");\n }\n N(SyntaxKind.QuestionToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"IsValid\");\n }\n }\n N(SyntaxKind.ColonToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"HasErrors\");\n }\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_02()\n {\n UsingStatement(\"return (isValid ? Errors.IsValid : Errors.HasErrors, i);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ConditionalExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"isValid\");\n }\n N(SyntaxKind.QuestionToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"IsValid\");\n }\n }\n N(SyntaxKind.ColonToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"HasErrors\");\n }\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_03()\n {\n UsingStatement(\"return (i, a < b, c > d);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.DeclarationExpression);\n {\n N(SyntaxKind.GenericName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n N(SyntaxKind.TypeArgumentList);\n {\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n }\n }\n N(SyntaxKind.SingleVariableDesignation);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_04()\n {\n UsingStatement(\"return (i, a < b, c > d.x);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LessThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.GreaterThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_05()\n {\n UsingStatement(\"return (i, a < b, c > d && x);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LessThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LogicalAndExpression);\n {\n N(SyntaxKind.GreaterThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n }\n N(SyntaxKind.AmpersandAmpersandToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing Xunit;\nusing System.Linq;\nusing Microsoft.CodeAnalysis.CSharp.Test.Utilities;\nusing Microsoft.CodeAnalysis.Test.Utilities;\nusing Roslyn.Test.Utilities;\nusing Xunit.Abstractions;\n\nnamespace Microsoft.CodeAnalysis.CSharp.UnitTests.Parsing\n{\n public class ValueTupleTests : ParsingTests\n {\n public ValueTupleTests(ITestOutputHelper output) : base(output) { }\n\n protected override SyntaxTree ParseTree(string text, CSharpParseOptions options)\n {\n return SyntaxFactory.ParseSyntaxTree(text, options: options);\n }\n\n [Fact]\n public void SimpleTuple()\n {\n var tree = UsingTree(@\"\nclass C\n{\n (int, string) Goo()\n {\n return (1, \"\"Alice\"\");\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.NumericLiteralExpression);\n {\n N(SyntaxKind.NumericLiteralToken);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.StringLiteralExpression);\n {\n N(SyntaxKind.StringLiteralToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void LongTuple()\n {\n var tree = UsingTree(@\"\nclass C\n{\n (int, int, int, string, string, string, int, int, int) Goo()\n {\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TuplesInLambda()\n {\n var tree = UsingTree(@\"\nclass C\n{\n var x = ((string, string) a, (int, int) b) => { };\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.ParenthesizedLambdaExpression);\n {\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.EqualsGreaterThanToken);\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TuplesWithNamesInLambda()\n {\n var tree = UsingTree(@\"\nclass C\n{\n var x = ((string a, string) a, (int, int b) b) => { };\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.ParenthesizedLambdaExpression);\n {\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.EqualsGreaterThanToken);\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleInParameters()\n {\n var tree = UsingTree(@\"\nclass C\n{\n void Goo((int, string) a)\n {\n }\n}\", options: TestOptions.Regular);\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.VoidKeyword);\n }\n N(SyntaxKind.IdentifierToken);\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.StringKeyword);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleTypeWithTooFewElements()\n {\n var tree = UsingTree(@\"\nclass C\n{\n void M(int x, () y, (int a) z) { }\n}\", options: TestOptions.Regular);\n\n tree.GetDiagnostics().Verify(\n // (4,20): error CS8124: Tuple must contain at least two elements.\n // void M(int x, () y, (int a) z) { }\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 20),\n // (4,31): error CS8124: Tuple must contain at least two elements.\n // void M(int x, () y, (int a) z) { }\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 31)\n );\n\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken, \"C\");\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.MethodDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.VoidKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"M\");\n N(SyntaxKind.ParameterList);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken, \"y\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Parameter);\n {\n N(SyntaxKind.TupleType);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.TupleElement);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.IntKeyword);\n }\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.TupleElement);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.IdentifierToken, \"z\");\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.Block);\n {\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.CloseBraceToken);\n }\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact]\n public void TupleExpressionWithTooFewElements()\n {\n var tree = UsingTree(@\"\nclass C\n{\n object x = ((Alice: 1), ());\n}\", options: TestOptions.Regular);\n\n tree.GetDiagnostics().Verify(\n // (4,26): error CS8124: Tuple must contain at least two elements.\n // object x = ((Alice: 1), ());\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 26),\n // (4,30): error CS1525: Invalid expression term ')'\n // object x = ((Alice: 1), ());\n Diagnostic(ErrorCode.ERR_InvalidExprTerm, \")\").WithArguments(\")\").WithLocation(4, 30)\n );\n\n N(SyntaxKind.CompilationUnit);\n {\n N(SyntaxKind.ClassDeclaration);\n {\n N(SyntaxKind.ClassKeyword);\n N(SyntaxKind.IdentifierToken, \"C\");\n N(SyntaxKind.OpenBraceToken);\n N(SyntaxKind.FieldDeclaration);\n {\n N(SyntaxKind.VariableDeclaration);\n {\n N(SyntaxKind.PredefinedType);\n {\n N(SyntaxKind.ObjectKeyword);\n }\n N(SyntaxKind.VariableDeclarator);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n N(SyntaxKind.EqualsValueClause);\n {\n N(SyntaxKind.EqualsToken);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.NameColon);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Alice\");\n }\n N(SyntaxKind.ColonToken);\n }\n N(SyntaxKind.NumericLiteralExpression);\n {\n N(SyntaxKind.NumericLiteralToken, \"1\");\n }\n }\n M(SyntaxKind.CommaToken);\n M(SyntaxKind.Argument);\n {\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ParenthesizedExpression);\n {\n N(SyntaxKind.OpenParenToken);\n M(SyntaxKind.IdentifierName);\n {\n M(SyntaxKind.IdentifierToken);\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n }\n }\n }\n N(SyntaxKind.SemicolonToken);\n }\n N(SyntaxKind.CloseBraceToken);\n }\n N(SyntaxKind.EndOfFileToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(13667, \"https://github.com/dotnet/roslyn/issues/13667\")]\n public void MissingShortTupleErrorWhenWarningPresent()\n {\n // Diff errors\n var test = @\"\nclass Program\n{\n object a = (x: 3l);\n}\n\";\n ParseAndValidate(test,\n // (4,21): warning CS0078: The 'l' suffix is easily confused with the digit '1' -- use 'L' for clarity\n // object a = (x: 3l);\n Diagnostic(ErrorCode.WRN_LowercaseEllSuffix, \"l\").WithLocation(4, 21),\n // (4,22): error CS8124: Tuple must contain at least two elements.\n // object a = (x: 3l);\n Diagnostic(ErrorCode.ERR_TupleTooFewElements, \")\").WithLocation(4, 22)\n );\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_01()\n {\n UsingStatement(\"return (i, isValid ? Errors.IsValid : Errors.HasErrors);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ConditionalExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"isValid\");\n }\n N(SyntaxKind.QuestionToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"IsValid\");\n }\n }\n N(SyntaxKind.ColonToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"HasErrors\");\n }\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_02()\n {\n UsingStatement(\"return (isValid ? Errors.IsValid : Errors.HasErrors, i);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.ConditionalExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"isValid\");\n }\n N(SyntaxKind.QuestionToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"IsValid\");\n }\n }\n N(SyntaxKind.ColonToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"Errors\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"HasErrors\");\n }\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_03()\n {\n UsingStatement(\"return (i, a < b, c > d);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.DeclarationExpression);\n {\n N(SyntaxKind.GenericName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n N(SyntaxKind.TypeArgumentList);\n {\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n }\n }\n N(SyntaxKind.SingleVariableDesignation);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_04()\n {\n UsingStatement(\"return (i, a < b, c > d.x);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LessThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.GreaterThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n N(SyntaxKind.SimpleMemberAccessExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n N(SyntaxKind.DotToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n\n [Fact, WorkItem(377111, \"https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems?id=377111\")]\n public void TernaryVersusDeclaration_05()\n {\n UsingStatement(\"return (i, a < b, c > d && x);\");\n N(SyntaxKind.ReturnStatement);\n {\n N(SyntaxKind.ReturnKeyword);\n N(SyntaxKind.TupleExpression);\n {\n N(SyntaxKind.OpenParenToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"i\");\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LessThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"a\");\n }\n N(SyntaxKind.LessThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"b\");\n }\n }\n }\n N(SyntaxKind.CommaToken);\n N(SyntaxKind.Argument);\n {\n N(SyntaxKind.LogicalAndExpression);\n {\n N(SyntaxKind.GreaterThanExpression);\n {\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"c\");\n }\n N(SyntaxKind.GreaterThanToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"d\");\n }\n }\n N(SyntaxKind.AmpersandAmpersandToken);\n N(SyntaxKind.IdentifierName);\n {\n N(SyntaxKind.IdentifierToken, \"x\");\n }\n }\n }\n N(SyntaxKind.CloseParenToken);\n }\n N(SyntaxKind.SemicolonToken);\n }\n EOF();\n }\n }\n}\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":108,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Features/CSharp/Portable/InitializeParameter/InitializeParameterHelpers.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.LanguageServices;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Editing;\nusing Microsoft.CodeAnalysis.Formatting;\nusing Microsoft.CodeAnalysis.Operations;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp.InitializeParameter\n{\n internal static class InitializeParameterHelpers\n {\n public static bool IsFunctionDeclaration(SyntaxNode node)\n => node is BaseMethodDeclarationSyntax\n || node is LocalFunctionStatementSyntax\n || node is AnonymousFunctionExpressionSyntax;\n\n public static SyntaxNode GetBody(SyntaxNode functionDeclaration)\n {\n switch (functionDeclaration)\n {\n case BaseMethodDeclarationSyntax methodDeclaration:\n return (SyntaxNode)methodDeclaration.Body ?? methodDeclaration.ExpressionBody;\n case LocalFunctionStatementSyntax localFunction:\n return (SyntaxNode)localFunction.Body ?? localFunction.ExpressionBody;\n case AnonymousFunctionExpressionSyntax anonymousFunction:\n return anonymousFunction.Body;\n default:\n throw ExceptionUtilities.UnexpectedValue(functionDeclaration);\n }\n }\n\n private static SyntaxToken? TryGetSemicolonToken(SyntaxNode functionDeclaration)\n {\n switch (functionDeclaration)\n {\n case BaseMethodDeclarationSyntax methodDeclaration:\n return methodDeclaration.SemicolonToken;\n case LocalFunctionStatementSyntax localFunction:\n return localFunction.SemicolonToken;\n case AnonymousFunctionExpressionSyntax _:\n return null;\n default:\n throw ExceptionUtilities.UnexpectedValue(functionDeclaration);\n }\n }\n\n public static bool IsImplicitConversion(Compilation compilation, ITypeSymbol source, ITypeSymbol destination)\n => compilation.ClassifyConversion(source: source, destination: destination).IsImplicit;\n\n public static SyntaxNode TryGetLastStatement(IBlockOperation blockStatementOpt)\n => blockStatementOpt?.Syntax is BlockSyntax block\n ? block.Statements.LastOrDefault()\n : blockStatementOpt?.Syntax;\n\n public static void InsertStatement(\n SyntaxEditor editor,\n SyntaxNode functionDeclaration,\n bool returnsVoid,\n SyntaxNode statementToAddAfterOpt,\n StatementSyntax statement)\n {\n var body = GetBody(functionDeclaration);\n\n if (IsExpressionBody(body))\n {\n var semicolonToken = TryGetSemicolonToken(functionDeclaration) ?? SyntaxFactory.Token(SyntaxKind.SemicolonToken);\n\n if (!TryConvertExpressionBodyToStatement(body, semicolonToken, !returnsVoid, out var convertedStatement))\n {\n return;\n }\n\n // Add the new statement as the first/last statement of the new block \n // depending if we were asked to go after something or not.\n editor.SetStatements(functionDeclaration, statementToAddAfterOpt == null\n ? ImmutableArray.Create(statement, convertedStatement)\n : ImmutableArray.Create(convertedStatement, statement));\n }\n else if (body is BlockSyntax block)\n {\n // Look for the statement we were asked to go after.\n var indexToAddAfter = block.Statements.IndexOf(s => s == statementToAddAfterOpt);\n if (indexToAddAfter >= 0)\n {\n // If we find it, then insert the new statement after it.\n editor.InsertAfter(block.Statements[indexToAddAfter], statement);\n }\n else if (block.Statements.Count > 0)\n {\n // Otherwise, if we have multiple statements already, then insert ourselves\n // before the first one.\n editor.InsertBefore(block.Statements[0], statement);\n }\n else\n {\n // Otherwise, we have no statements in this block. Add the new statement\n // as the single statement the block will have.\n Debug.Assert(block.Statements.Count == 0);\n editor.ReplaceNode(block, (currentBlock, _) => ((BlockSyntax)currentBlock).AddStatements(statement));\n }\n\n // If the block was on a single line before, the format it so that the formatting\n // engine will update it to go over multiple lines. Otherwise, we can end up in\n // the strange state where the { and } tokens stay where they were originally,\n // which will look very strange like:\n //\n // a => {\n // if (...) {\n // } };\n if (CSharpSyntaxFacts.Instance.IsOnSingleLine(block, fullSpan: false))\n {\n editor.ReplaceNode(\n block,\n (currentBlock, _) => currentBlock.WithAdditionalAnnotations(Formatter.Annotation));\n }\n }\n else\n {\n editor.SetStatements(functionDeclaration, ImmutableArray.Create(statement));\n }\n }\n\n // either from an expression lambda or expression bodied member\n public static bool IsExpressionBody(SyntaxNode body)\n => body is ExpressionSyntax || body is ArrowExpressionClauseSyntax;\n\n public static bool TryConvertExpressionBodyToStatement(SyntaxNode body, SyntaxToken semicolonToken, bool createReturnStatementForExpression, out StatementSyntax statement)\n {\n Debug.Assert(IsExpressionBody(body));\n\n switch (body)\n {\n case ArrowExpressionClauseSyntax arrowClause:\n // If this is a => method, then we'll have to convert the method to have a block body.\n return arrowClause.TryConvertToStatement(semicolonToken, createReturnStatementForExpression, out statement);\n case ExpressionSyntax expression:\n // must be an expression lambda\n return expression.TryConvertToStatement(semicolonToken, createReturnStatementForExpression, out statement);\n default:\n throw ExceptionUtilities.UnexpectedValue(body);\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Diagnostics.CodeAnalysis;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.LanguageServices;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Editing;\nusing Microsoft.CodeAnalysis.Formatting;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.Operations;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp.InitializeParameter\n{\n internal static class InitializeParameterHelpers\n {\n public static bool IsFunctionDeclaration(SyntaxNode node)\n => node is BaseMethodDeclarationSyntax\n || node is LocalFunctionStatementSyntax\n || node is AnonymousFunctionExpressionSyntax;\n\n public static SyntaxNode GetBody(SyntaxNode functionDeclaration)\n => functionDeclaration switch\n {\n BaseMethodDeclarationSyntax methodDeclaration => (SyntaxNode?)methodDeclaration.Body ?? methodDeclaration.ExpressionBody!,\n LocalFunctionStatementSyntax localFunction => (SyntaxNode?)localFunction.Body ?? localFunction.ExpressionBody!,\n AnonymousFunctionExpressionSyntax anonymousFunction => anonymousFunction.Body,\n _ => throw ExceptionUtilities.UnexpectedValue(functionDeclaration),\n };\n\n private static SyntaxToken? TryGetSemicolonToken(SyntaxNode functionDeclaration)\n => functionDeclaration switch\n {\n BaseMethodDeclarationSyntax methodDeclaration => methodDeclaration.SemicolonToken,\n LocalFunctionStatementSyntax localFunction => localFunction.SemicolonToken,\n AnonymousFunctionExpressionSyntax _ => null,\n _ => throw ExceptionUtilities.UnexpectedValue(functionDeclaration),\n };\n\n public static bool IsImplicitConversion(Compilation compilation, ITypeSymbol source, ITypeSymbol destination)\n => compilation.ClassifyConversion(source: source, destination: destination).IsImplicit;\n\n public static SyntaxNode? TryGetLastStatement(IBlockOperation blockStatementOpt)\n => blockStatementOpt?.Syntax is BlockSyntax block\n ? block.Statements.LastOrDefault()\n : blockStatementOpt?.Syntax;\n\n public static void InsertStatement(\n SyntaxEditor editor,\n SyntaxNode functionDeclaration,\n bool returnsVoid,\n SyntaxNode statementToAddAfterOpt,\n StatementSyntax statement)\n {\n var body = GetBody(functionDeclaration);\n\n if (IsExpressionBody(body))\n {\n var semicolonToken = TryGetSemicolonToken(functionDeclaration) ?? SyntaxFactory.Token(SyntaxKind.SemicolonToken);\n\n if (!TryConvertExpressionBodyToStatement(body, semicolonToken, !returnsVoid, out var convertedStatement))\n {\n return;\n }\n\n // Add the new statement as the first/last statement of the new block \n // depending if we were asked to go after something or not.\n editor.SetStatements(functionDeclaration, statementToAddAfterOpt == null\n ? ImmutableArray.Create(statement, convertedStatement)\n : ImmutableArray.Create(convertedStatement, statement));\n }\n else if (body is BlockSyntax block)\n {\n // Look for the statement we were asked to go after.\n var indexToAddAfter = block.Statements.IndexOf(s => s == statementToAddAfterOpt);\n if (indexToAddAfter >= 0)\n {\n // If we find it, then insert the new statement after it.\n editor.InsertAfter(block.Statements[indexToAddAfter], statement);\n }\n else if (block.Statements.Count > 0)\n {\n // Otherwise, if we have multiple statements already, then insert ourselves\n // before the first one.\n editor.InsertBefore(block.Statements[0], statement);\n }\n else\n {\n // Otherwise, we have no statements in this block. Add the new statement\n // as the single statement the block will have.\n Debug.Assert(block.Statements.Count == 0);\n editor.ReplaceNode(block, (currentBlock, _) => ((BlockSyntax)currentBlock).AddStatements(statement));\n }\n\n // If the block was on a single line before, the format it so that the formatting\n // engine will update it to go over multiple lines. Otherwise, we can end up in\n // the strange state where the { and } tokens stay where they were originally,\n // which will look very strange like:\n //\n // a => {\n // if (...) {\n // } };\n if (CSharpSyntaxFacts.Instance.IsOnSingleLine(block, fullSpan: false))\n {\n editor.ReplaceNode(\n block,\n (currentBlock, _) => currentBlock.WithAdditionalAnnotations(Formatter.Annotation));\n }\n }\n else\n {\n editor.SetStatements(functionDeclaration, ImmutableArray.Create(statement));\n }\n }\n\n // either from an expression lambda or expression bodied member\n public static bool IsExpressionBody(SyntaxNode body)\n => body is ExpressionSyntax or ArrowExpressionClauseSyntax;\n\n public static bool TryConvertExpressionBodyToStatement(\n SyntaxNode body,\n SyntaxToken semicolonToken,\n bool createReturnStatementForExpression,\n [NotNullWhen(true)] out StatementSyntax? statement)\n {\n Debug.Assert(IsExpressionBody(body));\n\n return body switch\n {\n // If this is a => method, then we'll have to convert the method to have a block body.\n ArrowExpressionClauseSyntax arrowClause => arrowClause.TryConvertToStatement(semicolonToken, createReturnStatementForExpression, out statement),\n // must be an expression lambda\n ExpressionSyntax expression => expression.TryConvertToStatement(semicolonToken, createReturnStatementForExpression, out statement),\n _ => throw ExceptionUtilities.UnexpectedValue(body),\n };\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":109,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections;\nusing System.Collections.Concurrent;\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.CodeAnalysis.Completion;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.Packaging;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.SymbolSearch;\nusing Roslyn.Utilities;\nusing static Microsoft.CodeAnalysis.Shared.Utilities.EditorBrowsableHelpers;\n\nnamespace Microsoft.CodeAnalysis.AddImport\n{\n internal abstract partial class AbstractAddImportFeatureService\n {\n private partial class SymbolReferenceFinder\n {\n private const string AttributeSuffix = nameof(Attribute);\n\n private readonly string _diagnosticId;\n private readonly Document _document;\n private readonly SemanticModel _semanticModel;\n\n private readonly ISet _namespacesInScope;\n private readonly ISyntaxFactsService _syntaxFacts;\n private readonly AbstractAddImportFeatureService _owner;\n\n private readonly SyntaxNode _node;\n private readonly ISymbolSearchService _symbolSearchService;\n private readonly bool _searchReferenceAssemblies;\n private readonly ImmutableArray _packageSources;\n\n public SymbolReferenceFinder(\n AbstractAddImportFeatureService owner,\n Document document, SemanticModel semanticModel,\n string diagnosticId, SyntaxNode node,\n ISymbolSearchService symbolSearchService,\n bool searchReferenceAssemblies,\n ImmutableArray packageSources,\n CancellationToken cancellationToken)\n {\n _owner = owner;\n _document = document;\n _semanticModel = semanticModel;\n _diagnosticId = diagnosticId;\n _node = node;\n\n _symbolSearchService = symbolSearchService;\n _searchReferenceAssemblies = searchReferenceAssemblies;\n _packageSources = packageSources;\n\n if (_searchReferenceAssemblies || packageSources.Length > 0)\n {\n Contract.ThrowIfNull(symbolSearchService);\n }\n\n _syntaxFacts = document.GetLanguageService();\n\n _namespacesInScope = GetNamespacesInScope(cancellationToken);\n }\n\n private ISet GetNamespacesInScope(CancellationToken cancellationToken)\n {\n // Add all the namespaces brought in by imports/usings.\n var set = _owner.GetImportNamespacesInScope(_semanticModel, _node, cancellationToken);\n\n // Also add all the namespaces we're contained in. We don't want\n // to add imports for these namespaces either.\n for (var containingNamespace = _semanticModel.GetEnclosingNamespace(_node.SpanStart, cancellationToken);\n containingNamespace != null;\n containingNamespace = containingNamespace.ContainingNamespace)\n {\n set.Add(MapToCompilationNamespaceIfPossible(containingNamespace));\n }\n\n return set;\n }\n\n private INamespaceSymbol MapToCompilationNamespaceIfPossible(INamespaceSymbol containingNamespace)\n => _semanticModel.Compilation.GetCompilationNamespace(containingNamespace) ?? containingNamespace;\n\n internal Task> FindInAllSymbolsInStartingProjectAsync(\n bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new AllSymbolsProjectSearchScope(\n _owner, _document.Project, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n internal Task> FindInSourceSymbolsInProjectAsync(\n ConcurrentDictionary> projectToAssembly,\n Project project, bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new SourceSymbolsProjectSearchScope(\n _owner, projectToAssembly, project, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n internal Task> FindInMetadataSymbolsAsync(\n IAssemblySymbol assembly, ProjectId assemblyProjectId, PortableExecutableReference metadataReference,\n bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new MetadataSymbolsSearchScope(\n _owner, _document.Project.Solution, assembly, assemblyProjectId,\n metadataReference, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n private async Task> DoAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n // Spin off tasks to do all our searching in parallel\n using var _1 = ArrayBuilder>>.GetInstance(out var tasks);\n tasks.Add(GetReferencesForMatchingTypesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingNamespacesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingFieldsAndPropertiesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingExtensionMethodsAsync(searchScope));\n\n // Searching for things like \"Add\" (for collection initializers) and \"Select\"\n // (for extension methods) should only be done when doing an 'exact' search.\n // We should not do fuzzy searches for these names. In this case it's not\n // like the user was writing Add or Select, but instead we're looking for\n // viable symbols with those names to make a collection initializer or \n // query expression valid.\n if (searchScope.Exact)\n {\n tasks.Add(GetReferencesForCollectionInitializerMethodsAsync(searchScope));\n tasks.Add(GetReferencesForQueryPatternsAsync(searchScope));\n tasks.Add(GetReferencesForDeconstructAsync(searchScope));\n tasks.Add(GetReferencesForGetAwaiterAsync(searchScope));\n tasks.Add(GetReferencesForGetEnumeratorAsync(searchScope));\n tasks.Add(GetReferencesForGetAsyncEnumeratorAsync(searchScope));\n }\n\n await Task.WhenAll(tasks).ConfigureAwait(false);\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n using var _2 = ArrayBuilder.GetInstance(out var allReferences);\n foreach (var task in tasks)\n {\n var taskResult = await task.ConfigureAwait(false);\n allReferences.AddRange(taskResult);\n }\n\n return DeDupeAndSortReferences(allReferences.ToImmutable());\n }\n\n private ImmutableArray DeDupeAndSortReferences(ImmutableArray allReferences)\n {\n return allReferences\n .Distinct()\n .Where(NotNull)\n .Where(NotGlobalNamespace)\n .OrderBy((r1, r2) => r1.CompareTo(_document, r2))\n .ToImmutableArray();\n }\n\n private static void CalculateContext(\n TSimpleNameSyntax nameNode, ISyntaxFactsService syntaxFacts, out string name, out int arity,\n out bool inAttributeContext, out bool hasIncompleteParentMember, out bool looksGeneric)\n {\n // Has to be a simple identifier or generic name.\n syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out name, out arity);\n\n inAttributeContext = syntaxFacts.IsAttributeName(nameNode);\n hasIncompleteParentMember = syntaxFacts.HasIncompleteParentMember(nameNode);\n looksGeneric = syntaxFacts.LooksGeneric(nameNode);\n }\n\n /// \n /// Searches for types that match the name the user has written. Returns s\n /// to the s or s those types are\n /// contained in.\n /// \n private async Task> GetReferencesForMatchingTypesAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (!_owner.CanAddImportForType(_diagnosticId, _node, out var nameNode))\n {\n return ImmutableArray.Empty;\n }\n\n CalculateContext(\n nameNode, _syntaxFacts,\n out var name, out var arity, out var inAttributeContext,\n out var hasIncompleteParentMember, out var looksGeneric);\n\n if (ExpressionBinds(nameNode, checkForExtensionMethods: false, cancellationToken: searchScope.CancellationToken))\n {\n // If the expression bound, there's nothing to do.\n return ImmutableArray.Empty;\n }\n\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Type).ConfigureAwait(false);\n\n // also lookup type symbols with the \"Attribute\" suffix if necessary.\n if (inAttributeContext)\n {\n var attributeSymbols = await searchScope.FindDeclarationsAsync(name + AttributeSuffix, nameNode, SymbolFilter.Type).ConfigureAwait(false);\n\n symbols = symbols.AddRange(\n attributeSymbols.Select(r => r.WithDesiredName(r.DesiredName.GetWithoutAttributeSuffix(isCaseSensitive: false))));\n }\n\n var typeSymbols = OfType(symbols);\n\n var options = await _document.GetOptionsAsync(searchScope.CancellationToken).ConfigureAwait(false);\n var hideAdvancedMembers = options.GetOption(CompletionOptions.HideAdvancedMembers);\n var editorBrowserInfo = new EditorBrowsableInfo(_semanticModel.Compilation);\n\n // Only keep symbols which are accessible from the current location and that are allowed by the current\n // editor browsable rules.\n var accessibleTypeSymbols = typeSymbols.WhereAsArray(\n s => ArityAccessibilityAndAttributeContextAreCorrect(s.Symbol, arity, inAttributeContext, hasIncompleteParentMember, looksGeneric) &&\n s.Symbol.IsEditorBrowsable(hideAdvancedMembers, _semanticModel.Compilation, editorBrowserInfo));\n\n // These types may be contained within namespaces, or they may be nested \n // inside generic types. Record these namespaces/types if it would be \n // legal to add imports for them.\n\n var typesContainedDirectlyInNamespaces = accessibleTypeSymbols.WhereAsArray(s => s.Symbol.ContainingSymbol is INamespaceSymbol);\n var typesContainedDirectlyInTypes = accessibleTypeSymbols.WhereAsArray(s => s.Symbol.ContainingType != null);\n\n var namespaceReferences = GetNamespaceSymbolReferences(searchScope,\n typesContainedDirectlyInNamespaces.SelectAsArray(r => r.WithSymbol(r.Symbol.ContainingNamespace)));\n\n var typeReferences = typesContainedDirectlyInTypes.SelectAsArray(\n r => searchScope.CreateReference(r.WithSymbol(r.Symbol.ContainingType)));\n\n return namespaceReferences.Concat(typeReferences);\n }\n\n private bool ArityAccessibilityAndAttributeContextAreCorrect(\n ITypeSymbol symbol,\n int arity,\n bool inAttributeContext,\n bool hasIncompleteParentMember,\n bool looksGeneric)\n {\n if (inAttributeContext && !symbol.IsAttribute())\n {\n return false;\n }\n\n if (!symbol.IsAccessibleWithin(_semanticModel.Compilation.Assembly))\n {\n return false;\n }\n\n if (looksGeneric && symbol.GetTypeArguments().Length == 0)\n {\n return false;\n }\n\n return arity == 0 || symbol.GetArity() == arity || hasIncompleteParentMember;\n }\n\n /// \n /// Searches for namespaces that match the name the user has written. Returns s\n /// to the s those namespaces are contained in.\n /// \n private async Task> GetReferencesForMatchingNamespacesAsync(\n SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForNamespace(_diagnosticId, _node, out var nameNode))\n {\n _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);\n\n if (arity == 0 &&\n !ExpressionBinds(nameNode, checkForExtensionMethods: false, cancellationToken: searchScope.CancellationToken))\n {\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Namespace).ConfigureAwait(false);\n var namespaceSymbols = OfType(symbols);\n var containingNamespaceSymbols = OfType(symbols).SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, containingNamespaceSymbols);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Specialized finder for the \"Color Color\" case. Used when we have \"Color.Black\" and \"Color\"\n /// bound to a Field/Property, but not a type. In this case, we want to look for namespaces\n /// containing 'Color' as if we import them it can resolve this issue.\n /// \n private async Task> GetReferencesForMatchingFieldsAndPropertiesAsync(\n SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out var nameNode) &&\n nameNode != null)\n {\n // We have code like \"Color.Black\". \"Color\" bound to a 'Color Color' property, and\n // 'Black' did not bind. We want to find a type called 'Color' that will actually\n // allow 'Black' to bind.\n var syntaxFacts = _document.GetLanguageService();\n if (syntaxFacts.IsNameOfSimpleMemberAccessExpression(nameNode) ||\n syntaxFacts.IsNameOfMemberBindingExpression(nameNode))\n {\n var expression = syntaxFacts.IsNameOfSimpleMemberAccessExpression(nameNode)\n ? syntaxFacts.GetExpressionOfMemberAccessExpression(nameNode.Parent, allowImplicitTarget: true)\n : syntaxFacts.GetTargetOfMemberBinding(nameNode.Parent);\n if (expression is TSimpleNameSyntax simpleName)\n {\n // Check if the expression before the dot binds to a property or field.\n var symbol = _semanticModel.GetSymbolInfo(expression, searchScope.CancellationToken).GetAnySymbol();\n if (symbol?.Kind is SymbolKind.Property or SymbolKind.Field)\n {\n // Check if we have the 'Color Color' case.\n var propertyOrFieldType = symbol.GetSymbolType();\n if (propertyOrFieldType is INamedTypeSymbol propertyType &&\n Equals(propertyType.Name, symbol.Name))\n {\n // Try to look up 'Color' as a type.\n var symbolResults = await searchScope.FindDeclarationsAsync(\n symbol.Name, simpleName, SymbolFilter.Type).ConfigureAwait(false);\n\n // Return results that have accessible members.\n var namedTypeSymbols = OfType(symbolResults);\n var name = nameNode.GetFirstToken().ValueText;\n var namespaceResults =\n namedTypeSymbols.WhereAsArray(sr => HasAccessibleStaticFieldOrProperty(sr.Symbol, name))\n .SelectAsArray(sr => sr.WithSymbol(sr.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, namespaceResults);\n }\n }\n }\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private bool HasAccessibleStaticFieldOrProperty(INamedTypeSymbol namedType, string fieldOrPropertyName)\n {\n return namedType.GetMembers(fieldOrPropertyName)\n .Any(m => (m is IFieldSymbol || m is IPropertySymbol) &&\n m.IsStatic &&\n m.IsAccessibleWithin(_semanticModel.Compilation.Assembly));\n }\n\n /// \n /// Searches for extension methods that match the name the user has written. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForMatchingExtensionMethodsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out var nameNode) &&\n nameNode != null)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n // See if the name binds. If it does, there's nothing further we need to do.\n if (!ExpressionBinds(nameNode, checkForExtensionMethods: true, cancellationToken: searchScope.CancellationToken))\n {\n _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);\n if (name != null)\n {\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Member).ConfigureAwait(false);\n\n var methodSymbols = OfType(symbols);\n\n var extensionMethodSymbols = GetViableExtensionMethods(\n methodSymbols, nameNode.Parent, searchScope.CancellationToken);\n\n var namespaceSymbols = extensionMethodSymbols.SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n return GetNamespaceSymbolReferences(searchScope, namespaceSymbols);\n }\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private ImmutableArray> GetViableExtensionMethods(\n ImmutableArray> methodSymbols,\n SyntaxNode expression, CancellationToken cancellationToken)\n {\n return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray(\n s => _owner.IsViableExtensionMethod(s.Symbol, expression, _semanticModel, _syntaxFacts, cancellationToken));\n }\n\n private ImmutableArray> GetViableExtensionMethods(\n ImmutableArray> methodSymbols, ITypeSymbol typeSymbol)\n {\n return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray(\n s => IsViableExtensionMethod(s.Symbol, typeSymbol));\n }\n\n private ImmutableArray> GetViableExtensionMethodsWorker(\n ImmutableArray> methodSymbols)\n {\n return methodSymbols.WhereAsArray(\n s => s.Symbol.IsExtensionMethod &&\n s.Symbol.IsAccessibleWithin(_semanticModel.Compilation.Assembly));\n }\n\n /// \n /// Searches for extension methods exactly called 'Add'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForCollectionInitializerMethodsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out _) &&\n !_syntaxFacts.IsSimpleName(_node) &&\n _owner.IsAddMethodContext(_node, _semanticModel))\n {\n var symbols = await searchScope.FindDeclarationsAsync(\n nameof(IList.Add), nameNode: null, filter: SymbolFilter.Member).ConfigureAwait(false);\n\n // Note: there is no desiredName for these search results. We're searching for\n // extension methods called \"Add\", but we have no intention of renaming any \n // of the existing user code to that name.\n var methodSymbols = OfType(symbols).SelectAsArray(s => s.WithDesiredName(null));\n\n var viableMethods = GetViableExtensionMethods(\n methodSymbols, _node.Parent, searchScope.CancellationToken);\n\n return GetNamespaceSymbolReferences(searchScope,\n viableMethods.SelectAsArray(m => m.WithSymbol(m.Symbol.ContainingNamespace)));\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'Select'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForQueryPatternsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForQuery(_diagnosticId, _node))\n {\n var type = _owner.GetQueryClauseInfo(_semanticModel, _node, searchScope.CancellationToken);\n if (type != null)\n {\n // find extension methods named \"Select\"\n return await GetReferencesForExtensionMethodAsync(\n searchScope, nameof(Enumerable.Select), type).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetAwaiter'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetAwaiterAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetAwaiter(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetAwaitInfo(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetAwaiter, type,\n m => m.IsValidGetAwaiter()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetEnumerator'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetEnumeratorAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetEnumerator(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetEnumeratorMethodName, type,\n m => m.IsValidGetEnumerator()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetAsyncEnumerator'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetAsyncEnumeratorAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetAsyncEnumerator(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetAsyncEnumeratorMethodName, type,\n m => m.IsValidGetAsyncEnumerator()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'Deconstruct'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForDeconstructAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForDeconstruct(_diagnosticId, _node))\n {\n var type = _owner.GetDeconstructInfo(_semanticModel, _node, searchScope.CancellationToken);\n if (type != null)\n {\n // Note: we could check that the extension methods have the right number of out-params. \n // But that would involve figuring out what we're trying to deconstruct into. For now\n // we'll just be permissive, with the assumption that there won't be that many matching\n // 'Deconstruct' extension methods for the type of node that we're on.\n return await GetReferencesForExtensionMethodAsync(\n searchScope, \"Deconstruct\", type,\n m => m.ReturnsVoid).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private async Task> GetReferencesForExtensionMethodAsync(\n SearchScope searchScope, string name, ITypeSymbol type, Func predicate = null)\n {\n var symbols = await searchScope.FindDeclarationsAsync(\n name, nameNode: null, filter: SymbolFilter.Member).ConfigureAwait(false);\n\n // Note: there is no \"desiredName\" when doing this. We're not going to do any\n // renames of the user code. We're just looking for an extension method called \n // \"Select\", but that name has no bearing on the code in question that we're\n // trying to fix up.\n var methodSymbols = OfType(symbols).SelectAsArray(s => s.WithDesiredName(null));\n var viableExtensionMethods = GetViableExtensionMethods(methodSymbols, type);\n\n if (predicate != null)\n {\n viableExtensionMethods = viableExtensionMethods.WhereAsArray(s => predicate(s.Symbol));\n }\n\n var namespaceSymbols = viableExtensionMethods.SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, namespaceSymbols);\n }\n\n protected bool ExpressionBinds(\n TSimpleNameSyntax nameNode, bool checkForExtensionMethods, CancellationToken cancellationToken)\n {\n // See if the name binds to something other then the error type. If it does, there's nothing further we need to do.\n // For extension methods, however, we will continue to search if there exists any better matched method.\n cancellationToken.ThrowIfCancellationRequested();\n var symbolInfo = _semanticModel.GetSymbolInfo(nameNode, cancellationToken);\n if (symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure && !checkForExtensionMethods)\n {\n return true;\n }\n\n return symbolInfo.Symbol != null;\n }\n\n private ImmutableArray GetNamespaceSymbolReferences(\n SearchScope scope, ImmutableArray> namespaces)\n {\n using var _ = ArrayBuilder.GetInstance(out var references);\n\n foreach (var namespaceResult in namespaces)\n {\n var symbol = namespaceResult.Symbol;\n var mappedResult = namespaceResult.WithSymbol(MapToCompilationNamespaceIfPossible(namespaceResult.Symbol));\n var namespaceIsInScope = _namespacesInScope.Contains(mappedResult.Symbol);\n if (!symbol.IsGlobalNamespace && !namespaceIsInScope)\n references.Add(scope.CreateReference(mappedResult));\n }\n\n return references.ToImmutable();\n }\n\n private static ImmutableArray> OfType(ImmutableArray> symbols) where T : ISymbol\n {\n return symbols.WhereAsArray(s => s.Symbol is T)\n .SelectAsArray(s => s.WithSymbol((T)s.Symbol));\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections;\nusing System.Collections.Concurrent;\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Microsoft.CodeAnalysis.Completion;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.Packaging;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.SymbolSearch;\nusing Roslyn.Utilities;\nusing static Microsoft.CodeAnalysis.Shared.Utilities.EditorBrowsableHelpers;\n\nnamespace Microsoft.CodeAnalysis.AddImport\n{\n internal abstract partial class AbstractAddImportFeatureService\n {\n private partial class SymbolReferenceFinder\n {\n private const string AttributeSuffix = nameof(Attribute);\n\n private readonly string _diagnosticId;\n private readonly Document _document;\n private readonly SemanticModel _semanticModel;\n\n private readonly ISet _namespacesInScope;\n private readonly ISyntaxFactsService _syntaxFacts;\n private readonly AbstractAddImportFeatureService _owner;\n\n private readonly SyntaxNode _node;\n private readonly ISymbolSearchService _symbolSearchService;\n private readonly bool _searchReferenceAssemblies;\n private readonly ImmutableArray _packageSources;\n\n public SymbolReferenceFinder(\n AbstractAddImportFeatureService owner,\n Document document, SemanticModel semanticModel,\n string diagnosticId, SyntaxNode node,\n ISymbolSearchService symbolSearchService,\n bool searchReferenceAssemblies,\n ImmutableArray packageSources,\n CancellationToken cancellationToken)\n {\n _owner = owner;\n _document = document;\n _semanticModel = semanticModel;\n _diagnosticId = diagnosticId;\n _node = node;\n\n _symbolSearchService = symbolSearchService;\n _searchReferenceAssemblies = searchReferenceAssemblies;\n _packageSources = packageSources;\n\n if (_searchReferenceAssemblies || packageSources.Length > 0)\n {\n Contract.ThrowIfNull(symbolSearchService);\n }\n\n _syntaxFacts = document.GetLanguageService();\n\n _namespacesInScope = GetNamespacesInScope(cancellationToken);\n }\n\n private ISet GetNamespacesInScope(CancellationToken cancellationToken)\n {\n // Add all the namespaces brought in by imports/usings.\n var set = _owner.GetImportNamespacesInScope(_semanticModel, _node, cancellationToken);\n\n // Also add all the namespaces we're contained in. We don't want\n // to add imports for these namespaces either.\n for (var containingNamespace = _semanticModel.GetEnclosingNamespace(_node.SpanStart, cancellationToken);\n containingNamespace != null;\n containingNamespace = containingNamespace.ContainingNamespace)\n {\n set.Add(MapToCompilationNamespaceIfPossible(containingNamespace));\n }\n\n return set;\n }\n\n private INamespaceSymbol MapToCompilationNamespaceIfPossible(INamespaceSymbol containingNamespace)\n => _semanticModel.Compilation.GetCompilationNamespace(containingNamespace) ?? containingNamespace;\n\n internal Task> FindInAllSymbolsInStartingProjectAsync(\n bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new AllSymbolsProjectSearchScope(\n _owner, _document.Project, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n internal Task> FindInSourceSymbolsInProjectAsync(\n ConcurrentDictionary> projectToAssembly,\n Project project, bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new SourceSymbolsProjectSearchScope(\n _owner, projectToAssembly, project, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n internal Task> FindInMetadataSymbolsAsync(\n IAssemblySymbol assembly, ProjectId assemblyProjectId, PortableExecutableReference metadataReference,\n bool exact, CancellationToken cancellationToken)\n {\n var searchScope = new MetadataSymbolsSearchScope(\n _owner, _document.Project.Solution, assembly, assemblyProjectId,\n metadataReference, exact, cancellationToken);\n return DoAsync(searchScope);\n }\n\n private async Task> DoAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n // Spin off tasks to do all our searching in parallel\n using var _1 = ArrayBuilder>>.GetInstance(out var tasks);\n tasks.Add(GetReferencesForMatchingTypesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingNamespacesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingFieldsAndPropertiesAsync(searchScope));\n tasks.Add(GetReferencesForMatchingExtensionMethodsAsync(searchScope));\n\n // Searching for things like \"Add\" (for collection initializers) and \"Select\"\n // (for extension methods) should only be done when doing an 'exact' search.\n // We should not do fuzzy searches for these names. In this case it's not\n // like the user was writing Add or Select, but instead we're looking for\n // viable symbols with those names to make a collection initializer or \n // query expression valid.\n if (searchScope.Exact)\n {\n tasks.Add(GetReferencesForCollectionInitializerMethodsAsync(searchScope));\n tasks.Add(GetReferencesForQueryPatternsAsync(searchScope));\n tasks.Add(GetReferencesForDeconstructAsync(searchScope));\n tasks.Add(GetReferencesForGetAwaiterAsync(searchScope));\n tasks.Add(GetReferencesForGetEnumeratorAsync(searchScope));\n tasks.Add(GetReferencesForGetAsyncEnumeratorAsync(searchScope));\n }\n\n await Task.WhenAll(tasks).ConfigureAwait(false);\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n using var _2 = ArrayBuilder.GetInstance(out var allReferences);\n foreach (var task in tasks)\n {\n var taskResult = await task.ConfigureAwait(false);\n allReferences.AddRange(taskResult);\n }\n\n return DeDupeAndSortReferences(allReferences.ToImmutable());\n }\n\n private ImmutableArray DeDupeAndSortReferences(ImmutableArray allReferences)\n {\n return allReferences\n .Distinct()\n .Where(NotNull)\n .Where(NotGlobalNamespace)\n .OrderBy((r1, r2) => r1.CompareTo(_document, r2))\n .ToImmutableArray();\n }\n\n private static void CalculateContext(\n TSimpleNameSyntax nameNode, ISyntaxFactsService syntaxFacts, out string name, out int arity,\n out bool inAttributeContext, out bool hasIncompleteParentMember, out bool looksGeneric)\n {\n // Has to be a simple identifier or generic name.\n syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out name, out arity);\n\n inAttributeContext = syntaxFacts.IsAttributeName(nameNode);\n hasIncompleteParentMember = nameNode?.Parent?.RawKind == syntaxFacts.SyntaxKinds.IncompleteMember;\n looksGeneric = syntaxFacts.LooksGeneric(nameNode);\n }\n\n /// \n /// Searches for types that match the name the user has written. Returns s\n /// to the s or s those types are\n /// contained in.\n /// \n private async Task> GetReferencesForMatchingTypesAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (!_owner.CanAddImportForType(_diagnosticId, _node, out var nameNode))\n {\n return ImmutableArray.Empty;\n }\n\n CalculateContext(\n nameNode, _syntaxFacts,\n out var name, out var arity, out var inAttributeContext,\n out var hasIncompleteParentMember, out var looksGeneric);\n\n if (ExpressionBinds(nameNode, checkForExtensionMethods: false, cancellationToken: searchScope.CancellationToken))\n {\n // If the expression bound, there's nothing to do.\n return ImmutableArray.Empty;\n }\n\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Type).ConfigureAwait(false);\n\n // also lookup type symbols with the \"Attribute\" suffix if necessary.\n if (inAttributeContext)\n {\n var attributeSymbols = await searchScope.FindDeclarationsAsync(name + AttributeSuffix, nameNode, SymbolFilter.Type).ConfigureAwait(false);\n\n symbols = symbols.AddRange(\n attributeSymbols.Select(r => r.WithDesiredName(r.DesiredName.GetWithoutAttributeSuffix(isCaseSensitive: false))));\n }\n\n var typeSymbols = OfType(symbols);\n\n var options = await _document.GetOptionsAsync(searchScope.CancellationToken).ConfigureAwait(false);\n var hideAdvancedMembers = options.GetOption(CompletionOptions.HideAdvancedMembers);\n var editorBrowserInfo = new EditorBrowsableInfo(_semanticModel.Compilation);\n\n // Only keep symbols which are accessible from the current location and that are allowed by the current\n // editor browsable rules.\n var accessibleTypeSymbols = typeSymbols.WhereAsArray(\n s => ArityAccessibilityAndAttributeContextAreCorrect(s.Symbol, arity, inAttributeContext, hasIncompleteParentMember, looksGeneric) &&\n s.Symbol.IsEditorBrowsable(hideAdvancedMembers, _semanticModel.Compilation, editorBrowserInfo));\n\n // These types may be contained within namespaces, or they may be nested \n // inside generic types. Record these namespaces/types if it would be \n // legal to add imports for them.\n\n var typesContainedDirectlyInNamespaces = accessibleTypeSymbols.WhereAsArray(s => s.Symbol.ContainingSymbol is INamespaceSymbol);\n var typesContainedDirectlyInTypes = accessibleTypeSymbols.WhereAsArray(s => s.Symbol.ContainingType != null);\n\n var namespaceReferences = GetNamespaceSymbolReferences(searchScope,\n typesContainedDirectlyInNamespaces.SelectAsArray(r => r.WithSymbol(r.Symbol.ContainingNamespace)));\n\n var typeReferences = typesContainedDirectlyInTypes.SelectAsArray(\n r => searchScope.CreateReference(r.WithSymbol(r.Symbol.ContainingType)));\n\n return namespaceReferences.Concat(typeReferences);\n }\n\n private bool ArityAccessibilityAndAttributeContextAreCorrect(\n ITypeSymbol symbol,\n int arity,\n bool inAttributeContext,\n bool hasIncompleteParentMember,\n bool looksGeneric)\n {\n if (inAttributeContext && !symbol.IsAttribute())\n {\n return false;\n }\n\n if (!symbol.IsAccessibleWithin(_semanticModel.Compilation.Assembly))\n {\n return false;\n }\n\n if (looksGeneric && symbol.GetTypeArguments().Length == 0)\n {\n return false;\n }\n\n return arity == 0 || symbol.GetArity() == arity || hasIncompleteParentMember;\n }\n\n /// \n /// Searches for namespaces that match the name the user has written. Returns s\n /// to the s those namespaces are contained in.\n /// \n private async Task> GetReferencesForMatchingNamespacesAsync(\n SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForNamespace(_diagnosticId, _node, out var nameNode))\n {\n _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);\n\n if (arity == 0 &&\n !ExpressionBinds(nameNode, checkForExtensionMethods: false, cancellationToken: searchScope.CancellationToken))\n {\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Namespace).ConfigureAwait(false);\n var namespaceSymbols = OfType(symbols);\n var containingNamespaceSymbols = OfType(symbols).SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, containingNamespaceSymbols);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Specialized finder for the \"Color Color\" case. Used when we have \"Color.Black\" and \"Color\"\n /// bound to a Field/Property, but not a type. In this case, we want to look for namespaces\n /// containing 'Color' as if we import them it can resolve this issue.\n /// \n private async Task> GetReferencesForMatchingFieldsAndPropertiesAsync(\n SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out var nameNode) &&\n nameNode != null)\n {\n // We have code like \"Color.Black\". \"Color\" bound to a 'Color Color' property, and\n // 'Black' did not bind. We want to find a type called 'Color' that will actually\n // allow 'Black' to bind.\n var syntaxFacts = _document.GetLanguageService();\n if (syntaxFacts.IsNameOfSimpleMemberAccessExpression(nameNode) ||\n syntaxFacts.IsNameOfMemberBindingExpression(nameNode))\n {\n var expression = syntaxFacts.IsNameOfSimpleMemberAccessExpression(nameNode)\n ? syntaxFacts.GetExpressionOfMemberAccessExpression(nameNode.Parent, allowImplicitTarget: true)\n : syntaxFacts.GetTargetOfMemberBinding(nameNode.Parent);\n if (expression is TSimpleNameSyntax simpleName)\n {\n // Check if the expression before the dot binds to a property or field.\n var symbol = _semanticModel.GetSymbolInfo(expression, searchScope.CancellationToken).GetAnySymbol();\n if (symbol?.Kind is SymbolKind.Property or SymbolKind.Field)\n {\n // Check if we have the 'Color Color' case.\n var propertyOrFieldType = symbol.GetSymbolType();\n if (propertyOrFieldType is INamedTypeSymbol propertyType &&\n Equals(propertyType.Name, symbol.Name))\n {\n // Try to look up 'Color' as a type.\n var symbolResults = await searchScope.FindDeclarationsAsync(\n symbol.Name, simpleName, SymbolFilter.Type).ConfigureAwait(false);\n\n // Return results that have accessible members.\n var namedTypeSymbols = OfType(symbolResults);\n var name = nameNode.GetFirstToken().ValueText;\n var namespaceResults =\n namedTypeSymbols.WhereAsArray(sr => HasAccessibleStaticFieldOrProperty(sr.Symbol, name))\n .SelectAsArray(sr => sr.WithSymbol(sr.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, namespaceResults);\n }\n }\n }\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private bool HasAccessibleStaticFieldOrProperty(INamedTypeSymbol namedType, string fieldOrPropertyName)\n {\n return namedType.GetMembers(fieldOrPropertyName)\n .Any(m => (m is IFieldSymbol || m is IPropertySymbol) &&\n m.IsStatic &&\n m.IsAccessibleWithin(_semanticModel.Compilation.Assembly));\n }\n\n /// \n /// Searches for extension methods that match the name the user has written. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForMatchingExtensionMethodsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out var nameNode) &&\n nameNode != null)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n // See if the name binds. If it does, there's nothing further we need to do.\n if (!ExpressionBinds(nameNode, checkForExtensionMethods: true, cancellationToken: searchScope.CancellationToken))\n {\n _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);\n if (name != null)\n {\n var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Member).ConfigureAwait(false);\n\n var methodSymbols = OfType(symbols);\n\n var extensionMethodSymbols = GetViableExtensionMethods(\n methodSymbols, nameNode.Parent, searchScope.CancellationToken);\n\n var namespaceSymbols = extensionMethodSymbols.SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n return GetNamespaceSymbolReferences(searchScope, namespaceSymbols);\n }\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private ImmutableArray> GetViableExtensionMethods(\n ImmutableArray> methodSymbols,\n SyntaxNode expression, CancellationToken cancellationToken)\n {\n return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray(\n s => _owner.IsViableExtensionMethod(s.Symbol, expression, _semanticModel, _syntaxFacts, cancellationToken));\n }\n\n private ImmutableArray> GetViableExtensionMethods(\n ImmutableArray> methodSymbols, ITypeSymbol typeSymbol)\n {\n return GetViableExtensionMethodsWorker(methodSymbols).WhereAsArray(\n s => IsViableExtensionMethod(s.Symbol, typeSymbol));\n }\n\n private ImmutableArray> GetViableExtensionMethodsWorker(\n ImmutableArray> methodSymbols)\n {\n return methodSymbols.WhereAsArray(\n s => s.Symbol.IsExtensionMethod &&\n s.Symbol.IsAccessibleWithin(_semanticModel.Compilation.Assembly));\n }\n\n /// \n /// Searches for extension methods exactly called 'Add'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForCollectionInitializerMethodsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n if (_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out _) &&\n !_syntaxFacts.IsSimpleName(_node) &&\n _owner.IsAddMethodContext(_node, _semanticModel))\n {\n var symbols = await searchScope.FindDeclarationsAsync(\n nameof(IList.Add), nameNode: null, filter: SymbolFilter.Member).ConfigureAwait(false);\n\n // Note: there is no desiredName for these search results. We're searching for\n // extension methods called \"Add\", but we have no intention of renaming any \n // of the existing user code to that name.\n var methodSymbols = OfType(symbols).SelectAsArray(s => s.WithDesiredName(null));\n\n var viableMethods = GetViableExtensionMethods(\n methodSymbols, _node.Parent, searchScope.CancellationToken);\n\n return GetNamespaceSymbolReferences(searchScope,\n viableMethods.SelectAsArray(m => m.WithSymbol(m.Symbol.ContainingNamespace)));\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'Select'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForQueryPatternsAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForQuery(_diagnosticId, _node))\n {\n var type = _owner.GetQueryClauseInfo(_semanticModel, _node, searchScope.CancellationToken);\n if (type != null)\n {\n // find extension methods named \"Select\"\n return await GetReferencesForExtensionMethodAsync(\n searchScope, nameof(Enumerable.Select), type).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetAwaiter'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetAwaiterAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetAwaiter(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetAwaitInfo(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetAwaiter, type,\n m => m.IsValidGetAwaiter()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetEnumerator'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetEnumeratorAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetEnumerator(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetEnumeratorMethodName, type,\n m => m.IsValidGetEnumerator()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'GetAsyncEnumerator'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForGetAsyncEnumeratorAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForGetAsyncEnumerator(_diagnosticId, _syntaxFacts, _node))\n {\n var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);\n if (type != null)\n {\n return await GetReferencesForExtensionMethodAsync(searchScope, WellKnownMemberNames.GetAsyncEnumeratorMethodName, type,\n m => m.IsValidGetAsyncEnumerator()).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n /// \n /// Searches for extension methods exactly called 'Deconstruct'. Returns\n /// s to the s that contain\n /// the static classes that those extension methods are contained in.\n /// \n private async Task> GetReferencesForDeconstructAsync(SearchScope searchScope)\n {\n searchScope.CancellationToken.ThrowIfCancellationRequested();\n\n if (_owner.CanAddImportForDeconstruct(_diagnosticId, _node))\n {\n var type = _owner.GetDeconstructInfo(_semanticModel, _node, searchScope.CancellationToken);\n if (type != null)\n {\n // Note: we could check that the extension methods have the right number of out-params. \n // But that would involve figuring out what we're trying to deconstruct into. For now\n // we'll just be permissive, with the assumption that there won't be that many matching\n // 'Deconstruct' extension methods for the type of node that we're on.\n return await GetReferencesForExtensionMethodAsync(\n searchScope, \"Deconstruct\", type,\n m => m.ReturnsVoid).ConfigureAwait(false);\n }\n }\n\n return ImmutableArray.Empty;\n }\n\n private async Task> GetReferencesForExtensionMethodAsync(\n SearchScope searchScope, string name, ITypeSymbol type, Func predicate = null)\n {\n var symbols = await searchScope.FindDeclarationsAsync(\n name, nameNode: null, filter: SymbolFilter.Member).ConfigureAwait(false);\n\n // Note: there is no \"desiredName\" when doing this. We're not going to do any\n // renames of the user code. We're just looking for an extension method called \n // \"Select\", but that name has no bearing on the code in question that we're\n // trying to fix up.\n var methodSymbols = OfType(symbols).SelectAsArray(s => s.WithDesiredName(null));\n var viableExtensionMethods = GetViableExtensionMethods(methodSymbols, type);\n\n if (predicate != null)\n {\n viableExtensionMethods = viableExtensionMethods.WhereAsArray(s => predicate(s.Symbol));\n }\n\n var namespaceSymbols = viableExtensionMethods.SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));\n\n return GetNamespaceSymbolReferences(searchScope, namespaceSymbols);\n }\n\n protected bool ExpressionBinds(\n TSimpleNameSyntax nameNode, bool checkForExtensionMethods, CancellationToken cancellationToken)\n {\n // See if the name binds to something other then the error type. If it does, there's nothing further we need to do.\n // For extension methods, however, we will continue to search if there exists any better matched method.\n cancellationToken.ThrowIfCancellationRequested();\n var symbolInfo = _semanticModel.GetSymbolInfo(nameNode, cancellationToken);\n if (symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure && !checkForExtensionMethods)\n {\n return true;\n }\n\n return symbolInfo.Symbol != null;\n }\n\n private ImmutableArray GetNamespaceSymbolReferences(\n SearchScope scope, ImmutableArray> namespaces)\n {\n using var _ = ArrayBuilder.GetInstance(out var references);\n\n foreach (var namespaceResult in namespaces)\n {\n var symbol = namespaceResult.Symbol;\n var mappedResult = namespaceResult.WithSymbol(MapToCompilationNamespaceIfPossible(namespaceResult.Symbol));\n var namespaceIsInScope = _namespacesInScope.Contains(mappedResult.Symbol);\n if (!symbol.IsGlobalNamespace && !namespaceIsInScope)\n references.Add(scope.CreateReference(mappedResult));\n }\n\n return references.ToImmutable();\n }\n\n private static ImmutableArray> OfType(ImmutableArray> symbols) where T : ISymbol\n {\n return symbols.WhereAsArray(s => s.Symbol is T)\n .SelectAsArray(s => s.WithSymbol((T)s.Symbol));\n }\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":110,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/BlockSyntaxExtensions.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Linq;\nusing Microsoft.CodeAnalysis.CodeStyle;\nusing Microsoft.CodeAnalysis.CSharp.LanguageServices;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Extensions\n{\n internal static class BlockSyntaxExtensions\n {\n public static bool TryConvertToExpressionBody(\n this BlockSyntax block,\n ParseOptions options, ExpressionBodyPreference preference,\n out ExpressionSyntax expression,\n out SyntaxToken semicolonToken)\n {\n if (preference != ExpressionBodyPreference.Never &&\n block != null && block.Statements.Count == 1)\n {\n var firstStatement = block.Statements[0];\n\n var version = ((CSharpParseOptions)options).LanguageVersion;\n if (TryGetExpression(version, firstStatement, out expression, out semicolonToken) &&\n MatchesPreference(expression, preference))\n {\n // The close brace of the block may have important trivia on it (like \n // comments or directives). Preserve them on the semicolon when we\n // convert to an expression body.\n semicolonToken = semicolonToken.WithAppendedTrailingTrivia(\n block.CloseBraceToken.LeadingTrivia.Where(t => !t.IsWhitespaceOrEndOfLine()));\n return true;\n }\n }\n\n expression = null;\n semicolonToken = default;\n return false;\n }\n\n public static bool TryConvertToArrowExpressionBody(\n this BlockSyntax block, SyntaxKind declarationKind,\n ParseOptions options, ExpressionBodyPreference preference,\n out ArrowExpressionClauseSyntax arrowExpression,\n out SyntaxToken semicolonToken)\n {\n var version = ((CSharpParseOptions)options).LanguageVersion;\n\n // We can always use arrow-expression bodies in C# 7 or above.\n // We can also use them in C# 6, but only a select set of member kinds.\n var acceptableVersion =\n version >= LanguageVersion.CSharp7 ||\n (version >= LanguageVersion.CSharp6 && IsSupportedInCSharp6(declarationKind));\n\n if (!acceptableVersion ||\n !block.TryConvertToExpressionBody(\n options, preference,\n out var expression, out semicolonToken))\n {\n arrowExpression = null;\n semicolonToken = default;\n return false;\n }\n\n arrowExpression = SyntaxFactory.ArrowExpressionClause(expression);\n return true;\n }\n\n private static bool IsSupportedInCSharp6(SyntaxKind declarationKind)\n {\n switch (declarationKind)\n {\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n case SyntaxKind.AddAccessorDeclaration:\n case SyntaxKind.RemoveAccessorDeclaration:\n case SyntaxKind.GetAccessorDeclaration:\n case SyntaxKind.SetAccessorDeclaration:\n return false;\n }\n\n return true;\n }\n\n public static bool MatchesPreference(\n ExpressionSyntax expression, ExpressionBodyPreference preference)\n {\n if (preference == ExpressionBodyPreference.WhenPossible)\n {\n return true;\n }\n\n Contract.ThrowIfFalse(preference == ExpressionBodyPreference.WhenOnSingleLine);\n return CSharpSyntaxFacts.Instance.IsOnSingleLine(expression, fullSpan: false);\n }\n\n private static bool TryGetExpression(\n LanguageVersion version, StatementSyntax firstStatement,\n out ExpressionSyntax expression, out SyntaxToken semicolonToken)\n {\n if (firstStatement is ExpressionStatementSyntax exprStatement)\n {\n expression = exprStatement.Expression;\n semicolonToken = exprStatement.SemicolonToken;\n return true;\n }\n else if (firstStatement is ReturnStatementSyntax returnStatement)\n {\n if (returnStatement.Expression != null)\n {\n // If there are any comments or directives on the return keyword, move them to\n // the expression.\n expression = firstStatement.GetLeadingTrivia().Any(t => t.IsDirective || t.IsSingleOrMultiLineComment())\n ? returnStatement.Expression.WithLeadingTrivia(returnStatement.GetLeadingTrivia())\n : returnStatement.Expression;\n semicolonToken = returnStatement.SemicolonToken;\n return true;\n }\n }\n else if (firstStatement is ThrowStatementSyntax throwStatement)\n {\n if (version >= LanguageVersion.CSharp7 && throwStatement.Expression != null)\n {\n expression = SyntaxFactory.ThrowExpression(throwStatement.ThrowKeyword, throwStatement.Expression);\n semicolonToken = throwStatement.SemicolonToken;\n return true;\n }\n }\n\n expression = null;\n semicolonToken = default;\n return false;\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Linq;\nusing Microsoft.CodeAnalysis.CodeStyle;\nusing Microsoft.CodeAnalysis.CSharp.LanguageServices;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Roslyn.Utilities;\nusing System.Diagnostics.CodeAnalysis;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Extensions\n{\n internal static class BlockSyntaxExtensions\n {\n public static bool TryConvertToExpressionBody(\n this BlockSyntax block,\n ParseOptions options, ExpressionBodyPreference preference,\n [NotNullWhen(true)] out ExpressionSyntax? expression,\n out SyntaxToken semicolonToken)\n {\n if (preference != ExpressionBodyPreference.Never &&\n block != null && block.Statements.Count == 1)\n {\n var firstStatement = block.Statements[0];\n\n var version = ((CSharpParseOptions)options).LanguageVersion;\n if (TryGetExpression(version, firstStatement, out expression, out semicolonToken) &&\n MatchesPreference(expression, preference))\n {\n // The close brace of the block may have important trivia on it (like \n // comments or directives). Preserve them on the semicolon when we\n // convert to an expression body.\n semicolonToken = semicolonToken.WithAppendedTrailingTrivia(\n block.CloseBraceToken.LeadingTrivia.Where(t => !t.IsWhitespaceOrEndOfLine()));\n return true;\n }\n }\n\n expression = null;\n semicolonToken = default;\n return false;\n }\n\n public static bool TryConvertToArrowExpressionBody(\n this BlockSyntax block, SyntaxKind declarationKind,\n ParseOptions options, ExpressionBodyPreference preference,\n [NotNullWhen(true)] out ArrowExpressionClauseSyntax? arrowExpression,\n out SyntaxToken semicolonToken)\n {\n var version = ((CSharpParseOptions)options).LanguageVersion;\n\n // We can always use arrow-expression bodies in C# 7 or above.\n // We can also use them in C# 6, but only a select set of member kinds.\n var acceptableVersion =\n version >= LanguageVersion.CSharp7 ||\n (version >= LanguageVersion.CSharp6 && IsSupportedInCSharp6(declarationKind));\n\n if (!acceptableVersion ||\n !block.TryConvertToExpressionBody(\n options, preference,\n out var expression, out semicolonToken))\n {\n arrowExpression = null;\n semicolonToken = default;\n return false;\n }\n\n arrowExpression = SyntaxFactory.ArrowExpressionClause(expression);\n return true;\n }\n\n private static bool IsSupportedInCSharp6(SyntaxKind declarationKind)\n {\n switch (declarationKind)\n {\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n case SyntaxKind.AddAccessorDeclaration:\n case SyntaxKind.RemoveAccessorDeclaration:\n case SyntaxKind.GetAccessorDeclaration:\n case SyntaxKind.SetAccessorDeclaration:\n return false;\n }\n\n return true;\n }\n\n public static bool MatchesPreference(\n ExpressionSyntax expression, ExpressionBodyPreference preference)\n {\n if (preference == ExpressionBodyPreference.WhenPossible)\n {\n return true;\n }\n\n Contract.ThrowIfFalse(preference == ExpressionBodyPreference.WhenOnSingleLine);\n return CSharpSyntaxFacts.Instance.IsOnSingleLine(expression, fullSpan: false);\n }\n\n private static bool TryGetExpression(\n LanguageVersion version, StatementSyntax firstStatement,\n [NotNullWhen(true)] out ExpressionSyntax? expression, out SyntaxToken semicolonToken)\n {\n if (firstStatement is ExpressionStatementSyntax exprStatement)\n {\n expression = exprStatement.Expression;\n semicolonToken = exprStatement.SemicolonToken;\n return true;\n }\n else if (firstStatement is ReturnStatementSyntax returnStatement)\n {\n if (returnStatement.Expression != null)\n {\n // If there are any comments or directives on the return keyword, move them to\n // the expression.\n expression = firstStatement.GetLeadingTrivia().Any(t => t.IsDirective || t.IsSingleOrMultiLineComment())\n ? returnStatement.Expression.WithLeadingTrivia(returnStatement.GetLeadingTrivia())\n : returnStatement.Expression;\n semicolonToken = returnStatement.SemicolonToken;\n return true;\n }\n }\n else if (firstStatement is ThrowStatementSyntax throwStatement)\n {\n if (version >= LanguageVersion.CSharp7 && throwStatement.Expression != null)\n {\n expression = SyntaxFactory.ThrowExpression(throwStatement.ThrowKeyword, throwStatement.Expression);\n semicolonToken = throwStatement.SemicolonToken;\n return true;\n }\n }\n\n expression = null;\n semicolonToken = default;\n return false;\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":111,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\nusing Microsoft.CodeAnalysis;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.Text;\nusing Roslyn.Utilities;\nusing Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;\nusing Microsoft.CodeAnalysis.CSharp.Shared.Extensions;\n\n#if CODE_STYLE\nusing Microsoft.CodeAnalysis.Internal.Editing;\n#else\nusing Microsoft.CodeAnalysis.Editing;\n#endif\n\nnamespace Microsoft.CodeAnalysis.CSharp.LanguageServices\n{\n internal class CSharpSyntaxFacts : AbstractSyntaxFacts, ISyntaxFacts\n {\n internal static readonly CSharpSyntaxFacts Instance = new();\n\n protected CSharpSyntaxFacts()\n {\n }\n\n public bool IsCaseSensitive => true;\n\n public StringComparer StringComparer { get; } = StringComparer.Ordinal;\n\n public SyntaxTrivia ElasticMarker\n => SyntaxFactory.ElasticMarker;\n\n public SyntaxTrivia ElasticCarriageReturnLineFeed\n => SyntaxFactory.ElasticCarriageReturnLineFeed;\n\n public override ISyntaxKinds SyntaxKinds { get; } = CSharpSyntaxKinds.Instance;\n\n public bool SupportsIndexingInitializer(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp6;\n\n public bool SupportsThrowExpression(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp7;\n\n public bool SupportsLocalFunctionDeclaration(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp7;\n\n public bool SupportsRecord(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp9;\n\n public bool SupportsRecordStruct(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion.IsCSharp10OrAbove();\n\n public SyntaxToken ParseToken(string text)\n => SyntaxFactory.ParseToken(text);\n\n public SyntaxTriviaList ParseLeadingTrivia(string text)\n => SyntaxFactory.ParseLeadingTrivia(text);\n\n public string EscapeIdentifier(string identifier)\n {\n var nullIndex = identifier.IndexOf('\\0');\n if (nullIndex >= 0)\n {\n identifier = identifier.Substring(0, nullIndex);\n }\n\n var needsEscaping = SyntaxFacts.GetKeywordKind(identifier) != SyntaxKind.None;\n return needsEscaping ? \"@\" + identifier : identifier;\n }\n\n public bool IsVerbatimIdentifier(SyntaxToken token)\n => token.IsVerbatimIdentifier();\n\n public bool IsOperator(SyntaxToken token)\n {\n var kind = token.Kind();\n\n return\n (SyntaxFacts.IsAnyUnaryExpression(kind) &&\n (token.Parent is PrefixUnaryExpressionSyntax || token.Parent is PostfixUnaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||\n (SyntaxFacts.IsBinaryExpression(kind) && (token.Parent is BinaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||\n (SyntaxFacts.IsAssignmentExpressionOperatorToken(kind) && token.Parent is AssignmentExpressionSyntax);\n }\n\n public bool IsReservedKeyword(SyntaxToken token)\n => SyntaxFacts.IsReservedKeyword(token.Kind());\n\n public bool IsContextualKeyword(SyntaxToken token)\n => SyntaxFacts.IsContextualKeyword(token.Kind());\n\n public bool IsPreprocessorKeyword(SyntaxToken token)\n => SyntaxFacts.IsPreprocessorKeyword(token.Kind());\n\n public bool IsPreProcessorDirectiveContext(SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)\n => syntaxTree.IsPreProcessorDirectiveContext(\n position, syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken, includeDirectives: true), cancellationToken);\n\n public bool IsEntirelyWithinStringOrCharOrNumericLiteral([NotNullWhen(true)] SyntaxTree? syntaxTree, int position, CancellationToken cancellationToken)\n {\n if (syntaxTree == null)\n {\n return false;\n }\n\n return syntaxTree.IsEntirelyWithinStringOrCharLiteral(position, cancellationToken);\n }\n\n public bool IsDirective([NotNullWhen(true)] SyntaxNode? node)\n => node is DirectiveTriviaSyntax;\n\n public bool TryGetExternalSourceInfo([NotNullWhen(true)] SyntaxNode? node, out ExternalSourceInfo info)\n {\n if (node is LineDirectiveTriviaSyntax lineDirective)\n {\n if (lineDirective.Line.Kind() == SyntaxKind.DefaultKeyword)\n {\n info = new ExternalSourceInfo(null, ends: true);\n return true;\n }\n else if (lineDirective.Line.Kind() == SyntaxKind.NumericLiteralToken &&\n lineDirective.Line.Value is int)\n {\n info = new ExternalSourceInfo((int)lineDirective.Line.Value, false);\n return true;\n }\n }\n\n info = default;\n return false;\n }\n\n public bool IsNameOfSimpleMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n {\n var name = node as SimpleNameSyntax;\n return name.IsSimpleMemberAccessExpressionName();\n }\n\n public bool IsNameOfAnyMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => node?.Parent is MemberAccessExpressionSyntax memberAccess && memberAccess.Name == node;\n\n public bool IsNameOfMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node)\n {\n var name = node as SimpleNameSyntax;\n return name.IsMemberBindingExpressionName();\n }\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? GetStandaloneExpression(SyntaxNode? node)\n => node is ExpressionSyntax expression ? SyntaxFactory.GetStandaloneExpression(expression) : node;\n\n public SyntaxNode? GetRootConditionalAccessExpression(SyntaxNode? node)\n => node.GetRootConditionalAccessExpression();\n\n public bool IsDeclarationExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is DeclarationExpressionSyntax;\n\n public bool IsAttributeName(SyntaxNode node)\n => SyntaxFacts.IsAttributeName(node);\n\n public bool IsNamedArgument([NotNullWhen(true)] SyntaxNode? node)\n => node is ArgumentSyntax arg && arg.NameColon != null;\n\n public bool IsNameOfNamedArgument([NotNullWhen(true)] SyntaxNode? node)\n => node.CheckParent(p => p.Name == node);\n\n public SyntaxToken? GetNameOfParameter(SyntaxNode? node)\n => (node as ParameterSyntax)?.Identifier;\n\n public SyntaxNode? GetDefaultOfParameter(SyntaxNode node)\n => ((ParameterSyntax)node).Default;\n\n public SyntaxNode? GetParameterList(SyntaxNode node)\n => node.GetParameterList();\n\n public bool IsParameterList([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ParameterList, SyntaxKind.BracketedParameterList);\n\n public SyntaxToken GetIdentifierOfGenericName(SyntaxNode node)\n => ((GenericNameSyntax)node).Identifier;\n\n public bool IsUsingDirectiveName([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.UsingDirective, out UsingDirectiveSyntax? usingDirective) &&\n usingDirective.Name == node;\n\n public bool IsUsingAliasDirective([NotNullWhen(true)] SyntaxNode? node)\n => node is UsingDirectiveSyntax usingDirectiveNode && usingDirectiveNode.Alias != null;\n\n public void GetPartsOfUsingAliasDirective(SyntaxNode node, out SyntaxToken globalKeyword, out SyntaxToken alias, out SyntaxNode name)\n {\n var usingDirective = (UsingDirectiveSyntax)node;\n globalKeyword = usingDirective.GlobalKeyword;\n alias = usingDirective.Alias!.Name.Identifier;\n name = usingDirective.Name;\n }\n\n public bool IsDeconstructionForEachStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is ForEachVariableStatementSyntax;\n\n public bool IsDeconstructionAssignment([NotNullWhen(true)] SyntaxNode? node)\n => node is AssignmentExpressionSyntax assignment && assignment.IsDeconstruction();\n\n public Location GetDeconstructionReferenceLocation(SyntaxNode node)\n {\n return node switch\n {\n AssignmentExpressionSyntax assignment => assignment.Left.GetLocation(),\n ForEachVariableStatementSyntax @foreach => @foreach.Variable.GetLocation(),\n _ => throw ExceptionUtilities.UnexpectedValue(node.Kind()),\n };\n }\n\n public bool IsStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is StatementSyntax;\n\n public bool IsExecutableStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is StatementSyntax;\n\n public bool IsMethodBody([NotNullWhen(true)] SyntaxNode? node)\n {\n if (node is BlockSyntax ||\n node is ArrowExpressionClauseSyntax)\n {\n return node.Parent is BaseMethodDeclarationSyntax ||\n node.Parent is AccessorDeclarationSyntax;\n }\n\n return false;\n }\n\n public SyntaxNode? GetExpressionOfReturnStatement(SyntaxNode node)\n => ((ReturnStatementSyntax)node).Expression;\n\n public bool IsThisConstructorInitializer(SyntaxToken token)\n => token.Parent.IsKind(SyntaxKind.ThisConstructorInitializer, out ConstructorInitializerSyntax? constructorInit) &&\n constructorInit.ThisOrBaseKeyword == token;\n\n public bool IsBaseConstructorInitializer(SyntaxToken token)\n => token.Parent.IsKind(SyntaxKind.BaseConstructorInitializer, out ConstructorInitializerSyntax? constructorInit) &&\n constructorInit.ThisOrBaseKeyword == token;\n\n public bool IsQueryKeyword(SyntaxToken token)\n {\n switch (token.Kind())\n {\n case SyntaxKind.FromKeyword:\n case SyntaxKind.JoinKeyword:\n case SyntaxKind.LetKeyword:\n case SyntaxKind.OrderByKeyword:\n case SyntaxKind.WhereKeyword:\n case SyntaxKind.OnKeyword:\n case SyntaxKind.EqualsKeyword:\n case SyntaxKind.InKeyword:\n return token.Parent is QueryClauseSyntax;\n case SyntaxKind.ByKeyword:\n case SyntaxKind.GroupKeyword:\n case SyntaxKind.SelectKeyword:\n return token.Parent is SelectOrGroupClauseSyntax;\n case SyntaxKind.AscendingKeyword:\n case SyntaxKind.DescendingKeyword:\n return token.Parent is OrderingSyntax;\n case SyntaxKind.IntoKeyword:\n return token.Parent.IsKind(SyntaxKind.JoinIntoClause, SyntaxKind.QueryContinuation);\n default:\n return false;\n }\n }\n\n public bool IsPredefinedType(SyntaxToken token)\n => TryGetPredefinedType(token, out _);\n\n public bool IsPredefinedType(SyntaxToken token, PredefinedType type)\n => TryGetPredefinedType(token, out var actualType) && actualType == type;\n\n public bool TryGetPredefinedType(SyntaxToken token, out PredefinedType type)\n {\n type = GetPredefinedType(token);\n return type != PredefinedType.None;\n }\n\n private static PredefinedType GetPredefinedType(SyntaxToken token)\n {\n return (SyntaxKind)token.RawKind switch\n {\n SyntaxKind.BoolKeyword => PredefinedType.Boolean,\n SyntaxKind.ByteKeyword => PredefinedType.Byte,\n SyntaxKind.SByteKeyword => PredefinedType.SByte,\n SyntaxKind.IntKeyword => PredefinedType.Int32,\n SyntaxKind.UIntKeyword => PredefinedType.UInt32,\n SyntaxKind.ShortKeyword => PredefinedType.Int16,\n SyntaxKind.UShortKeyword => PredefinedType.UInt16,\n SyntaxKind.LongKeyword => PredefinedType.Int64,\n SyntaxKind.ULongKeyword => PredefinedType.UInt64,\n SyntaxKind.FloatKeyword => PredefinedType.Single,\n SyntaxKind.DoubleKeyword => PredefinedType.Double,\n SyntaxKind.DecimalKeyword => PredefinedType.Decimal,\n SyntaxKind.StringKeyword => PredefinedType.String,\n SyntaxKind.CharKeyword => PredefinedType.Char,\n SyntaxKind.ObjectKeyword => PredefinedType.Object,\n SyntaxKind.VoidKeyword => PredefinedType.Void,\n _ => PredefinedType.None,\n };\n }\n\n public bool IsPredefinedOperator(SyntaxToken token)\n => TryGetPredefinedOperator(token, out var actualOperator) && actualOperator != PredefinedOperator.None;\n\n public bool IsPredefinedOperator(SyntaxToken token, PredefinedOperator op)\n => TryGetPredefinedOperator(token, out var actualOperator) && actualOperator == op;\n\n public bool TryGetPredefinedOperator(SyntaxToken token, out PredefinedOperator op)\n {\n op = GetPredefinedOperator(token);\n return op != PredefinedOperator.None;\n }\n\n private static PredefinedOperator GetPredefinedOperator(SyntaxToken token)\n {\n switch ((SyntaxKind)token.RawKind)\n {\n case SyntaxKind.PlusToken:\n case SyntaxKind.PlusEqualsToken:\n return PredefinedOperator.Addition;\n\n case SyntaxKind.MinusToken:\n case SyntaxKind.MinusEqualsToken:\n return PredefinedOperator.Subtraction;\n\n case SyntaxKind.AmpersandToken:\n case SyntaxKind.AmpersandEqualsToken:\n return PredefinedOperator.BitwiseAnd;\n\n case SyntaxKind.BarToken:\n case SyntaxKind.BarEqualsToken:\n return PredefinedOperator.BitwiseOr;\n\n case SyntaxKind.MinusMinusToken:\n return PredefinedOperator.Decrement;\n\n case SyntaxKind.PlusPlusToken:\n return PredefinedOperator.Increment;\n\n case SyntaxKind.SlashToken:\n case SyntaxKind.SlashEqualsToken:\n return PredefinedOperator.Division;\n\n case SyntaxKind.EqualsEqualsToken:\n return PredefinedOperator.Equality;\n\n case SyntaxKind.CaretToken:\n case SyntaxKind.CaretEqualsToken:\n return PredefinedOperator.ExclusiveOr;\n\n case SyntaxKind.GreaterThanToken:\n return PredefinedOperator.GreaterThan;\n\n case SyntaxKind.GreaterThanEqualsToken:\n return PredefinedOperator.GreaterThanOrEqual;\n\n case SyntaxKind.ExclamationEqualsToken:\n return PredefinedOperator.Inequality;\n\n case SyntaxKind.LessThanLessThanToken:\n case SyntaxKind.LessThanLessThanEqualsToken:\n return PredefinedOperator.LeftShift;\n\n case SyntaxKind.LessThanToken:\n return PredefinedOperator.LessThan;\n\n case SyntaxKind.LessThanEqualsToken:\n return PredefinedOperator.LessThanOrEqual;\n\n case SyntaxKind.AsteriskToken:\n case SyntaxKind.AsteriskEqualsToken:\n return PredefinedOperator.Multiplication;\n\n case SyntaxKind.PercentToken:\n case SyntaxKind.PercentEqualsToken:\n return PredefinedOperator.Modulus;\n\n case SyntaxKind.ExclamationToken:\n case SyntaxKind.TildeToken:\n return PredefinedOperator.Complement;\n\n case SyntaxKind.GreaterThanGreaterThanToken:\n case SyntaxKind.GreaterThanGreaterThanEqualsToken:\n return PredefinedOperator.RightShift;\n }\n\n return PredefinedOperator.None;\n }\n\n public string GetText(int kind)\n => SyntaxFacts.GetText((SyntaxKind)kind);\n\n public bool IsIdentifierStartCharacter(char c)\n => SyntaxFacts.IsIdentifierStartCharacter(c);\n\n public bool IsIdentifierPartCharacter(char c)\n => SyntaxFacts.IsIdentifierPartCharacter(c);\n\n public bool IsIdentifierEscapeCharacter(char c)\n => c == '@';\n\n public bool IsValidIdentifier(string identifier)\n {\n var token = SyntaxFactory.ParseToken(identifier);\n return this.IsIdentifier(token) && !token.ContainsDiagnostics && token.ToString().Length == identifier.Length;\n }\n\n public bool IsVerbatimIdentifier(string identifier)\n {\n var token = SyntaxFactory.ParseToken(identifier);\n return this.IsIdentifier(token) && !token.ContainsDiagnostics && token.ToString().Length == identifier.Length && token.IsVerbatimIdentifier();\n }\n\n public bool IsTypeCharacter(char c) => false;\n\n public bool IsStartOfUnicodeEscapeSequence(char c)\n => c == '\\\\';\n\n public bool IsLiteral(SyntaxToken token)\n {\n switch (token.Kind())\n {\n case SyntaxKind.NumericLiteralToken:\n case SyntaxKind.CharacterLiteralToken:\n case SyntaxKind.StringLiteralToken:\n case SyntaxKind.NullKeyword:\n case SyntaxKind.TrueKeyword:\n case SyntaxKind.FalseKeyword:\n case SyntaxKind.InterpolatedStringStartToken:\n case SyntaxKind.InterpolatedStringEndToken:\n case SyntaxKind.InterpolatedVerbatimStringStartToken:\n case SyntaxKind.InterpolatedStringTextToken:\n return true;\n default:\n return false;\n }\n }\n\n public bool IsStringLiteralOrInterpolatedStringLiteral(SyntaxToken token)\n => token.IsKind(SyntaxKind.StringLiteralToken, SyntaxKind.InterpolatedStringTextToken);\n\n public bool IsBindableToken(SyntaxToken token)\n {\n if (this.IsWord(token) || this.IsLiteral(token) || this.IsOperator(token))\n {\n switch ((SyntaxKind)token.RawKind)\n {\n case SyntaxKind.DelegateKeyword:\n case SyntaxKind.VoidKeyword:\n return false;\n }\n\n return true;\n }\n\n // In the order by clause a comma might be bound to ThenBy or ThenByDescending\n if (token.Kind() == SyntaxKind.CommaToken && token.Parent.IsKind(SyntaxKind.OrderByClause))\n {\n return true;\n }\n\n return false;\n }\n\n public bool IsPostfixUnaryExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is PostfixUnaryExpressionSyntax;\n\n public bool IsMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is MemberBindingExpressionSyntax;\n\n public bool IsPointerMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => (node as MemberAccessExpressionSyntax)?.Kind() == SyntaxKind.PointerMemberAccessExpression;\n\n public void GetNameAndArityOfSimpleName(SyntaxNode node, out string name, out int arity)\n {\n var simpleName = (SimpleNameSyntax)node;\n name = simpleName.Identifier.ValueText;\n arity = simpleName.Arity;\n }\n\n public bool LooksGeneric(SyntaxNode simpleName)\n => simpleName.IsKind(SyntaxKind.GenericName) ||\n simpleName.GetLastToken().GetNextToken().Kind() == SyntaxKind.LessThanToken;\n\n public SyntaxNode? GetTargetOfMemberBinding(SyntaxNode? node)\n => (node as MemberBindingExpressionSyntax).GetParentConditionalAccessExpression()?.Expression;\n\n public SyntaxNode GetNameOfMemberBindingExpression(SyntaxNode node)\n => ((MemberBindingExpressionSyntax)node).Name;\n\n public SyntaxNode? GetExpressionOfMemberAccessExpression(SyntaxNode node, bool allowImplicitTarget)\n => ((MemberAccessExpressionSyntax)node).Expression;\n\n public void GetPartsOfElementAccessExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxNode argumentList)\n {\n var elementAccess = (ElementAccessExpressionSyntax)node;\n expression = elementAccess.Expression;\n argumentList = elementAccess.ArgumentList;\n }\n\n public SyntaxNode GetExpressionOfInterpolation(SyntaxNode node)\n => ((InterpolationSyntax)node).Expression;\n\n public bool IsInStaticContext(SyntaxNode node)\n => node.IsInStaticContext();\n\n public bool IsInNamespaceOrTypeContext([NotNullWhen(true)] SyntaxNode? node)\n => SyntaxFacts.IsInNamespaceOrTypeContext(node as ExpressionSyntax);\n\n public bool IsBaseTypeList([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.BaseList);\n\n public SyntaxNode GetExpressionOfArgument(SyntaxNode node)\n => ((ArgumentSyntax)node).Expression;\n\n public RefKind GetRefKindOfArgument(SyntaxNode node)\n => ((ArgumentSyntax)node).GetRefKind();\n\n public bool IsArgument([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Argument);\n\n public bool IsSimpleArgument([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is ArgumentSyntax argument &&\n argument.RefOrOutKeyword.Kind() == SyntaxKind.None &&\n argument.NameColon == null;\n }\n\n public bool IsInConstantContext([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsInConstantContext();\n\n public bool IsInConstructor(SyntaxNode node)\n => node.GetAncestor() != null;\n\n public bool IsUnsafeContext(SyntaxNode node)\n => node.IsUnsafeContext();\n\n public SyntaxNode GetNameOfAttribute(SyntaxNode node)\n => ((AttributeSyntax)node).Name;\n\n public bool IsAttributeNamedArgumentIdentifier([NotNullWhen(true)] SyntaxNode? node)\n => (node as IdentifierNameSyntax).IsAttributeNamedArgumentIdentifier();\n\n public SyntaxNode? GetContainingTypeDeclaration(SyntaxNode? root, int position)\n {\n if (root == null)\n {\n throw new ArgumentNullException(nameof(root));\n }\n\n if (position < 0 || position > root.Span.End)\n {\n throw new ArgumentOutOfRangeException(nameof(position));\n }\n\n return root\n .FindToken(position)\n .GetAncestors()\n .FirstOrDefault(n => n is BaseTypeDeclarationSyntax || n is DelegateDeclarationSyntax);\n }\n\n public SyntaxNode? GetContainingVariableDeclaratorOfFieldDeclaration(SyntaxNode? node)\n => throw ExceptionUtilities.Unreachable;\n\n public bool IsNameOfSubpattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IdentifierName) &&\n node.IsParentKind(SyntaxKind.NameColon) &&\n node.Parent.IsParentKind(SyntaxKind.Subpattern);\n\n public bool IsPropertyPatternClause(SyntaxNode node)\n => node.Kind() == SyntaxKind.PropertyPatternClause;\n\n public bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node)\n => IsMemberInitializerNamedAssignmentIdentifier(node, out _);\n\n public bool IsMemberInitializerNamedAssignmentIdentifier(\n [NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance)\n {\n initializedInstance = null;\n if (node is IdentifierNameSyntax identifier &&\n identifier.IsLeftSideOfAssignExpression())\n {\n if (identifier.Parent.IsParentKind(SyntaxKind.WithInitializerExpression))\n {\n var withInitializer = identifier.Parent.GetRequiredParent();\n initializedInstance = withInitializer.GetRequiredParent();\n return true;\n }\n else if (identifier.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression))\n {\n var objectInitializer = identifier.Parent.GetRequiredParent();\n if (objectInitializer.Parent is BaseObjectCreationExpressionSyntax)\n {\n initializedInstance = objectInitializer.Parent;\n return true;\n }\n else if (objectInitializer.IsParentKind(SyntaxKind.SimpleAssignmentExpression, out AssignmentExpressionSyntax? assignment))\n {\n initializedInstance = assignment.Left;\n return true;\n }\n }\n }\n\n return false;\n }\n\n public bool IsElementAccessExpression(SyntaxNode? node)\n => node.IsKind(SyntaxKind.ElementAccessExpression);\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? ConvertToSingleLine(SyntaxNode? node, bool useElasticTrivia = false)\n => node.ConvertToSingleLine(useElasticTrivia);\n\n public bool IsIndexerMemberCRef(SyntaxNode? node)\n => node.IsKind(SyntaxKind.IndexerMemberCref);\n\n public SyntaxNode? GetContainingMemberDeclaration(SyntaxNode? root, int position, bool useFullSpan = true)\n {\n Contract.ThrowIfNull(root, \"root\");\n Contract.ThrowIfTrue(position < 0 || position > root.FullSpan.End, \"position\");\n\n var end = root.FullSpan.End;\n if (end == 0)\n {\n // empty file\n return null;\n }\n\n // make sure position doesn't touch end of root\n position = Math.Min(position, end - 1);\n\n var node = root.FindToken(position).Parent;\n while (node != null)\n {\n if (useFullSpan || node.Span.Contains(position))\n {\n var kind = node.Kind();\n if ((kind != SyntaxKind.GlobalStatement) && (kind != SyntaxKind.IncompleteMember) && (node is MemberDeclarationSyntax))\n {\n return node;\n }\n }\n\n node = node.Parent;\n }\n\n return null;\n }\n\n public bool IsMethodLevelMember([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is BaseMethodDeclarationSyntax ||\n node is BasePropertyDeclarationSyntax ||\n node is EnumMemberDeclarationSyntax ||\n node is BaseFieldDeclarationSyntax;\n }\n\n public bool IsTopLevelNodeWithMembers([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is BaseNamespaceDeclarationSyntax ||\n node is TypeDeclarationSyntax ||\n node is EnumDeclarationSyntax;\n }\n\n private const string dotToken = \".\";\n\n public string GetDisplayName(SyntaxNode? node, DisplayNameOptions options, string? rootNamespace = null)\n {\n if (node == null)\n {\n return string.Empty;\n }\n\n var pooled = PooledStringBuilder.GetInstance();\n var builder = pooled.Builder;\n\n // return type\n var memberDeclaration = node as MemberDeclarationSyntax;\n if ((options & DisplayNameOptions.IncludeType) != 0)\n {\n var type = memberDeclaration.GetMemberType();\n if (type != null && !type.IsMissing)\n {\n builder.Append(type);\n builder.Append(' ');\n }\n }\n\n var names = ArrayBuilder.GetInstance();\n // containing type(s)\n var parent = node.GetAncestor() ?? node.Parent;\n while (parent is TypeDeclarationSyntax)\n {\n names.Push(GetName(parent, options));\n parent = parent.Parent;\n }\n\n // containing namespace(s) in source (if any)\n if ((options & DisplayNameOptions.IncludeNamespaces) != 0)\n {\n while (parent is BaseNamespaceDeclarationSyntax)\n {\n names.Add(GetName(parent, options));\n parent = parent.Parent;\n }\n }\n\n while (!names.IsEmpty())\n {\n var name = names.Pop();\n if (name != null)\n {\n builder.Append(name);\n builder.Append(dotToken);\n }\n }\n\n // name (including generic type parameters)\n builder.Append(GetName(node, options));\n\n // parameter list (if any)\n if ((options & DisplayNameOptions.IncludeParameters) != 0)\n {\n builder.Append(memberDeclaration.GetParameterList());\n }\n\n return pooled.ToStringAndFree();\n }\n\n private static string? GetName(SyntaxNode node, DisplayNameOptions options)\n {\n const string missingTokenPlaceholder = \"?\";\n\n switch (node.Kind())\n {\n case SyntaxKind.CompilationUnit:\n return null;\n case SyntaxKind.IdentifierName:\n var identifier = ((IdentifierNameSyntax)node).Identifier;\n return identifier.IsMissing ? missingTokenPlaceholder : identifier.Text;\n case SyntaxKind.IncompleteMember:\n return missingTokenPlaceholder;\n case SyntaxKind.NamespaceDeclaration:\n case SyntaxKind.FileScopedNamespaceDeclaration:\n return GetName(((BaseNamespaceDeclarationSyntax)node).Name, options);\n case SyntaxKind.QualifiedName:\n var qualified = (QualifiedNameSyntax)node;\n return GetName(qualified.Left, options) + dotToken + GetName(qualified.Right, options);\n }\n\n string? name = null;\n if (node is MemberDeclarationSyntax memberDeclaration)\n {\n if (memberDeclaration.Kind() == SyntaxKind.ConversionOperatorDeclaration)\n {\n name = (memberDeclaration as ConversionOperatorDeclarationSyntax)?.Type.ToString();\n }\n else\n {\n var nameToken = memberDeclaration.GetNameToken();\n if (nameToken != default)\n {\n name = nameToken.IsMissing ? missingTokenPlaceholder : nameToken.Text;\n if (memberDeclaration.Kind() == SyntaxKind.DestructorDeclaration)\n {\n name = \"~\" + name;\n }\n\n if ((options & DisplayNameOptions.IncludeTypeParameters) != 0)\n {\n var pooled = PooledStringBuilder.GetInstance();\n var builder = pooled.Builder;\n builder.Append(name);\n AppendTypeParameterList(builder, memberDeclaration.GetTypeParameterList());\n name = pooled.ToStringAndFree();\n }\n }\n else\n {\n Debug.Assert(memberDeclaration.Kind() == SyntaxKind.IncompleteMember);\n name = \"?\";\n }\n }\n }\n else\n {\n if (node is VariableDeclaratorSyntax fieldDeclarator)\n {\n var nameToken = fieldDeclarator.Identifier;\n if (nameToken != default)\n {\n name = nameToken.IsMissing ? missingTokenPlaceholder : nameToken.Text;\n }\n }\n }\n\n Debug.Assert(name != null, \"Unexpected node type \" + node.Kind());\n return name;\n }\n\n private static void AppendTypeParameterList(StringBuilder builder, TypeParameterListSyntax typeParameterList)\n {\n if (typeParameterList != null && typeParameterList.Parameters.Count > 0)\n {\n builder.Append('<');\n builder.Append(typeParameterList.Parameters[0].Identifier.ValueText);\n for (var i = 1; i < typeParameterList.Parameters.Count; i++)\n {\n builder.Append(\", \");\n builder.Append(typeParameterList.Parameters[i].Identifier.ValueText);\n }\n\n builder.Append('>');\n }\n }\n\n public List GetTopLevelAndMethodLevelMembers(SyntaxNode? root)\n {\n var list = new List();\n AppendMembers(root, list, topLevel: true, methodLevel: true);\n return list;\n }\n\n public List GetMethodLevelMembers(SyntaxNode? root)\n {\n var list = new List();\n AppendMembers(root, list, topLevel: false, methodLevel: true);\n return list;\n }\n\n public SyntaxList GetMembersOfTypeDeclaration(SyntaxNode typeDeclaration)\n => ((TypeDeclarationSyntax)typeDeclaration).Members;\n\n private void AppendMembers(SyntaxNode? node, List list, bool topLevel, bool methodLevel)\n {\n Debug.Assert(topLevel || methodLevel);\n\n foreach (var member in node.GetMembers())\n {\n if (IsTopLevelNodeWithMembers(member))\n {\n if (topLevel)\n {\n list.Add(member);\n }\n\n AppendMembers(member, list, topLevel, methodLevel);\n continue;\n }\n\n if (methodLevel && IsMethodLevelMember(member))\n {\n list.Add(member);\n }\n }\n }\n\n public TextSpan GetMemberBodySpanForSpeculativeBinding(SyntaxNode node)\n {\n if (node.Span.IsEmpty)\n {\n return default;\n }\n\n var member = GetContainingMemberDeclaration(node, node.SpanStart);\n if (member == null)\n {\n return default;\n }\n\n // TODO: currently we only support method for now\n if (member is BaseMethodDeclarationSyntax method)\n {\n if (method.Body == null)\n {\n return default;\n }\n\n return GetBlockBodySpan(method.Body);\n }\n\n return default;\n }\n\n public bool ContainsInMemberBody([NotNullWhen(true)] SyntaxNode? node, TextSpan span)\n {\n switch (node)\n {\n case ConstructorDeclarationSyntax constructor:\n return (constructor.Body != null && GetBlockBodySpan(constructor.Body).Contains(span)) ||\n (constructor.Initializer != null && constructor.Initializer.Span.Contains(span));\n case BaseMethodDeclarationSyntax method:\n return method.Body != null && GetBlockBodySpan(method.Body).Contains(span);\n case BasePropertyDeclarationSyntax property:\n return property.AccessorList != null && property.AccessorList.Span.Contains(span);\n case EnumMemberDeclarationSyntax @enum:\n return @enum.EqualsValue != null && @enum.EqualsValue.Span.Contains(span);\n case BaseFieldDeclarationSyntax field:\n return field.Declaration != null && field.Declaration.Span.Contains(span);\n }\n\n return false;\n }\n\n private static TextSpan GetBlockBodySpan(BlockSyntax body)\n => TextSpan.FromBounds(body.OpenBraceToken.Span.End, body.CloseBraceToken.SpanStart);\n\n public SyntaxNode? TryGetBindableParent(SyntaxToken token)\n {\n var node = token.Parent;\n while (node != null)\n {\n var parent = node.Parent;\n\n // If this node is on the left side of a member access expression, don't ascend\n // further or we'll end up binding to something else.\n if (parent is MemberAccessExpressionSyntax memberAccess)\n {\n if (memberAccess.Expression == node)\n {\n break;\n }\n }\n\n // If this node is on the left side of a qualified name, don't ascend\n // further or we'll end up binding to something else.\n if (parent is QualifiedNameSyntax qualifiedName)\n {\n if (qualifiedName.Left == node)\n {\n break;\n }\n }\n\n // If this node is on the left side of a alias-qualified name, don't ascend\n // further or we'll end up binding to something else.\n if (parent is AliasQualifiedNameSyntax aliasQualifiedName)\n {\n if (aliasQualifiedName.Alias == node)\n {\n break;\n }\n }\n\n // If this node is the type of an object creation expression, return the\n // object creation expression.\n if (parent is ObjectCreationExpressionSyntax objectCreation)\n {\n if (objectCreation.Type == node)\n {\n node = parent;\n break;\n }\n }\n\n // The inside of an interpolated string is treated as its own token so we\n // need to force navigation to the parent expression syntax.\n if (node is InterpolatedStringTextSyntax && parent is InterpolatedStringExpressionSyntax)\n {\n node = parent;\n break;\n }\n\n // If this node is not parented by a name, we're done.\n if (!(parent is NameSyntax))\n {\n break;\n }\n\n node = parent;\n }\n\n if (node is VarPatternSyntax)\n {\n return node;\n }\n\n // Patterns are never bindable (though their constituent types/exprs may be).\n return node is PatternSyntax ? null : node;\n }\n\n public IEnumerable GetConstructors(SyntaxNode? root, CancellationToken cancellationToken)\n {\n if (root is not CompilationUnitSyntax compilationUnit)\n {\n return SpecializedCollections.EmptyEnumerable();\n }\n\n var constructors = new List();\n AppendConstructors(compilationUnit.Members, constructors, cancellationToken);\n return constructors;\n }\n\n private void AppendConstructors(SyntaxList members, List constructors, CancellationToken cancellationToken)\n {\n foreach (var member in members)\n {\n cancellationToken.ThrowIfCancellationRequested();\n switch (member)\n {\n case ConstructorDeclarationSyntax constructor:\n constructors.Add(constructor);\n continue;\n case BaseNamespaceDeclarationSyntax @namespace:\n AppendConstructors(@namespace.Members, constructors, cancellationToken);\n break;\n case ClassDeclarationSyntax @class:\n AppendConstructors(@class.Members, constructors, cancellationToken);\n break;\n case RecordDeclarationSyntax record:\n AppendConstructors(record.Members, constructors, cancellationToken);\n break;\n case StructDeclarationSyntax @struct:\n AppendConstructors(@struct.Members, constructors, cancellationToken);\n break;\n }\n }\n }\n\n public bool TryGetCorrespondingOpenBrace(SyntaxToken token, out SyntaxToken openBrace)\n {\n if (token.Kind() == SyntaxKind.CloseBraceToken)\n {\n var tuple = token.Parent.GetBraces();\n\n openBrace = tuple.openBrace;\n return openBrace.Kind() == SyntaxKind.OpenBraceToken;\n }\n\n openBrace = default;\n return false;\n }\n\n public TextSpan GetInactiveRegionSpanAroundPosition(SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)\n {\n var trivia = syntaxTree.GetRoot(cancellationToken).FindTrivia(position, findInsideTrivia: false);\n if (trivia.Kind() == SyntaxKind.DisabledTextTrivia)\n {\n return trivia.FullSpan;\n }\n\n var token = syntaxTree.FindTokenOrEndToken(position, cancellationToken);\n if (token.Kind() == SyntaxKind.EndOfFileToken)\n {\n var triviaList = token.LeadingTrivia;\n foreach (var triviaTok in triviaList.Reverse())\n {\n if (triviaTok.Span.Contains(position))\n {\n return default;\n }\n\n if (triviaTok.Span.End < position)\n {\n if (!triviaTok.HasStructure)\n {\n return default;\n }\n\n var structure = triviaTok.GetStructure();\n if (structure is BranchingDirectiveTriviaSyntax branch)\n {\n return !branch.IsActive || !branch.BranchTaken ? TextSpan.FromBounds(branch.FullSpan.Start, position) : default;\n }\n }\n }\n }\n\n return default;\n }\n\n public string GetNameForArgument(SyntaxNode? argument)\n => (argument as ArgumentSyntax)?.NameColon?.Name.Identifier.ValueText ?? string.Empty;\n\n public string GetNameForAttributeArgument(SyntaxNode? argument)\n => (argument as AttributeArgumentSyntax)?.NameEquals?.Name.Identifier.ValueText ?? string.Empty;\n\n public bool IsLeftSideOfDot([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfDot();\n\n public SyntaxNode? GetRightSideOfDot(SyntaxNode? node)\n {\n return (node as QualifiedNameSyntax)?.Right ??\n (node as MemberAccessExpressionSyntax)?.Name;\n }\n\n public SyntaxNode? GetLeftSideOfDot(SyntaxNode? node, bool allowImplicitTarget)\n {\n return (node as QualifiedNameSyntax)?.Left ??\n (node as MemberAccessExpressionSyntax)?.Expression;\n }\n\n public bool IsLeftSideOfExplicitInterfaceSpecifier([NotNullWhen(true)] SyntaxNode? node)\n => (node as NameSyntax).IsLeftSideOfExplicitInterfaceSpecifier();\n\n public bool IsLeftSideOfAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfAssignExpression();\n\n public bool IsLeftSideOfAnyAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfAnyAssignExpression();\n\n public bool IsLeftSideOfCompoundAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfCompoundAssignExpression();\n\n public SyntaxNode GetRightHandSideOfAssignment(SyntaxNode node)\n => ((AssignmentExpressionSyntax)node).Right;\n\n public bool IsInferredAnonymousObjectMemberDeclarator([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator, out AnonymousObjectMemberDeclaratorSyntax? anonObject) &&\n anonObject.NameEquals == null;\n\n public bool IsOperandOfIncrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.PostIncrementExpression) ||\n node.IsParentKind(SyntaxKind.PreIncrementExpression);\n\n public static bool IsOperandOfDecrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.PostDecrementExpression) ||\n node.IsParentKind(SyntaxKind.PreDecrementExpression);\n\n public bool IsOperandOfIncrementOrDecrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => IsOperandOfIncrementExpression(node) || IsOperandOfDecrementExpression(node);\n\n public SyntaxList GetContentsOfInterpolatedString(SyntaxNode interpolatedString)\n => ((InterpolatedStringExpressionSyntax)interpolatedString).Contents;\n\n public bool IsVerbatimStringLiteral(SyntaxToken token)\n => token.IsVerbatimStringLiteral();\n\n public bool IsNumericLiteral(SyntaxToken token)\n => token.Kind() == SyntaxKind.NumericLiteralToken;\n\n public SeparatedSyntaxList GetArgumentsOfInvocationExpression(SyntaxNode invocationExpression)\n => GetArgumentsOfArgumentList(((InvocationExpressionSyntax)invocationExpression).ArgumentList);\n\n public SeparatedSyntaxList GetArgumentsOfObjectCreationExpression(SyntaxNode objectCreationExpression)\n => ((BaseObjectCreationExpressionSyntax)objectCreationExpression).ArgumentList is { } argumentList\n ? GetArgumentsOfArgumentList(argumentList)\n : default;\n\n public SeparatedSyntaxList GetArgumentsOfArgumentList(SyntaxNode argumentList)\n => ((BaseArgumentListSyntax)argumentList).Arguments;\n\n public bool IsRegularComment(SyntaxTrivia trivia)\n => trivia.IsRegularComment();\n\n public bool IsDocumentationComment(SyntaxTrivia trivia)\n => trivia.IsDocComment();\n\n public bool IsElastic(SyntaxTrivia trivia)\n => trivia.IsElastic();\n\n public bool IsPragmaDirective(SyntaxTrivia trivia, out bool isDisable, out bool isActive, out SeparatedSyntaxList errorCodes)\n => trivia.IsPragmaDirective(out isDisable, out isActive, out errorCodes);\n\n public bool IsDocumentationCommentExteriorTrivia(SyntaxTrivia trivia)\n => trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia;\n\n public bool IsDocumentationComment(SyntaxNode node)\n => SyntaxFacts.IsDocumentationCommentTrivia(node.Kind());\n\n public bool IsUsingOrExternOrImport([NotNullWhen(true)] SyntaxNode? node)\n {\n return node.IsKind(SyntaxKind.UsingDirective) ||\n node.IsKind(SyntaxKind.ExternAliasDirective);\n }\n\n public bool IsGlobalAssemblyAttribute([NotNullWhen(true)] SyntaxNode? node)\n => IsGlobalAttribute(node, SyntaxKind.AssemblyKeyword);\n\n public bool IsGlobalModuleAttribute([NotNullWhen(true)] SyntaxNode? node)\n => IsGlobalAttribute(node, SyntaxKind.ModuleKeyword);\n\n private static bool IsGlobalAttribute([NotNullWhen(true)] SyntaxNode? node, SyntaxKind attributeTarget)\n => node.IsKind(SyntaxKind.Attribute) &&\n node.Parent.IsKind(SyntaxKind.AttributeList, out AttributeListSyntax? attributeList) &&\n attributeList.Target?.Identifier.Kind() == attributeTarget;\n\n private static bool IsMemberDeclaration(SyntaxNode node)\n {\n // From the C# language spec:\n // class-member-declaration:\n // constant-declaration\n // field-declaration\n // method-declaration\n // property-declaration\n // event-declaration\n // indexer-declaration\n // operator-declaration\n // constructor-declaration\n // destructor-declaration\n // static-constructor-declaration\n // type-declaration\n switch (node.Kind())\n {\n // Because fields declarations can define multiple symbols \"public int a, b;\"\n // We want to get the VariableDeclarator node inside the field declaration to print out the symbol for the name.\n case SyntaxKind.VariableDeclarator:\n return node.Parent.IsParentKind(SyntaxKind.FieldDeclaration) ||\n node.Parent.IsParentKind(SyntaxKind.EventFieldDeclaration);\n\n case SyntaxKind.FieldDeclaration:\n case SyntaxKind.MethodDeclaration:\n case SyntaxKind.PropertyDeclaration:\n case SyntaxKind.GetAccessorDeclaration:\n case SyntaxKind.SetAccessorDeclaration:\n case SyntaxKind.EventDeclaration:\n case SyntaxKind.EventFieldDeclaration:\n case SyntaxKind.AddAccessorDeclaration:\n case SyntaxKind.RemoveAccessorDeclaration:\n case SyntaxKind.IndexerDeclaration:\n case SyntaxKind.OperatorDeclaration:\n case SyntaxKind.ConversionOperatorDeclaration:\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n return true;\n\n default:\n return false;\n }\n }\n\n public bool IsDeclaration(SyntaxNode node)\n => SyntaxFacts.IsNamespaceMemberDeclaration(node.Kind()) || IsMemberDeclaration(node);\n\n public bool IsTypeDeclaration(SyntaxNode node)\n => SyntaxFacts.IsTypeDeclaration(node.Kind());\n\n public bool IsSimpleAssignmentStatement([NotNullWhen(true)] SyntaxNode? statement)\n => statement.IsKind(SyntaxKind.ExpressionStatement, out ExpressionStatementSyntax? exprStatement) &&\n exprStatement.Expression.IsKind(SyntaxKind.SimpleAssignmentExpression);\n\n public void GetPartsOfAssignmentStatement(\n SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n GetPartsOfAssignmentExpressionOrStatement(\n ((ExpressionStatementSyntax)statement).Expression, out left, out operatorToken, out right);\n }\n\n public void GetPartsOfAssignmentExpressionOrStatement(\n SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var expression = statement;\n if (statement is ExpressionStatementSyntax expressionStatement)\n {\n expression = expressionStatement.Expression;\n }\n\n var assignment = (AssignmentExpressionSyntax)expression;\n left = assignment.Left;\n operatorToken = assignment.OperatorToken;\n right = assignment.Right;\n }\n\n public SyntaxToken GetIdentifierOfSimpleName(SyntaxNode node)\n => ((SimpleNameSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclaratorSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfParameter(SyntaxNode node)\n => ((ParameterSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfTypeDeclaration(SyntaxNode node)\n => node switch\n {\n BaseTypeDeclarationSyntax typeDecl => typeDecl.Identifier,\n DelegateDeclarationSyntax delegateDecl => delegateDecl.Identifier,\n _ => throw ExceptionUtilities.UnexpectedValue(node),\n };\n\n public SyntaxToken GetIdentifierOfIdentifierName(SyntaxNode node)\n => ((IdentifierNameSyntax)node).Identifier;\n\n public bool IsDeclaratorOfLocalDeclarationStatement(SyntaxNode declarator, SyntaxNode localDeclarationStatement)\n {\n return ((LocalDeclarationStatementSyntax)localDeclarationStatement).Declaration.Variables.Contains(\n (VariableDeclaratorSyntax)declarator);\n }\n\n public bool AreEquivalent(SyntaxToken token1, SyntaxToken token2)\n => SyntaxFactory.AreEquivalent(token1, token2);\n\n public bool AreEquivalent(SyntaxNode? node1, SyntaxNode? node2)\n => SyntaxFactory.AreEquivalent(node1, node2);\n\n public static SyntaxNode GetExpressionOfInvocationExpression(SyntaxNode node)\n => ((InvocationExpressionSyntax)node).Expression;\n\n public bool IsExpressionOfForeach([NotNullWhen(true)] SyntaxNode? node)\n => node?.Parent is ForEachStatementSyntax foreachStatement && foreachStatement.Expression == node;\n\n public SyntaxNode GetExpressionOfExpressionStatement(SyntaxNode node)\n => ((ExpressionStatementSyntax)node).Expression;\n\n public bool IsIsExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IsExpression);\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? WalkDownParentheses(SyntaxNode? node)\n => (node as ExpressionSyntax)?.WalkDownParentheses() ?? node;\n\n public void GetPartsOfTupleExpression(SyntaxNode node,\n out SyntaxToken openParen, out SeparatedSyntaxList arguments, out SyntaxToken closeParen) where TArgumentSyntax : SyntaxNode\n {\n var tupleExpression = (TupleExpressionSyntax)node;\n openParen = tupleExpression.OpenParenToken;\n arguments = (SeparatedSyntaxList)(SeparatedSyntaxList)tupleExpression.Arguments;\n closeParen = tupleExpression.CloseParenToken;\n }\n\n public override bool IsPreprocessorDirective(SyntaxTrivia trivia)\n => SyntaxFacts.IsPreprocessorDirective(trivia.Kind());\n\n protected override bool ContainsInterleavedDirective(TextSpan span, SyntaxToken token, CancellationToken cancellationToken)\n => token.ContainsInterleavedDirective(span, cancellationToken);\n\n public SyntaxTokenList GetModifiers(SyntaxNode? node)\n => node.GetModifiers();\n\n public SyntaxNode? WithModifiers(SyntaxNode? node, SyntaxTokenList modifiers)\n => node.WithModifiers(modifiers);\n\n public SeparatedSyntaxList GetVariablesOfLocalDeclarationStatement(SyntaxNode node)\n => ((LocalDeclarationStatementSyntax)node).Declaration.Variables;\n\n public SyntaxNode? GetInitializerOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclaratorSyntax)node).Initializer;\n\n public SyntaxNode GetTypeOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclarationSyntax)((VariableDeclaratorSyntax)node).Parent!).Type;\n\n public SyntaxNode? GetValueOfEqualsValueClause(SyntaxNode? node)\n => ((EqualsValueClauseSyntax?)node)?.Value;\n\n public bool IsScopeBlock([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Block);\n\n public bool IsExecutableBlock([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Block, SyntaxKind.SwitchSection, SyntaxKind.CompilationUnit);\n\n public IReadOnlyList GetExecutableBlockStatements(SyntaxNode? node)\n {\n return node switch\n {\n BlockSyntax block => block.Statements,\n SwitchSectionSyntax switchSection => switchSection.Statements,\n CompilationUnitSyntax compilationUnit => compilationUnit.Members.OfType().SelectAsArray(globalStatement => globalStatement.Statement),\n _ => throw ExceptionUtilities.UnexpectedValue(node),\n };\n }\n\n public SyntaxNode? FindInnermostCommonExecutableBlock(IEnumerable nodes)\n => nodes.FindInnermostCommonNode(node => IsExecutableBlock(node));\n\n public bool IsStatementContainer([NotNullWhen(true)] SyntaxNode? node)\n => IsExecutableBlock(node) || node.IsEmbeddedStatementOwner();\n\n public IReadOnlyList GetStatementContainerStatements(SyntaxNode? node)\n {\n if (IsExecutableBlock(node))\n return GetExecutableBlockStatements(node);\n else if (node.GetEmbeddedStatement() is { } embeddedStatement)\n return ImmutableArray.Create(embeddedStatement);\n else\n return ImmutableArray.Empty;\n }\n\n public bool IsConversionExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is CastExpressionSyntax;\n\n public bool IsCastExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is CastExpressionSyntax;\n\n public void GetPartsOfCastExpression(SyntaxNode node, out SyntaxNode type, out SyntaxNode expression)\n {\n var cast = (CastExpressionSyntax)node;\n type = cast.Type;\n expression = cast.Expression;\n }\n\n public SyntaxToken? GetDeclarationIdentifierIfOverride(SyntaxToken token)\n {\n if (token.Kind() == SyntaxKind.OverrideKeyword && token.Parent is MemberDeclarationSyntax member)\n {\n return member.GetNameToken();\n }\n\n return null;\n }\n\n public override SyntaxList GetAttributeLists(SyntaxNode? node)\n => node.GetAttributeLists();\n\n public override bool IsParameterNameXmlElementSyntax([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.XmlElement, out XmlElementSyntax? xmlElement) &&\n xmlElement.StartTag.Name.LocalName.ValueText == DocumentationCommentXmlNames.ParameterElementName;\n\n public override SyntaxList GetContentFromDocumentationCommentTriviaSyntax(SyntaxTrivia trivia)\n {\n if (trivia.GetStructure() is DocumentationCommentTriviaSyntax documentationCommentTrivia)\n {\n return documentationCommentTrivia.Content;\n }\n\n throw ExceptionUtilities.UnexpectedValue(trivia.Kind());\n }\n\n public bool IsIsPatternExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IsPatternExpression);\n\n public void GetPartsOfIsPatternExpression(SyntaxNode node, out SyntaxNode left, out SyntaxToken isToken, out SyntaxNode right)\n {\n var isPatternExpression = (IsPatternExpressionSyntax)node;\n left = isPatternExpression.Expression;\n isToken = isPatternExpression.IsKeyword;\n right = isPatternExpression.Pattern;\n }\n\n public bool IsAnyPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is PatternSyntax;\n\n public bool IsConstantPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ConstantPattern);\n\n public bool IsDeclarationPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.DeclarationPattern);\n\n public bool IsRecursivePattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.RecursivePattern);\n\n public bool IsVarPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.VarPattern);\n\n public SyntaxNode GetExpressionOfConstantPattern(SyntaxNode node)\n => ((ConstantPatternSyntax)node).Expression;\n\n public void GetPartsOfDeclarationPattern(SyntaxNode node, out SyntaxNode type, out SyntaxNode designation)\n {\n var declarationPattern = (DeclarationPatternSyntax)node;\n type = declarationPattern.Type;\n designation = declarationPattern.Designation;\n }\n\n public void GetPartsOfRecursivePattern(SyntaxNode node, out SyntaxNode? type, out SyntaxNode? positionalPart, out SyntaxNode? propertyPart, out SyntaxNode? designation)\n {\n var recursivePattern = (RecursivePatternSyntax)node;\n type = recursivePattern.Type;\n positionalPart = recursivePattern.PositionalPatternClause;\n propertyPart = recursivePattern.PropertyPatternClause;\n designation = recursivePattern.Designation;\n }\n\n public bool SupportsNotPattern(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion.IsCSharp9OrAbove();\n\n public bool IsAndPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.AndPattern);\n\n public bool IsBinaryPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is BinaryPatternSyntax;\n\n public bool IsNotPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.NotPattern);\n\n public bool IsOrPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.OrPattern);\n\n public bool IsParenthesizedPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ParenthesizedPattern);\n\n public bool IsTypePattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.TypePattern);\n\n public bool IsUnaryPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is UnaryPatternSyntax;\n\n public void GetPartsOfParenthesizedPattern(SyntaxNode node, out SyntaxToken openParen, out SyntaxNode pattern, out SyntaxToken closeParen)\n {\n var parenthesizedPattern = (ParenthesizedPatternSyntax)node;\n openParen = parenthesizedPattern.OpenParenToken;\n pattern = parenthesizedPattern.Pattern;\n closeParen = parenthesizedPattern.CloseParenToken;\n }\n\n public void GetPartsOfBinaryPattern(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var binaryPattern = (BinaryPatternSyntax)node;\n left = binaryPattern.Left;\n operatorToken = binaryPattern.OperatorToken;\n right = binaryPattern.Right;\n }\n\n public void GetPartsOfUnaryPattern(SyntaxNode node, out SyntaxToken operatorToken, out SyntaxNode pattern)\n {\n var unaryPattern = (UnaryPatternSyntax)node;\n operatorToken = unaryPattern.OperatorToken;\n pattern = unaryPattern.Pattern;\n }\n\n public SyntaxNode GetTypeOfTypePattern(SyntaxNode node)\n => ((TypePatternSyntax)node).Type;\n\n public void GetPartsOfInterpolationExpression(SyntaxNode node,\n out SyntaxToken stringStartToken, out SyntaxList contents, out SyntaxToken stringEndToken)\n {\n var interpolatedStringExpression = (InterpolatedStringExpressionSyntax)node;\n stringStartToken = interpolatedStringExpression.StringStartToken;\n contents = interpolatedStringExpression.Contents;\n stringEndToken = interpolatedStringExpression.StringEndToken;\n }\n\n public bool IsVerbatimInterpolatedStringExpression(SyntaxNode node)\n => node is InterpolatedStringExpressionSyntax interpolatedString &&\n interpolatedString.StringStartToken.IsKind(SyntaxKind.InterpolatedVerbatimStringStartToken);\n\n #region IsXXX members\n\n public bool IsAnonymousFunctionExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is AnonymousFunctionExpressionSyntax;\n\n public bool IsBaseNamespaceDeclaration([NotNullWhen(true)] SyntaxNode? node)\n => node is BaseNamespaceDeclarationSyntax;\n\n public bool IsBinaryExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is BinaryExpressionSyntax;\n\n public bool IsLiteralExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is LiteralExpressionSyntax;\n\n public bool IsMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is MemberAccessExpressionSyntax;\n\n public bool IsSimpleName([NotNullWhen(true)] SyntaxNode? node)\n => node is SimpleNameSyntax;\n\n #endregion\n\n #region GetPartsOfXXX members\n\n public void GetPartsOfBinaryExpression(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var binaryExpression = (BinaryExpressionSyntax)node;\n left = binaryExpression.Left;\n operatorToken = binaryExpression.OperatorToken;\n right = binaryExpression.Right;\n }\n\n public void GetPartsOfCompilationUnit(SyntaxNode node, out SyntaxList imports, out SyntaxList attributeLists, out SyntaxList members)\n {\n var compilationUnit = (CompilationUnitSyntax)node;\n imports = compilationUnit.Usings;\n attributeLists = compilationUnit.AttributeLists;\n members = compilationUnit.Members;\n }\n\n public void GetPartsOfConditionalAccessExpression(\n SyntaxNode node, out SyntaxNode expression, out SyntaxToken operatorToken, out SyntaxNode whenNotNull)\n {\n var conditionalAccess = (ConditionalAccessExpressionSyntax)node;\n expression = conditionalAccess.Expression;\n operatorToken = conditionalAccess.OperatorToken;\n whenNotNull = conditionalAccess.WhenNotNull;\n }\n\n public void GetPartsOfConditionalExpression(SyntaxNode node, out SyntaxNode condition, out SyntaxNode whenTrue, out SyntaxNode whenFalse)\n {\n var conditionalExpression = (ConditionalExpressionSyntax)node;\n condition = conditionalExpression.Condition;\n whenTrue = conditionalExpression.WhenTrue;\n whenFalse = conditionalExpression.WhenFalse;\n }\n\n public void GetPartsOfInvocationExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxNode? argumentList)\n {\n var invocation = (InvocationExpressionSyntax)node;\n expression = invocation.Expression;\n argumentList = invocation.ArgumentList;\n }\n\n public void GetPartsOfMemberAccessExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxToken operatorToken, out SyntaxNode name)\n {\n var memberAccess = (MemberAccessExpressionSyntax)node;\n expression = memberAccess.Expression;\n operatorToken = memberAccess.OperatorToken;\n name = memberAccess.Name;\n }\n\n public void GetPartsOfBaseNamespaceDeclaration(SyntaxNode node, out SyntaxNode name, out SyntaxList imports, out SyntaxList members)\n {\n var namespaceDeclaration = (BaseNamespaceDeclarationSyntax)node;\n name = namespaceDeclaration.Name;\n imports = namespaceDeclaration.Usings;\n members = namespaceDeclaration.Members;\n }\n\n public void GetPartsOfObjectCreationExpression(SyntaxNode node, out SyntaxNode type, out SyntaxNode? argumentList, out SyntaxNode? initializer)\n {\n var objectCreationExpression = (ObjectCreationExpressionSyntax)node;\n type = objectCreationExpression.Type;\n argumentList = objectCreationExpression.ArgumentList;\n initializer = objectCreationExpression.Initializer;\n }\n\n public void GetPartsOfParenthesizedExpression(\n SyntaxNode node, out SyntaxToken openParen, out SyntaxNode expression, out SyntaxToken closeParen)\n {\n var parenthesizedExpression = (ParenthesizedExpressionSyntax)node;\n openParen = parenthesizedExpression.OpenParenToken;\n expression = parenthesizedExpression.Expression;\n closeParen = parenthesizedExpression.CloseParenToken;\n }\n\n public void GetPartsOfPrefixUnaryExpression(SyntaxNode node, out SyntaxToken operatorToken, out SyntaxNode operand)\n {\n var prefixUnaryExpression = (PrefixUnaryExpressionSyntax)node;\n operatorToken = prefixUnaryExpression.OperatorToken;\n operand = prefixUnaryExpression.Operand;\n }\n\n public void GetPartsOfQualifiedName(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var qualifiedName = (QualifiedNameSyntax)node;\n left = qualifiedName.Left;\n operatorToken = qualifiedName.DotToken;\n right = qualifiedName.Right;\n }\n\n #endregion\n\n #region GetXXXOfYYY members\n\n public SyntaxNode GetExpressionOfAwaitExpression(SyntaxNode node)\n => ((AwaitExpressionSyntax)node).Expression;\n\n public SyntaxNode GetExpressionOfThrowExpression(SyntaxNode node)\n => ((ThrowExpressionSyntax)node).Expression;\n\n #endregion\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\nusing Microsoft.CodeAnalysis;\nusing Microsoft.CodeAnalysis.CSharp.Extensions;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.LanguageServices;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Microsoft.CodeAnalysis.Shared.Extensions;\nusing Microsoft.CodeAnalysis.Text;\nusing Roslyn.Utilities;\nusing Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;\nusing Microsoft.CodeAnalysis.CSharp.Shared.Extensions;\n\n#if CODE_STYLE\nusing Microsoft.CodeAnalysis.Internal.Editing;\n#else\nusing Microsoft.CodeAnalysis.Editing;\n#endif\n\nnamespace Microsoft.CodeAnalysis.CSharp.LanguageServices\n{\n internal class CSharpSyntaxFacts : ISyntaxFacts\n {\n internal static readonly CSharpSyntaxFacts Instance = new();\n\n protected CSharpSyntaxFacts()\n {\n }\n\n public bool IsCaseSensitive => true;\n\n public StringComparer StringComparer { get; } = StringComparer.Ordinal;\n\n public SyntaxTrivia ElasticMarker\n => SyntaxFactory.ElasticMarker;\n\n public SyntaxTrivia ElasticCarriageReturnLineFeed\n => SyntaxFactory.ElasticCarriageReturnLineFeed;\n\n public ISyntaxKinds SyntaxKinds { get; } = CSharpSyntaxKinds.Instance;\n\n public bool SupportsIndexingInitializer(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp6;\n\n public bool SupportsThrowExpression(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp7;\n\n public bool SupportsLocalFunctionDeclaration(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp7;\n\n public bool SupportsRecord(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp9;\n\n public bool SupportsRecordStruct(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion.IsCSharp10OrAbove();\n\n public SyntaxToken ParseToken(string text)\n => SyntaxFactory.ParseToken(text);\n\n public SyntaxTriviaList ParseLeadingTrivia(string text)\n => SyntaxFactory.ParseLeadingTrivia(text);\n\n public string EscapeIdentifier(string identifier)\n {\n var nullIndex = identifier.IndexOf('\\0');\n if (nullIndex >= 0)\n {\n identifier = identifier.Substring(0, nullIndex);\n }\n\n var needsEscaping = SyntaxFacts.GetKeywordKind(identifier) != SyntaxKind.None;\n return needsEscaping ? \"@\" + identifier : identifier;\n }\n\n public bool IsVerbatimIdentifier(SyntaxToken token)\n => token.IsVerbatimIdentifier();\n\n public bool IsOperator(SyntaxToken token)\n {\n var kind = token.Kind();\n\n return\n (SyntaxFacts.IsAnyUnaryExpression(kind) &&\n (token.Parent is PrefixUnaryExpressionSyntax || token.Parent is PostfixUnaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||\n (SyntaxFacts.IsBinaryExpression(kind) && (token.Parent is BinaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||\n (SyntaxFacts.IsAssignmentExpressionOperatorToken(kind) && token.Parent is AssignmentExpressionSyntax);\n }\n\n public bool IsReservedKeyword(SyntaxToken token)\n => SyntaxFacts.IsReservedKeyword(token.Kind());\n\n public bool IsContextualKeyword(SyntaxToken token)\n => SyntaxFacts.IsContextualKeyword(token.Kind());\n\n public bool IsPreprocessorKeyword(SyntaxToken token)\n => SyntaxFacts.IsPreprocessorKeyword(token.Kind());\n\n public bool IsPreProcessorDirectiveContext(SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)\n => syntaxTree.IsPreProcessorDirectiveContext(\n position, syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken, includeDirectives: true), cancellationToken);\n\n public bool IsEntirelyWithinStringOrCharOrNumericLiteral([NotNullWhen(true)] SyntaxTree? syntaxTree, int position, CancellationToken cancellationToken)\n {\n if (syntaxTree == null)\n {\n return false;\n }\n\n return syntaxTree.IsEntirelyWithinStringOrCharLiteral(position, cancellationToken);\n }\n\n public bool IsDirective([NotNullWhen(true)] SyntaxNode? node)\n => node is DirectiveTriviaSyntax;\n\n public bool TryGetExternalSourceInfo([NotNullWhen(true)] SyntaxNode? node, out ExternalSourceInfo info)\n {\n if (node is LineDirectiveTriviaSyntax lineDirective)\n {\n if (lineDirective.Line.Kind() == SyntaxKind.DefaultKeyword)\n {\n info = new ExternalSourceInfo(null, ends: true);\n return true;\n }\n else if (lineDirective.Line.Kind() == SyntaxKind.NumericLiteralToken &&\n lineDirective.Line.Value is int)\n {\n info = new ExternalSourceInfo((int)lineDirective.Line.Value, false);\n return true;\n }\n }\n\n info = default;\n return false;\n }\n\n public bool IsNameOfSimpleMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n {\n var name = node as SimpleNameSyntax;\n return name.IsSimpleMemberAccessExpressionName();\n }\n\n public bool IsNameOfAnyMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => node?.Parent is MemberAccessExpressionSyntax memberAccess && memberAccess.Name == node;\n\n public bool IsNameOfMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node)\n {\n var name = node as SimpleNameSyntax;\n return name.IsMemberBindingExpressionName();\n }\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? GetStandaloneExpression(SyntaxNode? node)\n => node is ExpressionSyntax expression ? SyntaxFactory.GetStandaloneExpression(expression) : node;\n\n public SyntaxNode? GetRootConditionalAccessExpression(SyntaxNode? node)\n => node.GetRootConditionalAccessExpression();\n\n public bool IsDeclarationExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is DeclarationExpressionSyntax;\n\n public bool IsAttributeName(SyntaxNode node)\n => SyntaxFacts.IsAttributeName(node);\n\n public bool IsNamedArgument([NotNullWhen(true)] SyntaxNode? node)\n => node is ArgumentSyntax arg && arg.NameColon != null;\n\n public bool IsNameOfNamedArgument([NotNullWhen(true)] SyntaxNode? node)\n => node.CheckParent(p => p.Name == node);\n\n public SyntaxToken? GetNameOfParameter(SyntaxNode? node)\n => (node as ParameterSyntax)?.Identifier;\n\n public SyntaxNode? GetDefaultOfParameter(SyntaxNode node)\n => ((ParameterSyntax)node).Default;\n\n public SyntaxNode? GetParameterList(SyntaxNode node)\n => node.GetParameterList();\n\n public bool IsParameterList([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ParameterList, SyntaxKind.BracketedParameterList);\n\n public SyntaxToken GetIdentifierOfGenericName(SyntaxNode node)\n => ((GenericNameSyntax)node).Identifier;\n\n public bool IsUsingDirectiveName([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.UsingDirective, out UsingDirectiveSyntax? usingDirective) &&\n usingDirective.Name == node;\n\n public bool IsUsingAliasDirective([NotNullWhen(true)] SyntaxNode? node)\n => node is UsingDirectiveSyntax usingDirectiveNode && usingDirectiveNode.Alias != null;\n\n public void GetPartsOfUsingAliasDirective(SyntaxNode node, out SyntaxToken globalKeyword, out SyntaxToken alias, out SyntaxNode name)\n {\n var usingDirective = (UsingDirectiveSyntax)node;\n globalKeyword = usingDirective.GlobalKeyword;\n alias = usingDirective.Alias!.Name.Identifier;\n name = usingDirective.Name;\n }\n\n public bool IsDeconstructionForEachStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is ForEachVariableStatementSyntax;\n\n public bool IsDeconstructionAssignment([NotNullWhen(true)] SyntaxNode? node)\n => node is AssignmentExpressionSyntax assignment && assignment.IsDeconstruction();\n\n public Location GetDeconstructionReferenceLocation(SyntaxNode node)\n {\n return node switch\n {\n AssignmentExpressionSyntax assignment => assignment.Left.GetLocation(),\n ForEachVariableStatementSyntax @foreach => @foreach.Variable.GetLocation(),\n _ => throw ExceptionUtilities.UnexpectedValue(node.Kind()),\n };\n }\n\n public bool IsStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is StatementSyntax;\n\n public bool IsExecutableStatement([NotNullWhen(true)] SyntaxNode? node)\n => node is StatementSyntax;\n\n public bool IsMethodBody([NotNullWhen(true)] SyntaxNode? node)\n {\n if (node is BlockSyntax ||\n node is ArrowExpressionClauseSyntax)\n {\n return node.Parent is BaseMethodDeclarationSyntax ||\n node.Parent is AccessorDeclarationSyntax;\n }\n\n return false;\n }\n\n public SyntaxNode? GetExpressionOfReturnStatement(SyntaxNode node)\n => ((ReturnStatementSyntax)node).Expression;\n\n public bool IsThisConstructorInitializer(SyntaxToken token)\n => token.Parent.IsKind(SyntaxKind.ThisConstructorInitializer, out ConstructorInitializerSyntax? constructorInit) &&\n constructorInit.ThisOrBaseKeyword == token;\n\n public bool IsBaseConstructorInitializer(SyntaxToken token)\n => token.Parent.IsKind(SyntaxKind.BaseConstructorInitializer, out ConstructorInitializerSyntax? constructorInit) &&\n constructorInit.ThisOrBaseKeyword == token;\n\n public bool IsQueryKeyword(SyntaxToken token)\n {\n switch (token.Kind())\n {\n case SyntaxKind.FromKeyword:\n case SyntaxKind.JoinKeyword:\n case SyntaxKind.LetKeyword:\n case SyntaxKind.OrderByKeyword:\n case SyntaxKind.WhereKeyword:\n case SyntaxKind.OnKeyword:\n case SyntaxKind.EqualsKeyword:\n case SyntaxKind.InKeyword:\n return token.Parent is QueryClauseSyntax;\n case SyntaxKind.ByKeyword:\n case SyntaxKind.GroupKeyword:\n case SyntaxKind.SelectKeyword:\n return token.Parent is SelectOrGroupClauseSyntax;\n case SyntaxKind.AscendingKeyword:\n case SyntaxKind.DescendingKeyword:\n return token.Parent is OrderingSyntax;\n case SyntaxKind.IntoKeyword:\n return token.Parent.IsKind(SyntaxKind.JoinIntoClause, SyntaxKind.QueryContinuation);\n default:\n return false;\n }\n }\n\n public bool IsPredefinedType(SyntaxToken token)\n => TryGetPredefinedType(token, out _);\n\n public bool IsPredefinedType(SyntaxToken token, PredefinedType type)\n => TryGetPredefinedType(token, out var actualType) && actualType == type;\n\n public bool TryGetPredefinedType(SyntaxToken token, out PredefinedType type)\n {\n type = GetPredefinedType(token);\n return type != PredefinedType.None;\n }\n\n private static PredefinedType GetPredefinedType(SyntaxToken token)\n {\n return (SyntaxKind)token.RawKind switch\n {\n SyntaxKind.BoolKeyword => PredefinedType.Boolean,\n SyntaxKind.ByteKeyword => PredefinedType.Byte,\n SyntaxKind.SByteKeyword => PredefinedType.SByte,\n SyntaxKind.IntKeyword => PredefinedType.Int32,\n SyntaxKind.UIntKeyword => PredefinedType.UInt32,\n SyntaxKind.ShortKeyword => PredefinedType.Int16,\n SyntaxKind.UShortKeyword => PredefinedType.UInt16,\n SyntaxKind.LongKeyword => PredefinedType.Int64,\n SyntaxKind.ULongKeyword => PredefinedType.UInt64,\n SyntaxKind.FloatKeyword => PredefinedType.Single,\n SyntaxKind.DoubleKeyword => PredefinedType.Double,\n SyntaxKind.DecimalKeyword => PredefinedType.Decimal,\n SyntaxKind.StringKeyword => PredefinedType.String,\n SyntaxKind.CharKeyword => PredefinedType.Char,\n SyntaxKind.ObjectKeyword => PredefinedType.Object,\n SyntaxKind.VoidKeyword => PredefinedType.Void,\n _ => PredefinedType.None,\n };\n }\n\n public bool IsPredefinedOperator(SyntaxToken token)\n => TryGetPredefinedOperator(token, out var actualOperator) && actualOperator != PredefinedOperator.None;\n\n public bool IsPredefinedOperator(SyntaxToken token, PredefinedOperator op)\n => TryGetPredefinedOperator(token, out var actualOperator) && actualOperator == op;\n\n public bool TryGetPredefinedOperator(SyntaxToken token, out PredefinedOperator op)\n {\n op = GetPredefinedOperator(token);\n return op != PredefinedOperator.None;\n }\n\n private static PredefinedOperator GetPredefinedOperator(SyntaxToken token)\n {\n switch ((SyntaxKind)token.RawKind)\n {\n case SyntaxKind.PlusToken:\n case SyntaxKind.PlusEqualsToken:\n return PredefinedOperator.Addition;\n\n case SyntaxKind.MinusToken:\n case SyntaxKind.MinusEqualsToken:\n return PredefinedOperator.Subtraction;\n\n case SyntaxKind.AmpersandToken:\n case SyntaxKind.AmpersandEqualsToken:\n return PredefinedOperator.BitwiseAnd;\n\n case SyntaxKind.BarToken:\n case SyntaxKind.BarEqualsToken:\n return PredefinedOperator.BitwiseOr;\n\n case SyntaxKind.MinusMinusToken:\n return PredefinedOperator.Decrement;\n\n case SyntaxKind.PlusPlusToken:\n return PredefinedOperator.Increment;\n\n case SyntaxKind.SlashToken:\n case SyntaxKind.SlashEqualsToken:\n return PredefinedOperator.Division;\n\n case SyntaxKind.EqualsEqualsToken:\n return PredefinedOperator.Equality;\n\n case SyntaxKind.CaretToken:\n case SyntaxKind.CaretEqualsToken:\n return PredefinedOperator.ExclusiveOr;\n\n case SyntaxKind.GreaterThanToken:\n return PredefinedOperator.GreaterThan;\n\n case SyntaxKind.GreaterThanEqualsToken:\n return PredefinedOperator.GreaterThanOrEqual;\n\n case SyntaxKind.ExclamationEqualsToken:\n return PredefinedOperator.Inequality;\n\n case SyntaxKind.LessThanLessThanToken:\n case SyntaxKind.LessThanLessThanEqualsToken:\n return PredefinedOperator.LeftShift;\n\n case SyntaxKind.LessThanToken:\n return PredefinedOperator.LessThan;\n\n case SyntaxKind.LessThanEqualsToken:\n return PredefinedOperator.LessThanOrEqual;\n\n case SyntaxKind.AsteriskToken:\n case SyntaxKind.AsteriskEqualsToken:\n return PredefinedOperator.Multiplication;\n\n case SyntaxKind.PercentToken:\n case SyntaxKind.PercentEqualsToken:\n return PredefinedOperator.Modulus;\n\n case SyntaxKind.ExclamationToken:\n case SyntaxKind.TildeToken:\n return PredefinedOperator.Complement;\n\n case SyntaxKind.GreaterThanGreaterThanToken:\n case SyntaxKind.GreaterThanGreaterThanEqualsToken:\n return PredefinedOperator.RightShift;\n }\n\n return PredefinedOperator.None;\n }\n\n public string GetText(int kind)\n => SyntaxFacts.GetText((SyntaxKind)kind);\n\n public bool IsIdentifierStartCharacter(char c)\n => SyntaxFacts.IsIdentifierStartCharacter(c);\n\n public bool IsIdentifierPartCharacter(char c)\n => SyntaxFacts.IsIdentifierPartCharacter(c);\n\n public bool IsIdentifierEscapeCharacter(char c)\n => c == '@';\n\n public bool IsValidIdentifier(string identifier)\n {\n var token = SyntaxFactory.ParseToken(identifier);\n return this.IsIdentifier(token) && !token.ContainsDiagnostics && token.ToString().Length == identifier.Length;\n }\n\n public bool IsVerbatimIdentifier(string identifier)\n {\n var token = SyntaxFactory.ParseToken(identifier);\n return this.IsIdentifier(token) && !token.ContainsDiagnostics && token.ToString().Length == identifier.Length && token.IsVerbatimIdentifier();\n }\n\n public bool IsTypeCharacter(char c) => false;\n\n public bool IsStartOfUnicodeEscapeSequence(char c)\n => c == '\\\\';\n\n public bool IsLiteral(SyntaxToken token)\n {\n switch (token.Kind())\n {\n case SyntaxKind.NumericLiteralToken:\n case SyntaxKind.CharacterLiteralToken:\n case SyntaxKind.StringLiteralToken:\n case SyntaxKind.NullKeyword:\n case SyntaxKind.TrueKeyword:\n case SyntaxKind.FalseKeyword:\n case SyntaxKind.InterpolatedStringStartToken:\n case SyntaxKind.InterpolatedStringEndToken:\n case SyntaxKind.InterpolatedVerbatimStringStartToken:\n case SyntaxKind.InterpolatedStringTextToken:\n return true;\n default:\n return false;\n }\n }\n\n public bool IsStringLiteralOrInterpolatedStringLiteral(SyntaxToken token)\n => token.IsKind(SyntaxKind.StringLiteralToken, SyntaxKind.InterpolatedStringTextToken);\n\n public bool IsBindableToken(SyntaxToken token)\n {\n if (this.IsWord(token) || this.IsLiteral(token) || this.IsOperator(token))\n {\n switch ((SyntaxKind)token.RawKind)\n {\n case SyntaxKind.DelegateKeyword:\n case SyntaxKind.VoidKeyword:\n return false;\n }\n\n return true;\n }\n\n // In the order by clause a comma might be bound to ThenBy or ThenByDescending\n if (token.Kind() == SyntaxKind.CommaToken && token.Parent.IsKind(SyntaxKind.OrderByClause))\n {\n return true;\n }\n\n return false;\n }\n\n public bool IsPostfixUnaryExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is PostfixUnaryExpressionSyntax;\n\n public bool IsMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is MemberBindingExpressionSyntax;\n\n public bool IsPointerMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => (node as MemberAccessExpressionSyntax)?.Kind() == SyntaxKind.PointerMemberAccessExpression;\n\n public void GetNameAndArityOfSimpleName(SyntaxNode node, out string name, out int arity)\n {\n var simpleName = (SimpleNameSyntax)node;\n name = simpleName.Identifier.ValueText;\n arity = simpleName.Arity;\n }\n\n public bool LooksGeneric(SyntaxNode simpleName)\n => simpleName.IsKind(SyntaxKind.GenericName) ||\n simpleName.GetLastToken().GetNextToken().Kind() == SyntaxKind.LessThanToken;\n\n public SyntaxNode? GetTargetOfMemberBinding(SyntaxNode? node)\n => (node as MemberBindingExpressionSyntax).GetParentConditionalAccessExpression()?.Expression;\n\n public SyntaxNode GetNameOfMemberBindingExpression(SyntaxNode node)\n => ((MemberBindingExpressionSyntax)node).Name;\n\n public SyntaxNode? GetExpressionOfMemberAccessExpression(SyntaxNode node, bool allowImplicitTarget)\n => ((MemberAccessExpressionSyntax)node).Expression;\n\n public void GetPartsOfElementAccessExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxNode argumentList)\n {\n var elementAccess = (ElementAccessExpressionSyntax)node;\n expression = elementAccess.Expression;\n argumentList = elementAccess.ArgumentList;\n }\n\n public SyntaxNode GetExpressionOfInterpolation(SyntaxNode node)\n => ((InterpolationSyntax)node).Expression;\n\n public bool IsInStaticContext(SyntaxNode node)\n => node.IsInStaticContext();\n\n public bool IsInNamespaceOrTypeContext([NotNullWhen(true)] SyntaxNode? node)\n => SyntaxFacts.IsInNamespaceOrTypeContext(node as ExpressionSyntax);\n\n public bool IsBaseTypeList([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.BaseList);\n\n public SyntaxNode GetExpressionOfArgument(SyntaxNode node)\n => ((ArgumentSyntax)node).Expression;\n\n public RefKind GetRefKindOfArgument(SyntaxNode node)\n => ((ArgumentSyntax)node).GetRefKind();\n\n public bool IsArgument([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Argument);\n\n public bool IsSimpleArgument([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is ArgumentSyntax argument &&\n argument.RefOrOutKeyword.Kind() == SyntaxKind.None &&\n argument.NameColon == null;\n }\n\n public bool IsInConstantContext([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsInConstantContext();\n\n public bool IsInConstructor(SyntaxNode node)\n => node.GetAncestor() != null;\n\n public bool IsUnsafeContext(SyntaxNode node)\n => node.IsUnsafeContext();\n\n public SyntaxNode GetNameOfAttribute(SyntaxNode node)\n => ((AttributeSyntax)node).Name;\n\n public bool IsAttributeNamedArgumentIdentifier([NotNullWhen(true)] SyntaxNode? node)\n => (node as IdentifierNameSyntax).IsAttributeNamedArgumentIdentifier();\n\n public SyntaxNode? GetContainingTypeDeclaration(SyntaxNode? root, int position)\n {\n if (root == null)\n {\n throw new ArgumentNullException(nameof(root));\n }\n\n if (position < 0 || position > root.Span.End)\n {\n throw new ArgumentOutOfRangeException(nameof(position));\n }\n\n return root\n .FindToken(position)\n .GetAncestors()\n .FirstOrDefault(n => n is BaseTypeDeclarationSyntax || n is DelegateDeclarationSyntax);\n }\n\n public SyntaxNode? GetContainingVariableDeclaratorOfFieldDeclaration(SyntaxNode? node)\n => throw ExceptionUtilities.Unreachable;\n\n public bool IsNameOfSubpattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IdentifierName) &&\n node.IsParentKind(SyntaxKind.NameColon) &&\n node.Parent.IsParentKind(SyntaxKind.Subpattern);\n\n public bool IsPropertyPatternClause(SyntaxNode node)\n => node.Kind() == SyntaxKind.PropertyPatternClause;\n\n public bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node)\n => IsMemberInitializerNamedAssignmentIdentifier(node, out _);\n\n public bool IsMemberInitializerNamedAssignmentIdentifier(\n [NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance)\n {\n initializedInstance = null;\n if (node is IdentifierNameSyntax identifier &&\n identifier.IsLeftSideOfAssignExpression())\n {\n if (identifier.Parent.IsParentKind(SyntaxKind.WithInitializerExpression))\n {\n var withInitializer = identifier.Parent.GetRequiredParent();\n initializedInstance = withInitializer.GetRequiredParent();\n return true;\n }\n else if (identifier.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression))\n {\n var objectInitializer = identifier.Parent.GetRequiredParent();\n if (objectInitializer.Parent is BaseObjectCreationExpressionSyntax)\n {\n initializedInstance = objectInitializer.Parent;\n return true;\n }\n else if (objectInitializer.IsParentKind(SyntaxKind.SimpleAssignmentExpression, out AssignmentExpressionSyntax? assignment))\n {\n initializedInstance = assignment.Left;\n return true;\n }\n }\n }\n\n return false;\n }\n\n public bool IsElementAccessExpression(SyntaxNode? node)\n => node.IsKind(SyntaxKind.ElementAccessExpression);\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? ConvertToSingleLine(SyntaxNode? node, bool useElasticTrivia = false)\n => node.ConvertToSingleLine(useElasticTrivia);\n\n public bool IsIndexerMemberCRef(SyntaxNode? node)\n => node.IsKind(SyntaxKind.IndexerMemberCref);\n\n public SyntaxNode? GetContainingMemberDeclaration(SyntaxNode? root, int position, bool useFullSpan = true)\n {\n Contract.ThrowIfNull(root, \"root\");\n Contract.ThrowIfTrue(position < 0 || position > root.FullSpan.End, \"position\");\n\n var end = root.FullSpan.End;\n if (end == 0)\n {\n // empty file\n return null;\n }\n\n // make sure position doesn't touch end of root\n position = Math.Min(position, end - 1);\n\n var node = root.FindToken(position).Parent;\n while (node != null)\n {\n if (useFullSpan || node.Span.Contains(position))\n {\n var kind = node.Kind();\n if ((kind != SyntaxKind.GlobalStatement) && (kind != SyntaxKind.IncompleteMember) && (node is MemberDeclarationSyntax))\n {\n return node;\n }\n }\n\n node = node.Parent;\n }\n\n return null;\n }\n\n public bool IsMethodLevelMember([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is BaseMethodDeclarationSyntax ||\n node is BasePropertyDeclarationSyntax ||\n node is EnumMemberDeclarationSyntax ||\n node is BaseFieldDeclarationSyntax;\n }\n\n public bool IsTopLevelNodeWithMembers([NotNullWhen(true)] SyntaxNode? node)\n {\n return node is BaseNamespaceDeclarationSyntax ||\n node is TypeDeclarationSyntax ||\n node is EnumDeclarationSyntax;\n }\n\n private const string dotToken = \".\";\n\n public string GetDisplayName(SyntaxNode? node, DisplayNameOptions options, string? rootNamespace = null)\n {\n if (node == null)\n {\n return string.Empty;\n }\n\n var pooled = PooledStringBuilder.GetInstance();\n var builder = pooled.Builder;\n\n // return type\n var memberDeclaration = node as MemberDeclarationSyntax;\n if ((options & DisplayNameOptions.IncludeType) != 0)\n {\n var type = memberDeclaration.GetMemberType();\n if (type != null && !type.IsMissing)\n {\n builder.Append(type);\n builder.Append(' ');\n }\n }\n\n var names = ArrayBuilder.GetInstance();\n // containing type(s)\n var parent = node.GetAncestor() ?? node.Parent;\n while (parent is TypeDeclarationSyntax)\n {\n names.Push(GetName(parent, options));\n parent = parent.Parent;\n }\n\n // containing namespace(s) in source (if any)\n if ((options & DisplayNameOptions.IncludeNamespaces) != 0)\n {\n while (parent is BaseNamespaceDeclarationSyntax)\n {\n names.Add(GetName(parent, options));\n parent = parent.Parent;\n }\n }\n\n while (!names.IsEmpty())\n {\n var name = names.Pop();\n if (name != null)\n {\n builder.Append(name);\n builder.Append(dotToken);\n }\n }\n\n // name (including generic type parameters)\n builder.Append(GetName(node, options));\n\n // parameter list (if any)\n if ((options & DisplayNameOptions.IncludeParameters) != 0)\n {\n builder.Append(memberDeclaration.GetParameterList());\n }\n\n return pooled.ToStringAndFree();\n }\n\n private static string? GetName(SyntaxNode node, DisplayNameOptions options)\n {\n const string missingTokenPlaceholder = \"?\";\n\n switch (node.Kind())\n {\n case SyntaxKind.CompilationUnit:\n return null;\n case SyntaxKind.IdentifierName:\n var identifier = ((IdentifierNameSyntax)node).Identifier;\n return identifier.IsMissing ? missingTokenPlaceholder : identifier.Text;\n case SyntaxKind.IncompleteMember:\n return missingTokenPlaceholder;\n case SyntaxKind.NamespaceDeclaration:\n case SyntaxKind.FileScopedNamespaceDeclaration:\n return GetName(((BaseNamespaceDeclarationSyntax)node).Name, options);\n case SyntaxKind.QualifiedName:\n var qualified = (QualifiedNameSyntax)node;\n return GetName(qualified.Left, options) + dotToken + GetName(qualified.Right, options);\n }\n\n string? name = null;\n if (node is MemberDeclarationSyntax memberDeclaration)\n {\n if (memberDeclaration.Kind() == SyntaxKind.ConversionOperatorDeclaration)\n {\n name = (memberDeclaration as ConversionOperatorDeclarationSyntax)?.Type.ToString();\n }\n else\n {\n var nameToken = memberDeclaration.GetNameToken();\n if (nameToken != default)\n {\n name = nameToken.IsMissing ? missingTokenPlaceholder : nameToken.Text;\n if (memberDeclaration.Kind() == SyntaxKind.DestructorDeclaration)\n {\n name = \"~\" + name;\n }\n\n if ((options & DisplayNameOptions.IncludeTypeParameters) != 0)\n {\n var pooled = PooledStringBuilder.GetInstance();\n var builder = pooled.Builder;\n builder.Append(name);\n AppendTypeParameterList(builder, memberDeclaration.GetTypeParameterList());\n name = pooled.ToStringAndFree();\n }\n }\n else\n {\n Debug.Assert(memberDeclaration.Kind() == SyntaxKind.IncompleteMember);\n name = \"?\";\n }\n }\n }\n else\n {\n if (node is VariableDeclaratorSyntax fieldDeclarator)\n {\n var nameToken = fieldDeclarator.Identifier;\n if (nameToken != default)\n {\n name = nameToken.IsMissing ? missingTokenPlaceholder : nameToken.Text;\n }\n }\n }\n\n Debug.Assert(name != null, \"Unexpected node type \" + node.Kind());\n return name;\n }\n\n private static void AppendTypeParameterList(StringBuilder builder, TypeParameterListSyntax typeParameterList)\n {\n if (typeParameterList != null && typeParameterList.Parameters.Count > 0)\n {\n builder.Append('<');\n builder.Append(typeParameterList.Parameters[0].Identifier.ValueText);\n for (var i = 1; i < typeParameterList.Parameters.Count; i++)\n {\n builder.Append(\", \");\n builder.Append(typeParameterList.Parameters[i].Identifier.ValueText);\n }\n\n builder.Append('>');\n }\n }\n\n public List GetTopLevelAndMethodLevelMembers(SyntaxNode? root)\n {\n var list = new List();\n AppendMembers(root, list, topLevel: true, methodLevel: true);\n return list;\n }\n\n public List GetMethodLevelMembers(SyntaxNode? root)\n {\n var list = new List();\n AppendMembers(root, list, topLevel: false, methodLevel: true);\n return list;\n }\n\n public SyntaxList GetMembersOfTypeDeclaration(SyntaxNode typeDeclaration)\n => ((TypeDeclarationSyntax)typeDeclaration).Members;\n\n private void AppendMembers(SyntaxNode? node, List list, bool topLevel, bool methodLevel)\n {\n Debug.Assert(topLevel || methodLevel);\n\n foreach (var member in node.GetMembers())\n {\n if (IsTopLevelNodeWithMembers(member))\n {\n if (topLevel)\n {\n list.Add(member);\n }\n\n AppendMembers(member, list, topLevel, methodLevel);\n continue;\n }\n\n if (methodLevel && IsMethodLevelMember(member))\n {\n list.Add(member);\n }\n }\n }\n\n public TextSpan GetMemberBodySpanForSpeculativeBinding(SyntaxNode node)\n {\n if (node.Span.IsEmpty)\n {\n return default;\n }\n\n var member = GetContainingMemberDeclaration(node, node.SpanStart);\n if (member == null)\n {\n return default;\n }\n\n // TODO: currently we only support method for now\n if (member is BaseMethodDeclarationSyntax method)\n {\n if (method.Body == null)\n {\n return default;\n }\n\n return GetBlockBodySpan(method.Body);\n }\n\n return default;\n }\n\n public bool ContainsInMemberBody([NotNullWhen(true)] SyntaxNode? node, TextSpan span)\n {\n switch (node)\n {\n case ConstructorDeclarationSyntax constructor:\n return (constructor.Body != null && GetBlockBodySpan(constructor.Body).Contains(span)) ||\n (constructor.Initializer != null && constructor.Initializer.Span.Contains(span));\n case BaseMethodDeclarationSyntax method:\n return method.Body != null && GetBlockBodySpan(method.Body).Contains(span);\n case BasePropertyDeclarationSyntax property:\n return property.AccessorList != null && property.AccessorList.Span.Contains(span);\n case EnumMemberDeclarationSyntax @enum:\n return @enum.EqualsValue != null && @enum.EqualsValue.Span.Contains(span);\n case BaseFieldDeclarationSyntax field:\n return field.Declaration != null && field.Declaration.Span.Contains(span);\n }\n\n return false;\n }\n\n private static TextSpan GetBlockBodySpan(BlockSyntax body)\n => TextSpan.FromBounds(body.OpenBraceToken.Span.End, body.CloseBraceToken.SpanStart);\n\n public SyntaxNode? TryGetBindableParent(SyntaxToken token)\n {\n var node = token.Parent;\n while (node != null)\n {\n var parent = node.Parent;\n\n // If this node is on the left side of a member access expression, don't ascend\n // further or we'll end up binding to something else.\n if (parent is MemberAccessExpressionSyntax memberAccess)\n {\n if (memberAccess.Expression == node)\n {\n break;\n }\n }\n\n // If this node is on the left side of a qualified name, don't ascend\n // further or we'll end up binding to something else.\n if (parent is QualifiedNameSyntax qualifiedName)\n {\n if (qualifiedName.Left == node)\n {\n break;\n }\n }\n\n // If this node is on the left side of a alias-qualified name, don't ascend\n // further or we'll end up binding to something else.\n if (parent is AliasQualifiedNameSyntax aliasQualifiedName)\n {\n if (aliasQualifiedName.Alias == node)\n {\n break;\n }\n }\n\n // If this node is the type of an object creation expression, return the\n // object creation expression.\n if (parent is ObjectCreationExpressionSyntax objectCreation)\n {\n if (objectCreation.Type == node)\n {\n node = parent;\n break;\n }\n }\n\n // The inside of an interpolated string is treated as its own token so we\n // need to force navigation to the parent expression syntax.\n if (node is InterpolatedStringTextSyntax && parent is InterpolatedStringExpressionSyntax)\n {\n node = parent;\n break;\n }\n\n // If this node is not parented by a name, we're done.\n if (!(parent is NameSyntax))\n {\n break;\n }\n\n node = parent;\n }\n\n if (node is VarPatternSyntax)\n {\n return node;\n }\n\n // Patterns are never bindable (though their constituent types/exprs may be).\n return node is PatternSyntax ? null : node;\n }\n\n public IEnumerable GetConstructors(SyntaxNode? root, CancellationToken cancellationToken)\n {\n if (root is not CompilationUnitSyntax compilationUnit)\n {\n return SpecializedCollections.EmptyEnumerable();\n }\n\n var constructors = new List();\n AppendConstructors(compilationUnit.Members, constructors, cancellationToken);\n return constructors;\n }\n\n private void AppendConstructors(SyntaxList members, List constructors, CancellationToken cancellationToken)\n {\n foreach (var member in members)\n {\n cancellationToken.ThrowIfCancellationRequested();\n switch (member)\n {\n case ConstructorDeclarationSyntax constructor:\n constructors.Add(constructor);\n continue;\n case BaseNamespaceDeclarationSyntax @namespace:\n AppendConstructors(@namespace.Members, constructors, cancellationToken);\n break;\n case ClassDeclarationSyntax @class:\n AppendConstructors(@class.Members, constructors, cancellationToken);\n break;\n case RecordDeclarationSyntax record:\n AppendConstructors(record.Members, constructors, cancellationToken);\n break;\n case StructDeclarationSyntax @struct:\n AppendConstructors(@struct.Members, constructors, cancellationToken);\n break;\n }\n }\n }\n\n public bool TryGetCorrespondingOpenBrace(SyntaxToken token, out SyntaxToken openBrace)\n {\n if (token.Kind() == SyntaxKind.CloseBraceToken)\n {\n var tuple = token.Parent.GetBraces();\n\n openBrace = tuple.openBrace;\n return openBrace.Kind() == SyntaxKind.OpenBraceToken;\n }\n\n openBrace = default;\n return false;\n }\n\n public TextSpan GetInactiveRegionSpanAroundPosition(SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)\n {\n var trivia = syntaxTree.GetRoot(cancellationToken).FindTrivia(position, findInsideTrivia: false);\n if (trivia.Kind() == SyntaxKind.DisabledTextTrivia)\n {\n return trivia.FullSpan;\n }\n\n var token = syntaxTree.FindTokenOrEndToken(position, cancellationToken);\n if (token.Kind() == SyntaxKind.EndOfFileToken)\n {\n var triviaList = token.LeadingTrivia;\n foreach (var triviaTok in triviaList.Reverse())\n {\n if (triviaTok.Span.Contains(position))\n {\n return default;\n }\n\n if (triviaTok.Span.End < position)\n {\n if (!triviaTok.HasStructure)\n {\n return default;\n }\n\n var structure = triviaTok.GetStructure();\n if (structure is BranchingDirectiveTriviaSyntax branch)\n {\n return !branch.IsActive || !branch.BranchTaken ? TextSpan.FromBounds(branch.FullSpan.Start, position) : default;\n }\n }\n }\n }\n\n return default;\n }\n\n public string GetNameForArgument(SyntaxNode? argument)\n => (argument as ArgumentSyntax)?.NameColon?.Name.Identifier.ValueText ?? string.Empty;\n\n public string GetNameForAttributeArgument(SyntaxNode? argument)\n => (argument as AttributeArgumentSyntax)?.NameEquals?.Name.Identifier.ValueText ?? string.Empty;\n\n public bool IsLeftSideOfDot([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfDot();\n\n public SyntaxNode? GetRightSideOfDot(SyntaxNode? node)\n {\n return (node as QualifiedNameSyntax)?.Right ??\n (node as MemberAccessExpressionSyntax)?.Name;\n }\n\n public SyntaxNode? GetLeftSideOfDot(SyntaxNode? node, bool allowImplicitTarget)\n {\n return (node as QualifiedNameSyntax)?.Left ??\n (node as MemberAccessExpressionSyntax)?.Expression;\n }\n\n public bool IsLeftSideOfExplicitInterfaceSpecifier([NotNullWhen(true)] SyntaxNode? node)\n => (node as NameSyntax).IsLeftSideOfExplicitInterfaceSpecifier();\n\n public bool IsLeftSideOfAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfAssignExpression();\n\n public bool IsLeftSideOfAnyAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfAnyAssignExpression();\n\n public bool IsLeftSideOfCompoundAssignment([NotNullWhen(true)] SyntaxNode? node)\n => (node as ExpressionSyntax).IsLeftSideOfCompoundAssignExpression();\n\n public SyntaxNode GetRightHandSideOfAssignment(SyntaxNode node)\n => ((AssignmentExpressionSyntax)node).Right;\n\n public bool IsInferredAnonymousObjectMemberDeclarator([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator, out AnonymousObjectMemberDeclaratorSyntax? anonObject) &&\n anonObject.NameEquals == null;\n\n public bool IsOperandOfIncrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.PostIncrementExpression) ||\n node.IsParentKind(SyntaxKind.PreIncrementExpression);\n\n public static bool IsOperandOfDecrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsParentKind(SyntaxKind.PostDecrementExpression) ||\n node.IsParentKind(SyntaxKind.PreDecrementExpression);\n\n public bool IsOperandOfIncrementOrDecrementExpression([NotNullWhen(true)] SyntaxNode? node)\n => IsOperandOfIncrementExpression(node) || IsOperandOfDecrementExpression(node);\n\n public SyntaxList GetContentsOfInterpolatedString(SyntaxNode interpolatedString)\n => ((InterpolatedStringExpressionSyntax)interpolatedString).Contents;\n\n public bool IsVerbatimStringLiteral(SyntaxToken token)\n => token.IsVerbatimStringLiteral();\n\n public bool IsNumericLiteral(SyntaxToken token)\n => token.Kind() == SyntaxKind.NumericLiteralToken;\n\n public SeparatedSyntaxList GetArgumentsOfInvocationExpression(SyntaxNode invocationExpression)\n => GetArgumentsOfArgumentList(((InvocationExpressionSyntax)invocationExpression).ArgumentList);\n\n public SeparatedSyntaxList GetArgumentsOfObjectCreationExpression(SyntaxNode objectCreationExpression)\n => ((BaseObjectCreationExpressionSyntax)objectCreationExpression).ArgumentList is { } argumentList\n ? GetArgumentsOfArgumentList(argumentList)\n : default;\n\n public SeparatedSyntaxList GetArgumentsOfArgumentList(SyntaxNode argumentList)\n => ((BaseArgumentListSyntax)argumentList).Arguments;\n\n public bool IsRegularComment(SyntaxTrivia trivia)\n => trivia.IsRegularComment();\n\n public bool IsDocumentationComment(SyntaxTrivia trivia)\n => trivia.IsDocComment();\n\n public bool IsElastic(SyntaxTrivia trivia)\n => trivia.IsElastic();\n\n public bool IsPragmaDirective(SyntaxTrivia trivia, out bool isDisable, out bool isActive, out SeparatedSyntaxList errorCodes)\n => trivia.IsPragmaDirective(out isDisable, out isActive, out errorCodes);\n\n public bool IsDocumentationCommentExteriorTrivia(SyntaxTrivia trivia)\n => trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia;\n\n public bool IsDocumentationComment(SyntaxNode node)\n => SyntaxFacts.IsDocumentationCommentTrivia(node.Kind());\n\n public bool IsUsingOrExternOrImport([NotNullWhen(true)] SyntaxNode? node)\n {\n return node.IsKind(SyntaxKind.UsingDirective) ||\n node.IsKind(SyntaxKind.ExternAliasDirective);\n }\n\n public bool IsGlobalAssemblyAttribute([NotNullWhen(true)] SyntaxNode? node)\n => IsGlobalAttribute(node, SyntaxKind.AssemblyKeyword);\n\n public bool IsGlobalModuleAttribute([NotNullWhen(true)] SyntaxNode? node)\n => IsGlobalAttribute(node, SyntaxKind.ModuleKeyword);\n\n private static bool IsGlobalAttribute([NotNullWhen(true)] SyntaxNode? node, SyntaxKind attributeTarget)\n => node.IsKind(SyntaxKind.Attribute) &&\n node.Parent.IsKind(SyntaxKind.AttributeList, out AttributeListSyntax? attributeList) &&\n attributeList.Target?.Identifier.Kind() == attributeTarget;\n\n private static bool IsMemberDeclaration(SyntaxNode node)\n {\n // From the C# language spec:\n // class-member-declaration:\n // constant-declaration\n // field-declaration\n // method-declaration\n // property-declaration\n // event-declaration\n // indexer-declaration\n // operator-declaration\n // constructor-declaration\n // destructor-declaration\n // static-constructor-declaration\n // type-declaration\n switch (node.Kind())\n {\n // Because fields declarations can define multiple symbols \"public int a, b;\"\n // We want to get the VariableDeclarator node inside the field declaration to print out the symbol for the name.\n case SyntaxKind.VariableDeclarator:\n return node.Parent.IsParentKind(SyntaxKind.FieldDeclaration) ||\n node.Parent.IsParentKind(SyntaxKind.EventFieldDeclaration);\n\n case SyntaxKind.FieldDeclaration:\n case SyntaxKind.MethodDeclaration:\n case SyntaxKind.PropertyDeclaration:\n case SyntaxKind.GetAccessorDeclaration:\n case SyntaxKind.SetAccessorDeclaration:\n case SyntaxKind.EventDeclaration:\n case SyntaxKind.EventFieldDeclaration:\n case SyntaxKind.AddAccessorDeclaration:\n case SyntaxKind.RemoveAccessorDeclaration:\n case SyntaxKind.IndexerDeclaration:\n case SyntaxKind.OperatorDeclaration:\n case SyntaxKind.ConversionOperatorDeclaration:\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n return true;\n\n default:\n return false;\n }\n }\n\n public bool IsDeclaration(SyntaxNode node)\n => SyntaxFacts.IsNamespaceMemberDeclaration(node.Kind()) || IsMemberDeclaration(node);\n\n public bool IsTypeDeclaration(SyntaxNode node)\n => SyntaxFacts.IsTypeDeclaration(node.Kind());\n\n public bool IsSimpleAssignmentStatement([NotNullWhen(true)] SyntaxNode? statement)\n => statement.IsKind(SyntaxKind.ExpressionStatement, out ExpressionStatementSyntax? exprStatement) &&\n exprStatement.Expression.IsKind(SyntaxKind.SimpleAssignmentExpression);\n\n public void GetPartsOfAssignmentStatement(\n SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n GetPartsOfAssignmentExpressionOrStatement(\n ((ExpressionStatementSyntax)statement).Expression, out left, out operatorToken, out right);\n }\n\n public void GetPartsOfAssignmentExpressionOrStatement(\n SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var expression = statement;\n if (statement is ExpressionStatementSyntax expressionStatement)\n {\n expression = expressionStatement.Expression;\n }\n\n var assignment = (AssignmentExpressionSyntax)expression;\n left = assignment.Left;\n operatorToken = assignment.OperatorToken;\n right = assignment.Right;\n }\n\n public SyntaxToken GetIdentifierOfSimpleName(SyntaxNode node)\n => ((SimpleNameSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclaratorSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfParameter(SyntaxNode node)\n => ((ParameterSyntax)node).Identifier;\n\n public SyntaxToken GetIdentifierOfTypeDeclaration(SyntaxNode node)\n => node switch\n {\n BaseTypeDeclarationSyntax typeDecl => typeDecl.Identifier,\n DelegateDeclarationSyntax delegateDecl => delegateDecl.Identifier,\n _ => throw ExceptionUtilities.UnexpectedValue(node),\n };\n\n public SyntaxToken GetIdentifierOfIdentifierName(SyntaxNode node)\n => ((IdentifierNameSyntax)node).Identifier;\n\n public bool IsDeclaratorOfLocalDeclarationStatement(SyntaxNode declarator, SyntaxNode localDeclarationStatement)\n {\n return ((LocalDeclarationStatementSyntax)localDeclarationStatement).Declaration.Variables.Contains(\n (VariableDeclaratorSyntax)declarator);\n }\n\n public bool AreEquivalent(SyntaxToken token1, SyntaxToken token2)\n => SyntaxFactory.AreEquivalent(token1, token2);\n\n public bool AreEquivalent(SyntaxNode? node1, SyntaxNode? node2)\n => SyntaxFactory.AreEquivalent(node1, node2);\n\n public static SyntaxNode GetExpressionOfInvocationExpression(SyntaxNode node)\n => ((InvocationExpressionSyntax)node).Expression;\n\n public bool IsExpressionOfForeach([NotNullWhen(true)] SyntaxNode? node)\n => node?.Parent is ForEachStatementSyntax foreachStatement && foreachStatement.Expression == node;\n\n public SyntaxNode GetExpressionOfExpressionStatement(SyntaxNode node)\n => ((ExpressionStatementSyntax)node).Expression;\n\n public bool IsIsExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IsExpression);\n\n [return: NotNullIfNotNull(\"node\")]\n public SyntaxNode? WalkDownParentheses(SyntaxNode? node)\n => (node as ExpressionSyntax)?.WalkDownParentheses() ?? node;\n\n public void GetPartsOfTupleExpression(SyntaxNode node,\n out SyntaxToken openParen, out SeparatedSyntaxList arguments, out SyntaxToken closeParen) where TArgumentSyntax : SyntaxNode\n {\n var tupleExpression = (TupleExpressionSyntax)node;\n openParen = tupleExpression.OpenParenToken;\n arguments = (SeparatedSyntaxList)tupleExpression.Arguments;\n closeParen = tupleExpression.CloseParenToken;\n }\n\n public bool IsPreprocessorDirective(SyntaxTrivia trivia)\n => SyntaxFacts.IsPreprocessorDirective(trivia.Kind());\n\n public bool ContainsInterleavedDirective(TextSpan span, SyntaxToken token, CancellationToken cancellationToken)\n => token.ContainsInterleavedDirective(span, cancellationToken);\n\n public SyntaxTokenList GetModifiers(SyntaxNode? node)\n => node.GetModifiers();\n\n public SyntaxNode? WithModifiers(SyntaxNode? node, SyntaxTokenList modifiers)\n => node.WithModifiers(modifiers);\n\n public SeparatedSyntaxList GetVariablesOfLocalDeclarationStatement(SyntaxNode node)\n => ((LocalDeclarationStatementSyntax)node).Declaration.Variables;\n\n public SyntaxNode? GetInitializerOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclaratorSyntax)node).Initializer;\n\n public SyntaxNode GetTypeOfVariableDeclarator(SyntaxNode node)\n => ((VariableDeclarationSyntax)((VariableDeclaratorSyntax)node).Parent!).Type;\n\n public SyntaxNode? GetValueOfEqualsValueClause(SyntaxNode? node)\n => ((EqualsValueClauseSyntax?)node)?.Value;\n\n public bool IsScopeBlock([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Block);\n\n public bool IsExecutableBlock([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.Block, SyntaxKind.SwitchSection, SyntaxKind.CompilationUnit);\n\n public IReadOnlyList GetExecutableBlockStatements(SyntaxNode? node)\n {\n return node switch\n {\n BlockSyntax block => block.Statements,\n SwitchSectionSyntax switchSection => switchSection.Statements,\n CompilationUnitSyntax compilationUnit => compilationUnit.Members.OfType().SelectAsArray(globalStatement => globalStatement.Statement),\n _ => throw ExceptionUtilities.UnexpectedValue(node),\n };\n }\n\n public SyntaxNode? FindInnermostCommonExecutableBlock(IEnumerable nodes)\n => nodes.FindInnermostCommonNode(node => IsExecutableBlock(node));\n\n public bool IsStatementContainer([NotNullWhen(true)] SyntaxNode? node)\n => IsExecutableBlock(node) || node.IsEmbeddedStatementOwner();\n\n public IReadOnlyList GetStatementContainerStatements(SyntaxNode? node)\n {\n if (IsExecutableBlock(node))\n return GetExecutableBlockStatements(node);\n else if (node.GetEmbeddedStatement() is { } embeddedStatement)\n return ImmutableArray.Create(embeddedStatement);\n else\n return ImmutableArray.Empty;\n }\n\n public bool IsConversionExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is CastExpressionSyntax;\n\n public bool IsCastExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is CastExpressionSyntax;\n\n public void GetPartsOfCastExpression(SyntaxNode node, out SyntaxNode type, out SyntaxNode expression)\n {\n var cast = (CastExpressionSyntax)node;\n type = cast.Type;\n expression = cast.Expression;\n }\n\n public SyntaxToken? GetDeclarationIdentifierIfOverride(SyntaxToken token)\n {\n if (token.Kind() == SyntaxKind.OverrideKeyword && token.Parent is MemberDeclarationSyntax member)\n {\n return member.GetNameToken();\n }\n\n return null;\n }\n\n public SyntaxList GetAttributeLists(SyntaxNode? node)\n => node.GetAttributeLists();\n\n public bool IsParameterNameXmlElementSyntax([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.XmlElement, out XmlElementSyntax? xmlElement) &&\n xmlElement.StartTag.Name.LocalName.ValueText == DocumentationCommentXmlNames.ParameterElementName;\n\n public SyntaxList GetContentFromDocumentationCommentTriviaSyntax(SyntaxTrivia trivia)\n {\n if (trivia.GetStructure() is DocumentationCommentTriviaSyntax documentationCommentTrivia)\n {\n return documentationCommentTrivia.Content;\n }\n\n throw ExceptionUtilities.UnexpectedValue(trivia.Kind());\n }\n\n public bool IsIsPatternExpression([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.IsPatternExpression);\n\n public void GetPartsOfIsPatternExpression(SyntaxNode node, out SyntaxNode left, out SyntaxToken isToken, out SyntaxNode right)\n {\n var isPatternExpression = (IsPatternExpressionSyntax)node;\n left = isPatternExpression.Expression;\n isToken = isPatternExpression.IsKeyword;\n right = isPatternExpression.Pattern;\n }\n\n public bool IsAnyPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is PatternSyntax;\n\n public bool IsConstantPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ConstantPattern);\n\n public bool IsDeclarationPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.DeclarationPattern);\n\n public bool IsRecursivePattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.RecursivePattern);\n\n public bool IsVarPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.VarPattern);\n\n public SyntaxNode GetExpressionOfConstantPattern(SyntaxNode node)\n => ((ConstantPatternSyntax)node).Expression;\n\n public void GetPartsOfDeclarationPattern(SyntaxNode node, out SyntaxNode type, out SyntaxNode designation)\n {\n var declarationPattern = (DeclarationPatternSyntax)node;\n type = declarationPattern.Type;\n designation = declarationPattern.Designation;\n }\n\n public void GetPartsOfRecursivePattern(SyntaxNode node, out SyntaxNode? type, out SyntaxNode? positionalPart, out SyntaxNode? propertyPart, out SyntaxNode? designation)\n {\n var recursivePattern = (RecursivePatternSyntax)node;\n type = recursivePattern.Type;\n positionalPart = recursivePattern.PositionalPatternClause;\n propertyPart = recursivePattern.PropertyPatternClause;\n designation = recursivePattern.Designation;\n }\n\n public bool SupportsNotPattern(ParseOptions options)\n => ((CSharpParseOptions)options).LanguageVersion.IsCSharp9OrAbove();\n\n public bool IsAndPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.AndPattern);\n\n public bool IsBinaryPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is BinaryPatternSyntax;\n\n public bool IsNotPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.NotPattern);\n\n public bool IsOrPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.OrPattern);\n\n public bool IsParenthesizedPattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.ParenthesizedPattern);\n\n public bool IsTypePattern([NotNullWhen(true)] SyntaxNode? node)\n => node.IsKind(SyntaxKind.TypePattern);\n\n public bool IsUnaryPattern([NotNullWhen(true)] SyntaxNode? node)\n => node is UnaryPatternSyntax;\n\n public void GetPartsOfParenthesizedPattern(SyntaxNode node, out SyntaxToken openParen, out SyntaxNode pattern, out SyntaxToken closeParen)\n {\n var parenthesizedPattern = (ParenthesizedPatternSyntax)node;\n openParen = parenthesizedPattern.OpenParenToken;\n pattern = parenthesizedPattern.Pattern;\n closeParen = parenthesizedPattern.CloseParenToken;\n }\n\n public void GetPartsOfBinaryPattern(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var binaryPattern = (BinaryPatternSyntax)node;\n left = binaryPattern.Left;\n operatorToken = binaryPattern.OperatorToken;\n right = binaryPattern.Right;\n }\n\n public void GetPartsOfUnaryPattern(SyntaxNode node, out SyntaxToken operatorToken, out SyntaxNode pattern)\n {\n var unaryPattern = (UnaryPatternSyntax)node;\n operatorToken = unaryPattern.OperatorToken;\n pattern = unaryPattern.Pattern;\n }\n\n public SyntaxNode GetTypeOfTypePattern(SyntaxNode node)\n => ((TypePatternSyntax)node).Type;\n\n public void GetPartsOfInterpolationExpression(SyntaxNode node,\n out SyntaxToken stringStartToken, out SyntaxList contents, out SyntaxToken stringEndToken)\n {\n var interpolatedStringExpression = (InterpolatedStringExpressionSyntax)node;\n stringStartToken = interpolatedStringExpression.StringStartToken;\n contents = interpolatedStringExpression.Contents;\n stringEndToken = interpolatedStringExpression.StringEndToken;\n }\n\n public bool IsVerbatimInterpolatedStringExpression(SyntaxNode node)\n => node is InterpolatedStringExpressionSyntax interpolatedString &&\n interpolatedString.StringStartToken.IsKind(SyntaxKind.InterpolatedVerbatimStringStartToken);\n\n #region IsXXX members\n\n public bool IsAnonymousFunctionExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is AnonymousFunctionExpressionSyntax;\n\n public bool IsBaseNamespaceDeclaration([NotNullWhen(true)] SyntaxNode? node)\n => node is BaseNamespaceDeclarationSyntax;\n\n public bool IsBinaryExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is BinaryExpressionSyntax;\n\n public bool IsLiteralExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is LiteralExpressionSyntax;\n\n public bool IsMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node)\n => node is MemberAccessExpressionSyntax;\n\n public bool IsSimpleName([NotNullWhen(true)] SyntaxNode? node)\n => node is SimpleNameSyntax;\n\n #endregion\n\n #region GetPartsOfXXX members\n\n public void GetPartsOfBinaryExpression(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var binaryExpression = (BinaryExpressionSyntax)node;\n left = binaryExpression.Left;\n operatorToken = binaryExpression.OperatorToken;\n right = binaryExpression.Right;\n }\n\n public void GetPartsOfCompilationUnit(SyntaxNode node, out SyntaxList imports, out SyntaxList attributeLists, out SyntaxList members)\n {\n var compilationUnit = (CompilationUnitSyntax)node;\n imports = compilationUnit.Usings;\n attributeLists = compilationUnit.AttributeLists;\n members = compilationUnit.Members;\n }\n\n public void GetPartsOfConditionalAccessExpression(\n SyntaxNode node, out SyntaxNode expression, out SyntaxToken operatorToken, out SyntaxNode whenNotNull)\n {\n var conditionalAccess = (ConditionalAccessExpressionSyntax)node;\n expression = conditionalAccess.Expression;\n operatorToken = conditionalAccess.OperatorToken;\n whenNotNull = conditionalAccess.WhenNotNull;\n }\n\n public void GetPartsOfConditionalExpression(SyntaxNode node, out SyntaxNode condition, out SyntaxNode whenTrue, out SyntaxNode whenFalse)\n {\n var conditionalExpression = (ConditionalExpressionSyntax)node;\n condition = conditionalExpression.Condition;\n whenTrue = conditionalExpression.WhenTrue;\n whenFalse = conditionalExpression.WhenFalse;\n }\n\n public void GetPartsOfInvocationExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxNode? argumentList)\n {\n var invocation = (InvocationExpressionSyntax)node;\n expression = invocation.Expression;\n argumentList = invocation.ArgumentList;\n }\n\n public void GetPartsOfMemberAccessExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxToken operatorToken, out SyntaxNode name)\n {\n var memberAccess = (MemberAccessExpressionSyntax)node;\n expression = memberAccess.Expression;\n operatorToken = memberAccess.OperatorToken;\n name = memberAccess.Name;\n }\n\n public void GetPartsOfBaseNamespaceDeclaration(SyntaxNode node, out SyntaxNode name, out SyntaxList imports, out SyntaxList members)\n {\n var namespaceDeclaration = (BaseNamespaceDeclarationSyntax)node;\n name = namespaceDeclaration.Name;\n imports = namespaceDeclaration.Usings;\n members = namespaceDeclaration.Members;\n }\n\n public void GetPartsOfObjectCreationExpression(SyntaxNode node, out SyntaxNode type, out SyntaxNode? argumentList, out SyntaxNode? initializer)\n {\n var objectCreationExpression = (ObjectCreationExpressionSyntax)node;\n type = objectCreationExpression.Type;\n argumentList = objectCreationExpression.ArgumentList;\n initializer = objectCreationExpression.Initializer;\n }\n\n public void GetPartsOfParenthesizedExpression(\n SyntaxNode node, out SyntaxToken openParen, out SyntaxNode expression, out SyntaxToken closeParen)\n {\n var parenthesizedExpression = (ParenthesizedExpressionSyntax)node;\n openParen = parenthesizedExpression.OpenParenToken;\n expression = parenthesizedExpression.Expression;\n closeParen = parenthesizedExpression.CloseParenToken;\n }\n\n public void GetPartsOfPrefixUnaryExpression(SyntaxNode node, out SyntaxToken operatorToken, out SyntaxNode operand)\n {\n var prefixUnaryExpression = (PrefixUnaryExpressionSyntax)node;\n operatorToken = prefixUnaryExpression.OperatorToken;\n operand = prefixUnaryExpression.Operand;\n }\n\n public void GetPartsOfQualifiedName(SyntaxNode node, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right)\n {\n var qualifiedName = (QualifiedNameSyntax)node;\n left = qualifiedName.Left;\n operatorToken = qualifiedName.DotToken;\n right = qualifiedName.Right;\n }\n\n #endregion\n\n #region GetXXXOfYYY members\n\n public SyntaxNode GetExpressionOfAwaitExpression(SyntaxNode node)\n => ((AwaitExpressionSyntax)node).Expression;\n\n public SyntaxNode GetExpressionOfThrowExpression(SyntaxNode node)\n => ((ThrowExpressionSyntax)node).Expression;\n\n #endregion\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":112,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems"},"before_content":{"kind":"string","value":"\n\n \n $(MSBuildAllProjects);$(MSBuildThisFileFullPath)\n true\n ec946164-1e17-410b-b7d9-7de7e6268d63\n \n \n Microsoft.CodeAnalysis.Shared\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Collections\\ArrayBuilderExtensions.cs\n \n \n Collections\\DictionaryExtensions.cs\n \n \n Collections\\Boxes.cs\n \n \n Collections\\OrderPreservingMultiDictionary.cs\n \n \n EncodedStringText.cs\n \n \n FileSystem\\RelativePathResolver.cs\n \n \n InternalUtilities\\AssemblyIdentityUtils.cs\n \n \n InternalUtilities\\BitArithmeticUtilities.cs\n \n \n InternalUtilities\\ArrayExtensions.cs\n \n \n InternalUtilities\\CompilerOptionParseUtilities.cs\n \n \n InternalUtilities\\ConcurrentSet.cs\n \n \n InternalUtilities\\ConsList`1.cs\n \n \n InternalUtilities\\DecimalUtilities.cs\n \n \n InternalUtilities\\DocumentationCommentXmlNames.cs\n \n \n InternalUtilities\\EncodingExtensions.cs\n \n \n InternalUtilities\\EnumUtilties.cs\n \n \n InternalUtilities\\FailFast.cs\n \n \n InternalUtilities\\FatalError.cs\n \n \n InternalUtilities\\FileNameUtilities.cs\n \n \n InternalUtilities\\ImmutableListExtensions.cs\n \n \n InternalUtilities\\Index.cs\n \n \n InternalUtilities\\ISetExtensions.cs\n \n \n InternalUtilities\\MultiDictionary.cs\n \n \n InternalUtilities\\OrderedMultiDictionary.cs\n \n \n InternalUtilities\\SetWithInsertionOrder.cs\n \n \n FileSystem\\PathKind.cs\n \n \n InternalUtilities\\OneOrMany.cs\n \n \n InternalUtilities\\PerformanceSensitiveAttribute.cs\n \n \n InternalUtilities\\PlatformInformation.cs\n \n \n InternalUtilities\\Range.cs\n \n \n InternalUtilities\\ReaderWriterLockSlimExtensions.cs\n \n \n InternalUtilities\\SemaphoreSlimExtensions.cs\n \n \n InternalUtilities\\StackGuard.cs\n \n \n InternalUtilities\\StreamExtensions.cs\n \n \n \n InternalUtilities\\TextChangeRangeExtensions.cs\n \n \n InternalUtilities\\WeakReferenceExtensions.cs\n \n \n FileSystem\\FileUtilities.cs\n \n \n FileSystem\\PathUtilities.cs\n \n \n InternalUtilities\\ReflectionUtilities.cs\n \n \n InternalUtilities\\UnicodeCharacterUtilities.cs\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"},"after_content":{"kind":"string","value":"\n\n \n $(MSBuildAllProjects);$(MSBuildThisFileFullPath)\n true\n ec946164-1e17-410b-b7d9-7de7e6268d63\n \n \n Microsoft.CodeAnalysis.Shared\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Collections\\ArrayBuilderExtensions.cs\n \n \n Collections\\DictionaryExtensions.cs\n \n \n Collections\\Boxes.cs\n \n \n Collections\\OrderPreservingMultiDictionary.cs\n \n \n EncodedStringText.cs\n \n \n FileSystem\\RelativePathResolver.cs\n \n \n InternalUtilities\\AssemblyIdentityUtils.cs\n \n \n InternalUtilities\\BitArithmeticUtilities.cs\n \n \n InternalUtilities\\ArrayExtensions.cs\n \n \n InternalUtilities\\CompilerOptionParseUtilities.cs\n \n \n InternalUtilities\\ConcurrentSet.cs\n \n \n InternalUtilities\\ConsList`1.cs\n \n \n InternalUtilities\\DecimalUtilities.cs\n \n \n InternalUtilities\\DocumentationCommentXmlNames.cs\n \n \n InternalUtilities\\EncodingExtensions.cs\n \n \n InternalUtilities\\EnumUtilties.cs\n \n \n InternalUtilities\\FailFast.cs\n \n \n InternalUtilities\\FatalError.cs\n \n \n InternalUtilities\\FileNameUtilities.cs\n \n \n InternalUtilities\\ImmutableListExtensions.cs\n \n \n InternalUtilities\\Index.cs\n \n \n InternalUtilities\\ISetExtensions.cs\n \n \n InternalUtilities\\MultiDictionary.cs\n \n \n InternalUtilities\\OrderedMultiDictionary.cs\n \n \n InternalUtilities\\SetWithInsertionOrder.cs\n \n \n FileSystem\\PathKind.cs\n \n \n InternalUtilities\\OneOrMany.cs\n \n \n InternalUtilities\\PerformanceSensitiveAttribute.cs\n \n \n InternalUtilities\\PlatformInformation.cs\n \n \n InternalUtilities\\Range.cs\n \n \n InternalUtilities\\ReaderWriterLockSlimExtensions.cs\n \n \n InternalUtilities\\SemaphoreSlimExtensions.cs\n \n \n InternalUtilities\\StackGuard.cs\n \n \n InternalUtilities\\StreamExtensions.cs\n \n \n \n InternalUtilities\\TextChangeRangeExtensions.cs\n \n \n InternalUtilities\\WeakReferenceExtensions.cs\n \n \n FileSystem\\FileUtilities.cs\n \n \n FileSystem\\PathUtilities.cs\n \n \n InternalUtilities\\ReflectionUtilities.cs\n \n \n InternalUtilities\\UnicodeCharacterUtilities.cs\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":113,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56491,"string":"56,491"},"pr_title":{"kind":"string","value":"Make method extensions"},"pr_description":{"kind":"string","value":"No need for these to be instance methods on ABstractSyntaxFacts"},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-17T20:59:25Z","string":"2021-09-17T20:59:25Z"},"date_merged":{"kind":"timestamp","value":"2021-09-18T00:30:21Z","string":"2021-09-18T00:30:21Z"},"previous_commit":{"kind":"string","value":"a73ef13d7f21ca65c1fc85fa6c6cbde0d075c45d"},"pr_commit":{"kind":"string","value":"b7d780dba0b1fbe63215bb4ec7c253a5a469d7b6"},"query":{"kind":"string","value":"Make method extensions. No need for these to be instance methods on ABstractSyntaxFacts"},"filepath":{"kind":"string","value":"./src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.Text;\n\n#if CODE_STYLE\nusing Microsoft.CodeAnalysis.Internal.Editing;\n#else\nusing Microsoft.CodeAnalysis.Editing;\n#endif\n\nnamespace Microsoft.CodeAnalysis.LanguageServices\n{\n /// \n /// Contains helpers to allow features and other algorithms to run over C# and Visual Basic code in a uniform fashion.\n /// It should be thought of a generalized way to apply type-pattern-matching and syntax-deconstruction in a uniform\n /// fashion over the languages. Helpers in this type should only be one of the following forms:\n /// \n /// \n /// 'IsXXX' where 'XXX' exactly matches one of the same named syntax (node, token, trivia, list, etc.) constructs that \n /// both C# and VB have. For example 'IsSimpleName' to correspond to C# and VB's SimpleNameSyntax node. These 'checking' \n /// methods should never fail. For non leaf node types this should be implemented as a typecheck ('is' in C#, 'typeof ... is'\n /// in VB). For leaf nodes, this should be implemented by deffering to to check against the \n /// raw kind of the node.\n /// \n /// \n /// 'GetPartsOfXXX(SyntaxNode node, out SyntaxNode/SyntaxToken part1, ...)' where 'XXX' one of the same named Syntax constructs\n /// that both C# and VB have, and where the returned parts correspond to the members those nodes have in common across the \n /// languages. For example 'GetPartsOfQualifiedName(SyntaxNode node, out SyntaxNode left, out SyntaxToken dotToken, out SyntaxNode right)'\n /// VB. These functions should throw if passed a node that the corresponding 'IsXXX' did not return for.\n /// For nodes that only have a single child, 'GetPartsOfXXX' is not not needed and can be replaced with the easier to use\n /// 'GetXXXOfYYY' to get that single child.\n /// \n /// \n /// 'GetXxxOfYYY' where 'XXX' matches the name of a property on a 'YYY' syntax construct that both C# and VB have. For\n /// example 'GetExpressionOfMemberAccessExpression' corresponding to MemberAccessExpressionsyntax.Expression in both C# and\n /// VB. These functions should throw if passed a node that the corresponding 'IsYYY' did not return for.\n /// For nodes that only have a single child, these functions can stay here. For nodes with multiple children, these should migrate\n /// to and be built off of 'GetPartsOfXXX'.\n /// \n /// \n /// Absolutely trivial questions that relate to syntax and can be asked sensibly of each language. For example,\n /// if certain constructs (like 'patterns') are supported in that language or not.\n /// \n /// \n ///\n /// Importantly, avoid:\n ///\n /// \n /// \n /// Functions that attempt to blur the lines between similar constructs in the same language. For example, a QualifiedName\n /// is not the same as a MemberAccessExpression (despite A.B being representable as either depending on context). \n /// Features that need to handle both should make it clear that they are doing so, showing that they're doing the right\n /// thing for the contexts each can arise in (for the above example in 'type' vs 'expression' contexts).\n /// \n /// \n /// Functions which are effectively specific to a single feature are are just trying to find a place to place complex\n /// feature logic in a place such that it can run over VB or C#. For example, a function to determine if a position\n /// is on the 'header' of a node. a 'header' is a not a well defined syntax concept that can be trivially asked of\n /// nodes in either language. It is an excapsulation of a feature (or set of features) level idea that should be in\n /// its own dedicated service.\n /// \n /// \n /// Functions that mutate or update syntax constructs for example 'WithXXX'. These should be on SyntaxGenerator or\n /// some other feature specific service.\n /// \n /// \n /// Functions that a single item when one language may allow for multiple. For example 'GetIdentifierOfVariableDeclarator'.\n /// In VB a VariableDeclarator can itself have several names, so calling code must be written to check for that and handle\n /// it apropriately. Functions like this make it seem like that doesn't need to be considered, easily allowing for bugs\n /// to creep in.\n /// \n /// \n /// Abbreviating or otherwise changing the names that C# and VB share here. For example use 'ObjectCreationExpression'\n /// not 'ObjectCreation'. This prevents accidental duplication and keeps consistency with all members.\n /// \n /// \n /// \n /// \n /// Many helpers in this type currently violate the above 'dos' and 'do nots'. They should be removed and either \n /// inlined directly into the feature that needs if (if only a single feature), or moved into a dedicated service\n /// for that purpose if needed by multiple features.\n /// \n internal interface ISyntaxFacts\n {\n bool IsCaseSensitive { get; }\n StringComparer StringComparer { get; }\n\n SyntaxTrivia ElasticMarker { get; }\n SyntaxTrivia ElasticCarriageReturnLineFeed { get; }\n\n ISyntaxKinds SyntaxKinds { get; }\n\n bool SupportsIndexingInitializer(ParseOptions options);\n bool SupportsLocalFunctionDeclaration(ParseOptions options);\n bool SupportsNotPattern(ParseOptions options);\n bool SupportsRecord(ParseOptions options);\n bool SupportsRecordStruct(ParseOptions options);\n bool SupportsThrowExpression(ParseOptions options);\n\n SyntaxToken ParseToken(string text);\n SyntaxTriviaList ParseLeadingTrivia(string text);\n string EscapeIdentifier(string identifier);\n bool IsVerbatimIdentifier(SyntaxToken token);\n bool IsOperator(SyntaxToken token);\n bool IsPredefinedType(SyntaxToken token);\n bool IsPredefinedType(SyntaxToken token, PredefinedType type);\n bool IsPredefinedOperator(SyntaxToken token);\n bool IsPredefinedOperator(SyntaxToken token, PredefinedOperator op);\n\n /// \n /// Returns 'true' if this a 'reserved' keyword for the language. A 'reserved' keyword is a\n /// identifier that is always treated as being a special keyword, regardless of where it is\n /// found in the token stream. Examples of this are tokens like and\n /// in C# and VB respectively.\n ///\n /// Importantly, this does *not* include contextual keywords. If contextual keywords are\n /// important for your scenario, use or . Also, consider using\n /// if all you need is the ability to know\n /// if this is effectively any identifier in the language, regardless of whether the language\n /// is treating it as a keyword or not.\n /// \n bool IsReservedKeyword(SyntaxToken token);\n\n /// \n /// Returns if this a 'contextual' keyword for the language. A\n /// 'contextual' keyword is a identifier that is only treated as being a special keyword in\n /// certain *syntactic* contexts. Examples of this is 'yield' in C#. This is only a\n /// keyword if used as 'yield return' or 'yield break'. Importantly, identifiers like , and are *not*\n /// 'contextual' keywords. This is because they are not treated as keywords depending on\n /// the syntactic context around them. Instead, the language always treats them identifiers\n /// that have special *semantic* meaning if they end up not binding to an existing symbol.\n ///\n /// Importantly, if is not in the syntactic construct where the\n /// language thinks an identifier should be contextually treated as a keyword, then this\n /// will return .\n ///\n /// Or, in other words, the parser must be able to identify these cases in order to be a\n /// contextual keyword. If identification happens afterwards, it's not contextual.\n /// \n bool IsContextualKeyword(SyntaxToken token);\n\n /// \n /// The set of identifiers that have special meaning directly after the `#` token in a\n /// preprocessor directive. For example `if` or `pragma`.\n /// \n bool IsPreprocessorKeyword(SyntaxToken token);\n bool IsPreProcessorDirectiveContext(SyntaxTree syntaxTree, int position, CancellationToken cancellationToken);\n\n bool IsLiteral(SyntaxToken token);\n bool IsStringLiteralOrInterpolatedStringLiteral(SyntaxToken token);\n\n bool IsNumericLiteral(SyntaxToken token);\n bool IsVerbatimStringLiteral(SyntaxToken token);\n\n bool IsUsingOrExternOrImport([NotNullWhen(true)] SyntaxNode? node);\n bool IsGlobalAssemblyAttribute([NotNullWhen(true)] SyntaxNode? node);\n bool IsGlobalModuleAttribute([NotNullWhen(true)] SyntaxNode? node);\n bool IsDeclaration(SyntaxNode node);\n bool IsTypeDeclaration(SyntaxNode node);\n\n bool IsUsingAliasDirective([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsRegularComment(SyntaxTrivia trivia);\n bool IsDocumentationComment(SyntaxTrivia trivia);\n bool IsElastic(SyntaxTrivia trivia);\n bool IsPragmaDirective(SyntaxTrivia trivia, out bool isDisable, out bool isActive, out SeparatedSyntaxList errorCodes);\n\n bool IsSingleLineCommentTrivia(SyntaxTrivia trivia);\n bool IsMultiLineCommentTrivia(SyntaxTrivia trivia);\n bool IsSingleLineDocCommentTrivia(SyntaxTrivia trivia);\n bool IsMultiLineDocCommentTrivia(SyntaxTrivia trivia);\n bool IsShebangDirectiveTrivia(SyntaxTrivia trivia);\n bool IsPreprocessorDirective(SyntaxTrivia trivia);\n\n bool IsDocumentationComment(SyntaxNode node);\n\n string GetText(int kind);\n bool IsEntirelyWithinStringOrCharOrNumericLiteral([NotNullWhen(true)] SyntaxTree? syntaxTree, int position, CancellationToken cancellationToken);\n\n bool TryGetPredefinedType(SyntaxToken token, out PredefinedType type);\n bool TryGetPredefinedOperator(SyntaxToken token, out PredefinedOperator op);\n bool TryGetExternalSourceInfo([NotNullWhen(true)] SyntaxNode? directive, out ExternalSourceInfo info);\n\n bool IsDeclarationExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsIsExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsIsPatternExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsConversionExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsCastExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsExpressionOfForeach([NotNullWhen(true)] SyntaxNode? node);\n\n void GetPartsOfTupleExpression(SyntaxNode node,\n out SyntaxToken openParen, out SeparatedSyntaxList arguments, out SyntaxToken closeParen) where TArgumentSyntax : SyntaxNode;\n\n void GetPartsOfInterpolationExpression(SyntaxNode node,\n out SyntaxToken stringStartToken, out SyntaxList contents, out SyntaxToken stringEndToken);\n\n bool IsVerbatimInterpolatedStringExpression(SyntaxNode node);\n\n // Left side of = assignment.\n bool IsLeftSideOfAssignment([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsSimpleAssignmentStatement([NotNullWhen(true)] SyntaxNode? statement);\n void GetPartsOfAssignmentStatement(SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right);\n void GetPartsOfAssignmentExpressionOrStatement(SyntaxNode statement, out SyntaxNode left, out SyntaxToken operatorToken, out SyntaxNode right);\n\n // Left side of any assignment (for example = or ??= or *= or += )\n bool IsLeftSideOfAnyAssignment([NotNullWhen(true)] SyntaxNode? node);\n // Left side of compound assignment (for example ??= or *= or += )\n bool IsLeftSideOfCompoundAssignment([NotNullWhen(true)] SyntaxNode? node);\n SyntaxNode GetRightHandSideOfAssignment(SyntaxNode node);\n\n bool IsInferredAnonymousObjectMemberDeclarator([NotNullWhen(true)] SyntaxNode? node);\n bool IsOperandOfIncrementExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsOperandOfIncrementOrDecrementExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsLeftSideOfDot([NotNullWhen(true)] SyntaxNode? node);\n SyntaxNode? GetRightSideOfDot(SyntaxNode? node);\n\n /// \n /// Get the node on the left side of the dot if given a dotted expression.\n /// \n /// \n /// In VB, we have a member access expression with a null expression, this may be one of the\n /// following forms:\n /// 1) new With { .a = 1, .b = .a .a refers to the anonymous type\n /// 2) With obj : .m .m refers to the obj type\n /// 3) new T() With { .a = 1, .b = .a 'a refers to the T type\n /// If `allowImplicitTarget` is set to true, the returned node will be set to approperiate node, otherwise, it will return null.\n /// This parameter has no affect on C# node.\n /// \n SyntaxNode? GetLeftSideOfDot(SyntaxNode? node, bool allowImplicitTarget = false);\n\n bool IsLeftSideOfExplicitInterfaceSpecifier([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsNameOfSimpleMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsNameOfAnyMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsNameOfMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node);\n\n /// \n /// Gets the containing expression that is actually a language expression and not just typed\n /// as an ExpressionSyntax for convenience. For example, NameSyntax nodes on the right side\n /// of qualified names and member access expressions are not language expressions, yet the\n /// containing qualified names or member access expressions are indeed expressions.\n /// \n [return: NotNullIfNotNull(\"node\")]\n SyntaxNode? GetStandaloneExpression(SyntaxNode? node);\n\n /// \n /// Call on the `.y` part of a `x?.y` to get the entire `x?.y` conditional access expression. This also works\n /// when there are multiple chained conditional accesses. For example, calling this on '.y' or '.z' in\n /// `x?.y?.z` will both return the full `x?.y?.z` node. This can be used to effectively get 'out' of the RHS of\n /// a conditional access, and commonly represents the full standalone expression that can be operated on\n /// atomically.\n /// \n SyntaxNode? GetRootConditionalAccessExpression(SyntaxNode? node);\n\n /// \n /// Returns the expression node the member is being accessed off of. If \n /// is , this will be the node directly to the left of the dot-token. If \n /// is , then this can return another node in the tree that the member will be accessed\n /// off of. For example, in VB, if you have a member-access-expression of the form \".Length\" then this\n /// may return the expression in the surrounding With-statement.\n /// \n SyntaxNode? GetExpressionOfMemberAccessExpression(SyntaxNode node, bool allowImplicitTarget = false);\n\n SyntaxNode? GetTargetOfMemberBinding(SyntaxNode? node);\n\n SyntaxNode GetNameOfMemberBindingExpression(SyntaxNode node);\n\n bool IsPointerMemberAccessExpression([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsNamedArgument([NotNullWhen(true)] SyntaxNode? node);\n bool IsNameOfNamedArgument([NotNullWhen(true)] SyntaxNode? node);\n SyntaxToken? GetNameOfParameter([NotNullWhen(true)] SyntaxNode? node);\n SyntaxNode? GetDefaultOfParameter(SyntaxNode node);\n SyntaxNode? GetParameterList(SyntaxNode node);\n bool IsParameterList([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsDocumentationCommentExteriorTrivia(SyntaxTrivia trivia);\n\n void GetPartsOfElementAccessExpression(SyntaxNode node, out SyntaxNode expression, out SyntaxNode argumentList);\n\n SyntaxNode GetExpressionOfArgument(SyntaxNode node);\n SyntaxNode GetExpressionOfInterpolation(SyntaxNode node);\n SyntaxNode GetNameOfAttribute(SyntaxNode node);\n\n bool IsMemberBindingExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsPostfixUnaryExpression([NotNullWhen(true)] SyntaxNode? node);\n\n SyntaxToken GetIdentifierOfGenericName(SyntaxNode node);\n SyntaxToken GetIdentifierOfSimpleName(SyntaxNode node);\n SyntaxToken GetIdentifierOfParameter(SyntaxNode node);\n SyntaxToken GetIdentifierOfTypeDeclaration(SyntaxNode node);\n SyntaxToken GetIdentifierOfVariableDeclarator(SyntaxNode node);\n SyntaxToken GetIdentifierOfIdentifierName(SyntaxNode node);\n SyntaxNode GetTypeOfVariableDeclarator(SyntaxNode node);\n\n /// \n /// True if this is an argument with just an expression and nothing else (i.e. no ref/out,\n /// no named params, no omitted args).\n /// \n bool IsSimpleArgument([NotNullWhen(true)] SyntaxNode? node);\n bool IsArgument([NotNullWhen(true)] SyntaxNode? node);\n RefKind GetRefKindOfArgument(SyntaxNode node);\n\n void GetNameAndArityOfSimpleName(SyntaxNode node, out string name, out int arity);\n bool LooksGeneric(SyntaxNode simpleName);\n\n SyntaxList GetContentsOfInterpolatedString(SyntaxNode interpolatedString);\n\n SeparatedSyntaxList GetArgumentsOfInvocationExpression(SyntaxNode node);\n SeparatedSyntaxList GetArgumentsOfObjectCreationExpression(SyntaxNode node);\n SeparatedSyntaxList GetArgumentsOfArgumentList(SyntaxNode node);\n\n bool IsUsingDirectiveName([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsAttributeName(SyntaxNode node);\n // Violation. Doesn't correspond to any shared structure for vb/c#\n SyntaxList GetAttributeLists(SyntaxNode? node);\n\n bool IsAttributeNamedArgumentIdentifier([NotNullWhen(true)] SyntaxNode? node);\n bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node);\n bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance);\n\n bool IsDirective([NotNullWhen(true)] SyntaxNode? node);\n bool IsStatement([NotNullWhen(true)] SyntaxNode? node);\n bool IsExecutableStatement([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsDeconstructionAssignment([NotNullWhen(true)] SyntaxNode? node);\n bool IsDeconstructionForEachStatement([NotNullWhen(true)] SyntaxNode? node);\n\n /// \n /// Returns true for nodes that represent the body of a method.\n ///\n /// For VB this will be\n /// MethodBlockBaseSyntax. This will be true for things like constructor, method, operator\n /// bodies as well as accessor bodies. It will not be true for things like sub() function()\n /// lambdas.\n ///\n /// For C# this will be the BlockSyntax or ArrowExpressionSyntax for a\n /// method/constructor/deconstructor/operator/accessor. It will not be included for local\n /// functions.\n /// \n bool IsMethodBody([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsDeclaratorOfLocalDeclarationStatement(SyntaxNode declarator, SyntaxNode localDeclarationStatement);\n SeparatedSyntaxList GetVariablesOfLocalDeclarationStatement(SyntaxNode node);\n SyntaxNode? GetInitializerOfVariableDeclarator(SyntaxNode node);\n\n bool IsThisConstructorInitializer(SyntaxToken token);\n bool IsBaseConstructorInitializer(SyntaxToken token);\n bool IsQueryKeyword(SyntaxToken token);\n bool IsElementAccessExpression([NotNullWhen(true)] SyntaxNode? node);\n bool IsIndexerMemberCRef([NotNullWhen(true)] SyntaxNode? node);\n bool IsIdentifierStartCharacter(char c);\n bool IsIdentifierPartCharacter(char c);\n bool IsIdentifierEscapeCharacter(char c);\n bool IsStartOfUnicodeEscapeSequence(char c);\n\n bool IsValidIdentifier(string identifier);\n bool IsVerbatimIdentifier(string identifier);\n\n /// \n /// Returns true if the given character is a character which may be included in an\n /// identifier to specify the type of a variable.\n /// \n bool IsTypeCharacter(char c);\n\n // Violation. This is a feature level API for QuickInfo.\n bool IsBindableToken(SyntaxToken token);\n\n bool IsInStaticContext(SyntaxNode node);\n bool IsUnsafeContext(SyntaxNode node);\n\n bool IsInNamespaceOrTypeContext([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsBaseTypeList([NotNullWhen(true)] SyntaxNode? node);\n\n bool IsInConstantContext([NotNullWhen(true)] SyntaxNode? node);\n bool IsInConstructor(SyntaxNode node);\n bool IsMethodLevelMember([NotNullWhen(true)] SyntaxNode? node);\n bool IsTopLevelNodeWithMembers([NotNullWhen(true)] SyntaxNode? node);\n bool HasIncompleteParentMember([NotNullWhen(true)] SyntaxNode? node);\n\n /// \n /// A block that has no semantics other than introducing a new scope. That is only C# BlockSyntax.\n /// \n bool IsScopeBlock([NotNullWhen(true)] SyntaxNode? node);\n\n /// \n /// A node that contains a list of statements. In C#, this is BlockSyntax and SwitchSectionSyntax.\n /// In VB, this includes all block statements such as a MultiLineIfBlockSyntax.\n /// \n bool IsExecutableBlock([NotNullWhen(true)] SyntaxNode? node);\n // Violation. This should return a SyntaxList\n IReadOnlyList GetExecutableBlockStatements(SyntaxNode? node);\n // Violation. This is a feature level API.\n SyntaxNode? FindInnermostCommonExecutableBlock(IEnumerable nodes);\n\n /// \n /// A node that can host a list of statements or a single statement. In addition to\n /// every \"executable block\", this also includes C# embedded statement owners.\n /// \n // Violation. This is a feature level API.\n bool IsStatementContainer([NotNullWhen(true)] SyntaxNode? node);\n\n // Violation. This is a feature level API.\n IReadOnlyList GetStatementContainerStatements(SyntaxNode? node);\n\n bool AreEquivalent(SyntaxToken token1, SyntaxToken token2);\n bool AreEquivalent(SyntaxNode? node1, SyntaxNode? node2);\n\n string GetDisplayName(SyntaxNode? node, DisplayNameOptions options, string? rootNamespace = null);\n\n // Violation. This is a feature level API. How 'position' relates to 'containment' is not defined.\n SyntaxNode? GetContainingTypeDeclaration(SyntaxNode? root, int position);\n SyntaxNode? GetContainingMemberDeclaration(SyntaxNode? root, int position, bool useFullSpan = true);\n SyntaxNode? GetContainingVariableDeclaratorOfFieldDeclaration(SyntaxNode? node);\n\n [return: NotNullIfNotNull(\"node\")]\n SyntaxNode? WalkDownParentheses(SyntaxNode? node);\n\n // Violation. This is a feature level API.\n [return: NotNullIfNotNull(\"node\")]\n SyntaxNode? ConvertToSingleLine(SyntaxNode? node, bool useElasticTrivia = false);\n\n // Violation. This is a feature level API.\n List GetTopLevelAndMethodLevelMembers(SyntaxNode? root);\n // Violation. This is a feature level API.\n List GetMethodLevelMembers(SyntaxNode? root);\n SyntaxList GetMembersOfTypeDeclaration(SyntaxNode typeDeclaration);\n\n // Violation. This is a feature level API.\n bool ContainsInMemberBody([NotNullWhen(true)] SyntaxNode? node, TextSpan span);\n // Violation. This is a feature level API.\n TextSpan GetInactiveRegionSpanAroundPosition(SyntaxTree tree, int position, CancellationToken cancellationToken);\n\n /// \n /// Given a , return the