From 38bf120e341b618ab4bbe379e72c4a0c0220fd0f Mon Sep 17 00:00:00 2001 From: Lavanya Date: Thu, 8 Aug 2019 17:47:28 -0700 Subject: [PATCH] Addressed syntax changes, extra new lines, and made appropriate naming changes --- .../MakeLocalFunctionStaticService.cs | 27 ++++++++----------- ...tlyInLocalStaticFunctionCodeFixProvider.cs | 4 --- .../Portable/FeaturesResources.Designer.cs | 2 +- .../Core/Portable/FeaturesResources.resx | 2 +- .../Portable/xlf/FeaturesResources.cs.xlf | 4 +-- .../Portable/xlf/FeaturesResources.de.xlf | 4 +-- .../Portable/xlf/FeaturesResources.es.xlf | 4 +-- .../Portable/xlf/FeaturesResources.fr.xlf | 4 +-- .../Portable/xlf/FeaturesResources.it.xlf | 4 +-- .../Portable/xlf/FeaturesResources.ja.xlf | 4 +-- .../Portable/xlf/FeaturesResources.ko.xlf | 4 +-- .../Portable/xlf/FeaturesResources.pl.xlf | 4 +-- .../Portable/xlf/FeaturesResources.pt-BR.xlf | 4 +-- .../Portable/xlf/FeaturesResources.ru.xlf | 4 +-- .../Portable/xlf/FeaturesResources.tr.xlf | 4 +-- .../xlf/FeaturesResources.zh-Hans.xlf | 4 +-- .../xlf/FeaturesResources.zh-Hant.xlf | 4 +-- .../CSharpCodeGenerationService.cs | 10 +++---- 18 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticService.cs b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticService.cs index ed70311c094..b48033c071b 100644 --- a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticService.cs +++ b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticService.cs @@ -23,14 +23,13 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic [ExportLanguageService(typeof(MakeLocalFunctionStaticService), LanguageNames.CSharp)] internal sealed class MakeLocalFunctionStaticService : ILanguageService { - private static readonly char[] s_underscore = { '_' }; private readonly SyntaxGenerator s_generator = CSharpSyntaxGenerator.Instance; - internal async Task CreateParameterSymbolAsync(Document document, LocalFunctionStatementSyntax localfunction, CancellationToken cancellationToken) + internal async Task CreateParameterSymbolAsync(Document document, LocalFunctionStatementSyntax localFunction, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(true); - var localFunctionSymbol = semanticModel.GetDeclaredSymbol(localfunction, cancellationToken); - var dataFlow = semanticModel.AnalyzeDataFlow(localfunction); + var localFunctionSymbol = semanticModel.GetDeclaredSymbol(localFunction, cancellationToken); + var dataFlow = semanticModel.AnalyzeDataFlow(localFunction); var captures = dataFlow.CapturedInside; var parameters = CreateParameterSymbol(captures); @@ -42,7 +41,6 @@ internal async Task CreateParameterSymbolAsync(Document document, Loca var rootOne = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var editor = new SyntaxEditor(rootOne, s_generator); - foreach (var referenceSymbol in arrayNode) { foreach (var location in referenceSymbol.Locations) @@ -50,7 +48,6 @@ internal async Task CreateParameterSymbolAsync(Document document, Loca var root = await location.Document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var syntaxNode = root.FindNode(location.Location.SourceSpan); //Node for the identifier syntax - var invocation = (syntaxNode as IdentifierNameSyntax).Parent as InvocationExpressionSyntax; if (invocation == null) { @@ -58,31 +55,30 @@ internal async Task CreateParameterSymbolAsync(Document document, Loca } var argList = invocation.ArgumentList; - List x = new List(); + List paramList = new List(); foreach (var parameter in parameters) { - var newArgument = GenerateArgument(parameter, parameter.Name, false); - x.Add(newArgument as ArgumentSyntax); + paramList.Add(newArgument as ArgumentSyntax); } - - var newArgList = argList.WithArguments(argList.Arguments.AddRange(x)); + var newArgList = argList.WithArguments(argList.Arguments.AddRange(paramList)); var newInvocation = invocation.WithArgumentList(newArgList); editor.ReplaceNode(invocation, newInvocation); } } + //Updates the declaration with the variables passed in - var newLF = CodeGenerator.AddParameterDeclarations(localfunction, parameters, workspace); + var updatedLocalFunction = CodeGenerator.AddParameterDeclarations(localFunction, parameters, workspace); //Adds the modifier static var modifiers = DeclarationModifiers.From(localFunctionSymbol).WithIsStatic(true); - var LFWithStatic = s_generator.WithModifiers(newLF, modifiers); + var localFunctionWithStatic = s_generator.WithModifiers(updatedLocalFunction, modifiers); - editor.ReplaceNode(localfunction, LFWithStatic); + editor.ReplaceNode(localFunction, localFunctionWithStatic); var newRoot = editor.GetChangedRoot(); var newDocument = document.WithSyntaxRoot(newRoot); @@ -102,12 +98,11 @@ static ImmutableArray CreateParameterSymbol(ImmutableArray FixableDiagnosticIds => ImmutableArray.Create("CS8421"); - public sealed override FixAllProvider GetFixAllProvider() { // See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers @@ -42,14 +41,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var document = context.Document; var cancellationToken = context.CancellationToken; - var service = document.GetLanguageService(); - context.RegisterCodeFix( new MyCodeAction(c => service.CreateParameterSymbolAsync(context.Document, declaration, c)), diagnostic); - } private class MyCodeAction : CodeAction.DocumentChangeAction diff --git a/src/Features/Core/Portable/FeaturesResources.Designer.cs b/src/Features/Core/Portable/FeaturesResources.Designer.cs index 27cf10036e4..c6f8b516436 100644 --- a/src/Features/Core/Portable/FeaturesResources.Designer.cs +++ b/src/Features/Core/Portable/FeaturesResources.Designer.cs @@ -2975,7 +2975,7 @@ internal class FeaturesResources { } /// - /// Passes in local variables explicitly in a static local function. + /// Looks up a localized string similar to Pass in local variables explicitly in a static local function. /// internal static string Pass_variable_explicitly_in_local_static_function { get { diff --git a/src/Features/Core/Portable/FeaturesResources.resx b/src/Features/Core/Portable/FeaturesResources.resx index c7418b75059..44d5da5258c 100644 --- a/src/Features/Core/Portable/FeaturesResources.resx +++ b/src/Features/Core/Portable/FeaturesResources.resx @@ -1694,6 +1694,6 @@ This version used in: {2} Warning: Semantics may change when converting statement. - Passes in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function \ No newline at end of file diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf index e799e3da6cd..7c10d3457f3 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf index 80da381796f..b64db1593f4 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf index 9fa48d9b8e2..df1b0befeba 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf index 0ebd7935acd..a20011fbcee 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf index d75fa39c328..38539d518d1 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf index eb95ece5ace..bedd5e89066 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf index 2c60be43367..d87b5fbe184 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf index 8479b7d4811..6e117a34e40 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf index ae5da27e662..cebaea564b7 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf index c808ae3b62b..14358b1f5c3 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf index d3d012ce66d..188b295b4cb 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf index 2f54c6b7697..e64d19ed2a0 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf index ea3be1e1dc9..ab9b64e8663 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf @@ -318,8 +318,8 @@ - Pass_variable_explicitly_in_local_static_function - Pass_variable_explicitly_in_local_static_function + Pass in local variables explicitly in a static local function + Pass in local variables explicitly in a static local function diff --git a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs index b699fbb0f34..685921d0465 100644 --- a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs +++ b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs @@ -272,17 +272,17 @@ protected override TDeclarationNode AddNamespace(TDeclarationN } public override TDeclarationNode AddParameters( - TDeclarationNode destinationMember, + TDeclarationNode destination, IEnumerable parameters, CodeGenerationOptions options, CancellationToken cancellationToken) { - var s_generator = CSharpSyntaxGenerator.Instance; - var currentParameterList = s_generator.GetParameters(destinationMember); + var syntaxGenerator = CSharpSyntaxGenerator.Instance; + var currentParameterList = syntaxGenerator.GetParameters(destination); if (currentParameterList == null) { - return destinationMember; + return destination; } var currentParamsCount = currentParameterList.Count; @@ -300,7 +300,7 @@ protected override TDeclarationNode AddNamespace(TDeclarationN } - var finalMember = s_generator.AddParameters(destinationMember, newParams); + var finalMember = syntaxGenerator.AddParameters(destination, newParams.ToImmutableAndFree()); return Cast(finalMember); } -- GitLab