Skip to content

Commit

Permalink
Merge pull request #22314 from MaStr11/AddParameterCodeFixForMethod
Browse files Browse the repository at this point in the history
AddParameterCodeFixProvider: Add support for method invocations.
  • Loading branch information
sharwell authored Jun 11, 2018
2 parents a685dfa + 0da7044 commit 5665268
Show file tree
Hide file tree
Showing 28 changed files with 3,196 additions and 101 deletions.
1,822 changes: 1,822 additions & 0 deletions src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs

Large diffs are not rendered by default.

623 changes: 623 additions & 0 deletions src/EditorFeatures/VisualBasicTest/AddParameter/AddParameterTests.vb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.AddParameter;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.GenerateConstructor;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.CSharp.AddParameter
{
Expand All @@ -20,10 +20,24 @@ internal class CSharpAddParameterCodeFixProvider : AbstractAddParameterCodeFixPr
InvocationExpressionSyntax,
ObjectCreationExpressionSyntax>
{
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
GenerateConstructorDiagnosticIds.AllDiagnosticIds;

protected override ImmutableArray<string> TooManyArgumentsDiagnosticIds { get; } =
GenerateConstructorDiagnosticIds.TooManyArgumentsDiagnosticIds;
private const string CS1501 = nameof(CS1501); // error CS1501: No overload for method 'M' takes 1 arguments
private const string CS1503 = nameof(CS1503); // error CS1503: Argument 1: cannot convert from 'double' to 'int'
private const string CS1660 = nameof(CS1660); // error CS1660: Cannot convert lambda expression to type 'string[]' because it is not a delegate type
private const string CS1729 = nameof(CS1729); // error CS1729: 'C' does not contain a constructor that takes n arguments
private const string CS1739 = nameof(CS1739); // error CS1739: The best overload for 'M' does not have a parameter named 'x'

private static readonly ImmutableArray<string> AddParameterFixableDiagnosticIds = ImmutableArray.Create(
CS1501, CS1503, CS1660, CS1729, CS1739,
IDEDiagnosticIds.UnboundConstructorId);

public override ImmutableArray<string> FixableDiagnosticIds
=> AddParameterFixableDiagnosticIds;

protected override ImmutableArray<string> TooManyArgumentsDiagnosticIds
=> GenerateConstructorDiagnosticIds.TooManyArgumentsDiagnosticIds;

protected override ImmutableArray<string> CannotConvertDiagnosticIds
=> GenerateConstructorDiagnosticIds.CannotConvertDiagnosticIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal static class GenerateMethodDiagnosticIds
[ExtensionOrder(After = PredefinedCodeFixProviderNames.GenerateEnumMember, Before = PredefinedCodeFixProviderNames.PopulateSwitch)]
internal class GenerateMethodCodeFixProvider : AbstractGenerateMemberCodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
GenerateMethodDiagnosticIds.FixableDiagnosticIds;

protected override bool IsCandidate(SyntaxNode node, SyntaxToken token, Diagnostic diagnostic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ internal static class GenerateConstructorDiagnosticIds
public const string CS1729 = nameof(CS1729); // CS1729: 'C' does not contain a constructor that takes n arguments
public const string CS1739 = nameof(CS1739); // CS1739: The best overload for 'Program' does not have a parameter named 'v'
public const string CS1503 = nameof(CS1503); // CS1503: Argument 1: cannot convert from 'T1' to 'T2'
public const string CS1660 = nameof(CS1660); // CS1660: Cannot convert lambda expression to type 'string[]' because it is not a delegate type
public const string CS7036 = nameof(CS7036); // CS7036: There is no argument given that corresponds to the required formal parameter 'v' of 'C.C(int)'

public static readonly ImmutableArray<string> AllDiagnosticIds =
ImmutableArray.Create(CS0122, CS1729, CS1739, CS1503, CS7036, IDEDiagnosticIds.UnboundConstructorId);
ImmutableArray.Create(CS0122, CS1729, CS1739, CS1503, CS1660, CS7036, IDEDiagnosticIds.UnboundConstructorId);

public static readonly ImmutableArray<string> TooManyArgumentsDiagnosticIds =
ImmutableArray.Create(CS1729);

public static readonly ImmutableArray<string> CannotConvertDiagnosticIds =
ImmutableArray.Create(CS1503, CS1660);
}

/// <summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.CodeAnalysis.AddParameter
{
internal struct ArgumentInsertPositionData<TArgumentSyntax> where TArgumentSyntax : SyntaxNode
{
public ArgumentInsertPositionData(IMethodSymbol methodToUpdate, TArgumentSyntax argumentToInsert, int argumentInsertionIndex)
{
MethodToUpdate = methodToUpdate;
ArgumentToInsert = argumentToInsert;
ArgumentInsertionIndex = argumentInsertionIndex;
}

public IMethodSymbol MethodToUpdate { get; }
public TArgumentSyntax ArgumentToInsert { get; }
public int ArgumentInsertionIndex { get; }
}
}
38 changes: 38 additions & 0 deletions src/Features/Core/Portable/AddParameter/CodeFixData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.AddParameter
{
internal struct CodeFixData
{
public CodeFixData(
IMethodSymbol method,
Func<CancellationToken, Task<Solution>> createChangedSolutionNonCascading,
Func<CancellationToken, Task<Solution>> createChangedSolutionCascading)
{
Method = method ?? throw new ArgumentNullException(nameof(method));
CreateChangedSolutionNonCascading = createChangedSolutionNonCascading ?? throw new ArgumentNullException(nameof(createChangedSolutionNonCascading));
CreateChangedSolutionCascading = createChangedSolutionCascading;
}

/// <summary>
/// The overload to fix.
/// </summary>
public IMethodSymbol Method { get; }

/// <summary>
/// A mandatory fix for the overload without cascading.
/// </summary>
public Func<CancellationToken, Task<Solution>> CreateChangedSolutionNonCascading { get; }

/// <summary>
/// An optional fix for the overload with cascading.
/// </summary>
public Func<CancellationToken, Task<Solution>> CreateChangedSolutionCascading { get; }
}
}
39 changes: 36 additions & 3 deletions src/Features/Core/Portable/FeaturesResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Features/Core/Portable/FeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,15 @@ This version used in: {2}</value>
<data name="Add_parameter_to_0" xml:space="preserve">
<value>Add parameter to '{0}'</value>
</data>
<data name="Add_parameter_to_0_and_overrides_implementations" xml:space="preserve">
<value>Add parameter to '{0}' (and overrides/implementations)</value>
</data>
<data name="Add_to_0" xml:space="preserve">
<value>Add to '{0}'</value>
</data>
<data name="Related_method_signatures_found_in_metadata_will_not_be_updated" xml:space="preserve">
<value>Related method signatures found in metadata will not be updated.</value>
</data>
<data name="Generate_constructor" xml:space="preserve">
<value>Generate constructor...</value>
</data>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">Přidat odkaz na projekt do {0}</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">Akce nemůžou zůstat prázdné.</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">obecné přetížení</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">Fügen Sie zu "{0}" einen Projektverweis hinzu.</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">Aktionen dürfen nicht leer sein.</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">generische Überladung</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">Agregue referencia de proyecto a '{0}'.</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">Las acciones no pueden estar vacías.</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">sobrecarga genérica</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">Ajoutez une référence de projet à '{0}'.</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">Les actions ne peuvent pas être vides.</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">surcharge générique</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">Aggiunge il riferimento al progetto a '{0}'.</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">Il campo Azioni non può essere vuoto.</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">overload generico</target>
Expand Down
15 changes: 15 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../FeaturesResources.resx">
<body>
<trans-unit id="Add_parameter_to_0_and_overrides_implementations">
<source>Add parameter to '{0}' (and overrides/implementations)</source>
<target state="new">Add parameter to '{0}' (and overrides/implementations)</target>
<note />
</trans-unit>
<trans-unit id="Add_project_reference_to_0">
<source>Add project reference to '{0}'.</source>
<target state="translated">プロジェクト参照を '{0}' に追加します。</target>
Expand All @@ -17,6 +22,16 @@
<target state="translated">アクションは空にできません。</target>
<note />
</trans-unit>
<trans-unit id="Add_to_0">
<source>Add to '{0}'</source>
<target state="new">Add to '{0}'</target>
<note />
</trans-unit>
<trans-unit id="Related_method_signatures_found_in_metadata_will_not_be_updated">
<source>Related method signatures found in metadata will not be updated.</source>
<target state="new">Related method signatures found in metadata will not be updated.</target>
<note />
</trans-unit>
<trans-unit id="generic_overload">
<source>generic overload</source>
<target state="translated">ジェネリック オーバーロード</target>
Expand Down
Loading

0 comments on commit 5665268

Please sign in to comment.