提交 a1de13fb 编写于 作者: I Ivan Basov

engine unit tests

上级 3c6accbe
......@@ -319,7 +319,7 @@ class C : I3 { public void M(string y, int newIntegerParameter, int x) { } }";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Cascade_ToMethods_WithDifferentParameterNames()
{
var markup = @"
......@@ -380,6 +380,7 @@ public virtual int M(string y, int newIntegerParameter, int x)
public class D : B
{
/// <param name=""b""></param>
/// <param name=""newIntegerParameter""></param>
/// <param name=""a""></param>
public override int M(string b, int newIntegerParameter, int a)
{
......@@ -390,6 +391,7 @@ public override int M(string b, int newIntegerParameter, int a)
public class D2 : D
{
/// <param name=""x""></param>
/// <param name=""newIntegerParameter""></param>
/// <param name=""y""></param>
public override int M(string x, int newIntegerParameter, int y)
{
......@@ -397,9 +399,9 @@ public override int M(string x, int newIntegerParameter, int y)
((D)this).M(""Two"", 12345, 1);
((B)this).M(""Two"", 12345, 1);
M(x: ""Two"", 12345, y: 1);
((D)this).M(b: ""Two"", a: 1, newIntegerParameter: 12345);
((B)this).M(y: ""Two"", x: 1, newIntegerParameter: 12345);
M(x: ""Two"", newIntegerParameter: 12345, y: 1);
((D)this).M(b: ""Two"", newIntegerParameter: 12345, a: 1);
((B)this).M(y: ""Two"", newIntegerParameter: 12345, x: 1);
return 1;
}
......
// 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.Threading.Tasks;
using Microsoft.CodeAnalysis.ChangeSignature;
using Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.ChangeSignature;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ChangeSignature
{
public partial class ChangeSignatureTests : AbstractChangeSignatureTests
{
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_KeepCountsPerLine()
{
var markup = @"
class C
{
void $$Method(int a, int b, int c,
int d, int e,
int f)
{
Method(1,
2, 3,
4, 5, 6);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(5),
new AddedParameterOrExistingIndex(4),
new AddedParameterOrExistingIndex(3),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(2),
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class C
{
void Method(int f, int e, int d,
byte bb, int c,
int b, int a)
{
Method(6,
5, 4,
34, 3, 2, 1);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_KeepTrivia()
{
var markup = @"
class C
{
void $$Method(
int a, int b, int c,
int d, int e,
int f)
{
Method(
1, 2, 3,
4, 5, 6);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(2),
new AddedParameterOrExistingIndex(3),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(4),
new AddedParameterOrExistingIndex(5)};
var expectedUpdatedCode = @"
class C
{
void Method(
int b, int c, int d,
byte bb, int e,
int f)
{
Method(
2, 3, 4,
34, 5, 6);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_KeepTrivia_WithArgumentNames()
{
var markup = @"
class C
{
void $$Method(
int a, int b, int c,
int d, int e,
int f)
{
Method(
a: 1, b: 2, c: 3,
d: 4, e: 5, f: 6);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(2),
new AddedParameterOrExistingIndex(3),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(4),
new AddedParameterOrExistingIndex(5)};
var expectedUpdatedCode = @"
class C
{
void Method(
int b, int c, int d,
byte bb, int e,
int f)
{
Method(
b: 2, c: 3, d: 4,
bb: 34, e: 5, f: 6);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_Method()
{
var markup = @"
class C
{
void $$Method(int a,
int b)
{
Method(1,
2);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class C
{
void Method(int b,
byte bb, int a)
{
Method(2,
34, 1);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_Constructor()
{
var markup = @"
class SomeClass
{
$$SomeClass(int a,
int b)
{
new SomeClass(1,
2);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class SomeClass
{
SomeClass(int b,
byte bb, int a)
{
new SomeClass(2,
a: 1, bb: 34);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_Indexer()
{
var markup = @"
class SomeClass
{
public int $$this[int a,
int b]
{
get
{
return new SomeClass()[1,
2];
}
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class SomeClass
{
public int this[int b,
byte bb, int a]
{
get
{
return new SomeClass()[2,
a: 1, bb: 34];
}
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_Delegate()
{
var markup = @"
class SomeClass
{
delegate void $$MyDelegate(int a,
int b);
void M(int a,
int b)
{
var myDel = new MyDelegate(M);
myDel(1,
2);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class SomeClass
{
delegate void MyDelegate(int b,
byte bb, int a);
void M(int b,
byte bb, int a)
{
var myDel = new MyDelegate(M);
myDel(2,
34, 1);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_AnonymousMethod()
{
var markup = @"
class SomeClass
{
delegate void $$MyDelegate(int a,
int b);
void M()
{
MyDelegate myDel = delegate (int x,
int y)
{
// Nothing
};
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class SomeClass
{
delegate void MyDelegate(int b,
byte bb, int a);
void M()
{
MyDelegate myDel = delegate (int y,
byte bb, int x)
{
// Nothing
};
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_ConstructorInitializers()
{
var markup = @"
class B
{
public $$B(int x, int y) { }
public B() : this(1,
2)
{ }
}
class D : B
{
public D() : base(1,
2)
{ }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
class B
{
public B(int y, byte bb, int x) { }
public B() : this(2,
x: 1, bb: 34)
{ }
}
class D : B
{
public D() : base(2,
x: 1, bb: 34)
{ }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_Attribute()
{
var markup = @"
[Custom(1,
2)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y) { }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(0)};
var expectedUpdatedCode = @"
[Custom(2,
x: 1, bb: 34)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(int y, byte bb, int x) { }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_Attribute_KeepTrivia()
{
var markup = @"
[Custom(
1, 2)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y) { }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")) };
var expectedUpdatedCode = @"
[Custom(
2, bb: 34)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(int y, byte bb) { }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_Attribute_KeepTrivia_RemovingSecond()
{
var markup = @"
[Custom(
1, 2)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y) { }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(0),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34"))};
var expectedUpdatedCode = @"
[Custom(
1, bb: 34)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(int x, byte bb) { }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_Attribute_KeepTrivia_RemovingBothAddingNew()
{
var markup = @"
[Custom(
1, 2)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y) { }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34"))};
var expectedUpdatedCode = @"
[Custom(
bb: 34)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(byte bb) { }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WorkItem(28156, "https://github.com/dotnet/roslyn/issues/28156")]
public async Task AddParameter_Formatting_Attribute_KeepTrivia_RemovingBeforeNewlineComma()
{
var markup = @"
[Custom(1
, 2, 3)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y, int z) { }
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(1),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34")),
new AddedParameterOrExistingIndex(2)};
var expectedUpdatedCode = @"
[Custom(2, z: 3, bb: 34)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(int y, byte bb, int z) { }
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
[WorkItem(946220, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/946220")]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddParameter_Formatting_LambdaAsArgument()
{
var markup = @"class C
{
void M(System.Action<int, int> f, int z$$)
{
M((x, y) => System.Console.WriteLine(x + y), 5);
}
}";
var updatedSignature = new[] {
new AddedParameterOrExistingIndex(0),
new AddedParameterOrExistingIndex(new AddedParameter("byte", "bb", "34"))};
var expectedUpdatedCode = @"class C
{
void M(System.Action<int, int> f, byte bb)
{
M((x, y) => System.Console.WriteLine(x + y), 34);
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: updatedSignature, expectedUpdatedInvocationDocumentCode: expectedUpdatedCode);
}
}
}
......@@ -590,7 +590,7 @@ void M()
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_OnIndividualLines()
{
var markup = @"
......@@ -616,7 +616,7 @@ public class C
/// <param name=""b""></param>
/// <param name=""bb""></param>
/// <param name=""a""></param>
void Goo(int c, int b, byte b, int a)
void Goo(int c, int b, byte bb, int a)
{
}
......@@ -625,7 +625,7 @@ void Goo(int c, int b, byte b, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_OnSameLine()
{
var markup = @"
......@@ -646,7 +646,7 @@ public class C
public class C
{
/// <param name=""c"">c is fun</param><param name=""b"">b is fun</param><param name=""bb""></param>
/// </param><param name=""a"">a is fun</param>
/// <param name=""a"">a is fun</param>
void Goo(int c, int b, byte bb, int a)
{
......@@ -656,7 +656,7 @@ void Goo(int c, int b, byte bb, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_MixedLineDistribution()
{
var markup = @"
......@@ -700,7 +700,7 @@ void Goo(int f, int e, int d, int c, byte bb, int b, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_SingleLineDocComments_MixedWithRegularComments()
{
var markup = @"
......@@ -726,7 +726,8 @@ public class C
{
/// <param name=""e""></param><param name=""d""></param>
// Why is there a regular comment here?
/// <param name=""c""></param><param name=""b""></param><param name=""b""></param><param name=""a""></param>
/// <param name=""c""></param><param name=""b""></param><param name=""b""></param>
/// <param name=""a""></param>
void Goo(int e, int d, int c, byte b, int b, int a)
{
......@@ -736,7 +737,7 @@ void Goo(int e, int d, int c, byte b, int b, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_MultiLineDocComments_OnSeparateLines1()
{
var markup = @"
......@@ -763,9 +764,9 @@ class Program
* <param name=""z"">z!</param>
* <param name=""b""></param>
* <param name=""y"">y!</param>
* <param name=""x"">x!</param>
*/
static void M(int z, int y, byte b, int x)
/// <param name=""x"">x!</param>
static void M(int z, byte b, int y, int x)
{
}
}";
......@@ -773,7 +774,7 @@ static void M(int z, int y, byte b, int x)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_MultiLineDocComments_OnSingleLine()
{
var markup = @"
......@@ -793,8 +794,8 @@ class Program
class Program
{
/** <param name=""z"">z!</param><param name=""b""></param><param name=""y"">y!</param> */
/** <param name=""x"">x!</param> */
static void M(int z, int y, byte b, int x)
/// <param name=""x"">x!</param>
static void M(int z, byte b, int y, int x)
{
}
}";
......@@ -934,7 +935,7 @@ void Goo(int c, byte bb, int b, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_OnConstructors()
{
var markup = @"
......@@ -960,7 +961,7 @@ public class C
/// <param name=""bb""></param>
/// <param name=""b""></param>
/// <param name=""a""></param>
public C(int c, byte b, int b, int a)
public C(int c, byte bb, int b, int a)
{
}
......@@ -968,7 +969,7 @@ public C(int c, byte b, int b, int a)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact(Skip = "TODO"), Trait(Traits.Feature, Traits.Features.ChangeSignature)]
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderParamTagsInDocComments_OnIndexers()
{
var markup = @"
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.ChangeSignature
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
Imports Microsoft.CodeAnalysis.Test.Utilities.ChangeSignature
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ChangeSignature
Partial Public Class ChangeSignatureTests
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToImplementedMethod() As Task
Dim markup = <Text><![CDATA[
Interface I
Sub Goo(x As Integer, y As String)
End Interface
Class C
Implements I
$$Public Sub Goo(x As Integer, y As String) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Interface I
Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Interface
Class C
Implements I
Public Sub Goo(y As String, newIntegerParameter As Integer, x As Integer) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToImplementedMethod_WithTuples() As Task
Dim markup = <Text><![CDATA[
Interface I
Sub Goo(x As (Integer, Integer), y As (String, String))
End Interface
Class C
Implements I
$$Public Sub Goo(x As (Integer, Integer), y As (String, String)) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Interface I
Sub Goo(y As (String, String), newIntegerParameter As Integer, x As (Integer, Integer))
End Interface
Class C
Implements I
Public Sub Goo(y As (String, String), newIntegerParameter As Integer, x As (Integer, Integer)) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToImplementingMethod() As Task
Dim markup = <Text><![CDATA[
Interface I
$$Sub Goo(x As Integer, y As String)
End Interface
Class C
Implements I
Public Sub Goo(x As Integer, y As String) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Interface I
Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Interface
Class C
Implements I
Public Sub Goo(y As String, newIntegerParameter As Integer, x As Integer) Implements I.Goo
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToOverriddenMethod() As Task
Dim markup = <Text><![CDATA[
Class B
Overridable Sub Goo(x As Integer, y As String)
End Sub
End Class
Class D
Inherits B
$$Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
Overridable Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class D
Inherits B
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToOverridingMethod() As Task
Dim markup = <Text><![CDATA[
Class B
$$Overridable Sub Goo(x As Integer, y As String)
End Sub
End Class
Class D
Inherits B
Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
Overridable Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class D
Inherits B
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToOverriddenMethod_Transitive() As Task
Dim markup = <Text><![CDATA[
Class B
Overridable Sub Goo(x As Integer, y As String)
End Sub
End Class
Class C
Inherits B
Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class
Class D
Inherits C
$$Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
Overridable Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class C
Inherits B
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class
Class D
Inherits C
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToOverridingMethod_Transitive() As Task
Dim markup = <Text><![CDATA[
Class B
$$Overridable Sub Goo(x As Integer, y As String)
End Sub
End Class
Class C
Inherits B
Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class
Class D
Inherits C
Public Overrides Sub Goo(x As Integer, y As String)
MyBase.Goo(x, y)
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
Overridable Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class C
Inherits B
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class
Class D
Inherits C
Public Overrides Sub Goo(y As String, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, x:=x, newIntegerParameter:=12345)
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Cascade_ToMethods_Complex() As Task
' B I I2
' \ / \ /
' D (I3)
' / \ \
' $$D2 D3 C
Dim markup = <Text><![CDATA[
Class B
Overridable Sub M(x As Integer, y As String)
End Sub
End Class
Class D
Inherits B
Implements I
Public Overrides Sub M(x As Integer, y As String) Implements I.M
End Sub
End Class
Class D2
Inherits D
Overrides Sub $$M(x As Integer, y As String)
End Sub
End Class
Class D3
Inherits D
Overrides Sub M(x As Integer, y As String)
End Sub
End Class
Interface I
Sub M(x As Integer, y As String)
End Interface
Interface I2
Sub M(x As Integer, y As String)
End Interface
Interface I3
Inherits I, I2
End Interface
Class C
Implements I3
Public Sub M(x As Integer, y As String) Implements I.M, I2.M
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
Overridable Sub M(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class D
Inherits B
Implements I
Public Overrides Sub M(y As String, newIntegerParameter As Integer, x As Integer) Implements I.M
End Sub
End Class
Class D2
Inherits D
Overrides Sub M(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Class D3
Inherits D
Overrides Sub M(y As String, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
Interface I
Sub M(y As String, newIntegerParameter As Integer, x As Integer)
End Interface
Interface I2
Sub M(y As String, newIntegerParameter As Integer, x As Integer)
End Interface
Interface I3
Inherits I, I2
End Interface
Class C
Implements I3
Public Sub M(y As String, newIntegerParameter As Integer, x As Integer) Implements I.M, I2.M
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
Public Async Function TestAddParameter_Cascade_ToOverridingMethod_IncludeParamTags() As Task
Dim markup = <Text><![CDATA[
Class B
''' <param name="a"></param>
''' <param name="b"></param>
Overridable Sub Goo(a As Integer, b As Integer)
End Sub
End Class
Class D
Inherits B
''' <param name="x"></param>
''' <param name="y"></param>
Public Overrides Sub $$Goo(x As Integer, y As Integer)
MyBase.Goo(x, y)
End Sub
End Class]]></Text>.NormalizedValue()
Dim permutation = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim updatedCode = <Text><![CDATA[
Class B
''' <param name="b"></param>
''' <param name="newIntegerParameter"></param>
''' <param name="a"></param>
Overridable Sub Goo(b As Integer, newIntegerParameter As Integer, a As Integer)
End Sub
End Class
Class D
Inherits B
''' <param name="y"></param>
''' <param name="newIntegerParameter"></param>
''' <param name="x"></param>
Public Overrides Sub Goo(y As Integer, newIntegerParameter As Integer, x As Integer)
MyBase.Goo(y, 12345, x)
End Sub
End Class]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=permutation, expectedUpdatedInvocationDocumentCode:=updatedCode)
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.ChangeSignature
Imports Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
Imports Microsoft.CodeAnalysis.Test.Utilities.ChangeSignature
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ChangeSignature
Partial Public Class ChangeSignatureTests
Inherits AbstractChangeSignatureTests
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_KeepCountsPerLine() As Task
Dim markup = <Text><![CDATA[
Class C
Sub $$Method(a As Integer, b As Integer, c As Integer,
d As Integer, e As Integer,
f As Integer)
Method(1,
2, 3,
4, 5, 6)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(5),
New AddedParameterOrExistingIndex(4),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(3),
New AddedParameterOrExistingIndex(2),
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Sub Method(f As Integer, e As Integer, newIntegerParameter As Integer,
d As Integer, c As Integer,
b As Integer, a As Integer)
Method(6,
5, d:=4,
c:=3, b:=2, a:=1, newIntegerParameter:=12345)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_SubMethods() As Task
Dim markup = <Text><![CDATA[
Class C
Sub $$Method(x As Integer,
y As Integer)
Method(1,
2)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Sub Method(y As Integer,
newIntegerParameter As Integer, x As Integer)
Method(2,
x:=1, newIntegerParameter:=12345)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_FunctionMethods() As Task
Dim markup = <Text><![CDATA[
Class C
Sub $$Method(x As Integer,
y As Integer)
Method(1,
2)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Sub Method(y As Integer,
newIntegerParameter As Integer, x As Integer)
Method(2,
x:=1, newIntegerParameter:=12345)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_Events() As Task
Dim markup = <Text><![CDATA[
Class C
Public Event $$MyEvent(a As Integer,
b As Integer)
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Public Event MyEvent(b As Integer,
newIntegerParameter As Integer, a As Integer)
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_CustomEvents() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Sub $$MyDelegate(a As Integer,
b As Integer)
Custom Event MyEvent As MyDelegate
AddHandler(value As MyDelegate)
End AddHandler
RemoveHandler(value As MyDelegate)
End RemoveHandler
RaiseEvent(a As Integer,
b As Integer)
End RaiseEvent
End Event
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Sub MyDelegate(b As Integer,
newIntegerParameter As Integer, a As Integer)
Custom Event MyEvent As MyDelegate
AddHandler(value As MyDelegate)
End AddHandler
RemoveHandler(value As MyDelegate)
End RemoveHandler
RaiseEvent(b As Integer,
newIntegerParameter As Integer, a As Integer)
End RaiseEvent
End Event
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_Constructors() As Task
Dim markup = <Text><![CDATA[
Class C
Sub $$New(a As Integer,
b As Integer)
End Sub
Sub M()
Dim x = New C(1,
2)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Sub New(b As Integer,
newIntegerParameter As Integer, a As Integer)
End Sub
Sub M()
Dim x = New C(2,
a:=1, newIntegerParameter:=12345)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_Properties() As Task
Dim markup = <Text><![CDATA[
Class C
Public Property $$NewProperty(x As Integer,
y As Integer) As Integer
Get
Return 1
End Get
Set(value As Integer)
End Set
End Property
Sub M()
Dim x = NewProperty(1,
2)
NewProperty(1,
2) = x
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Public Property NewProperty(y As Integer,
newIntegerParameter As Integer, x As Integer) As Integer
Get
Return 1
End Get
Set(value As Integer)
End Set
End Property
Sub M()
Dim x = NewProperty(2,
x:=1, newIntegerParameter:=12345)
NewProperty(2,
x:=1, newIntegerParameter:=12345) = x
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_Attribute() As Task
Dim markup = <Text><![CDATA[
<Custom(1,
2)>
Class CustomAttribute
Inherits Attribute
Sub $$New(x As Integer, y As Integer)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
<Custom(2,
x:=1, newIntegerParameter:=12345)>
Class CustomAttribute
Inherits Attribute
Sub New(y As Integer, newIntegerParameter As Integer, x As Integer)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_DelegateFunction() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Function $$MyDelegate(x As Integer,
y As Integer)
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Function MyDelegate(y As Integer,
newIntegerParameter As Integer, x As Integer)
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_MultilineSubLambda() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Sub $$MyDelegate(a As Integer, b As Integer)
Sub M(del As MyDelegate)
M(Sub(a As Integer,
b As Integer)
End Sub)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Sub MyDelegate(b As Integer, newIntegerParameter As Integer, a As Integer)
Sub M(del As MyDelegate)
M(Sub(b As Integer,
newIntegerParameter As Integer, a As Integer)
End Sub)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_MultilineFunctionLambda() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Function $$MyDelegate(a As Integer, b As Integer) As Integer
Sub M(del As MyDelegate)
M(Function(a As Integer,
b As Integer)
Return 1
End Function)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Function MyDelegate(b As Integer, newIntegerParameter As Integer, a As Integer) As Integer
Sub M(del As MyDelegate)
M(Function(b As Integer,
newIntegerParameter As Integer, a As Integer)
Return 1
End Function)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_SingleLineSubLambda() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Sub $$MyDelegate(a As Integer, b As Integer)
Sub M(del As MyDelegate)
M(Sub(a As Integer,
b As Integer) System.Console.WriteLine("Test"))
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Sub MyDelegate(b As Integer, newIntegerParameter As Integer, a As Integer)
Sub M(del As MyDelegate)
M(Sub(b As Integer,
newIntegerParameter As Integer, a As Integer) System.Console.WriteLine("Test"))
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)>
Public Async Function TestAddParameter_Formatting_SingleLineFunctionLambda() As Task
Dim markup = <Text><![CDATA[
Class C
Delegate Function $$MyDelegate(a As Integer, b As Integer) As Integer
Sub M(del As MyDelegate)
M(Function(a As Integer,
b As Integer) 1)
End Sub
End Class
]]></Text>.NormalizedValue()
Dim updatedSignature = {
New AddedParameterOrExistingIndex(1),
New AddedParameterOrExistingIndex(New AddedParameter("Integer", "newIntegerParameter", "12345")),
New AddedParameterOrExistingIndex(0)}
Dim expectedUpdatedCode = <Text><![CDATA[
Class C
Delegate Function MyDelegate(b As Integer, newIntegerParameter As Integer, a As Integer) As Integer
Sub M(del As MyDelegate)
M(Function(b As Integer,
newIntegerParameter As Integer, a As Integer) 1)
End Sub
End Class
]]></Text>.NormalizedValue()
Await TestChangeSignatureViaCommandAsync(LanguageNames.VisualBasic, markup, updatedSignature:=updatedSignature, expectedUpdatedInvocationDocumentCode:=expectedUpdatedCode)
End Function
End Class
End Namespace
......@@ -291,7 +291,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
updatedNode.IsKind(SyntaxKind.IndexerDeclaration) ||
updatedNode.IsKind(SyntaxKind.DelegateDeclaration))
{
var updatedLeadingTrivia = UpdateParamTagsInLeadingTrivia(updatedNode, declarationSymbol, signaturePermutation);
var updatedLeadingTrivia = UpdateParamTagsInLeadingTrivia(document, updatedNode, declarationSymbol, signaturePermutation);
if (updatedLeadingTrivia != null)
{
updatedNode = updatedNode.WithLeadingTrivia(updatedLeadingTrivia);
......@@ -665,7 +665,7 @@ private static CrefParameterSyntax CreateNewCrefParameterSyntax(AddedParameter a
return result;
}
private List<SyntaxTrivia> UpdateParamTagsInLeadingTrivia(CSharpSyntaxNode node, ISymbol declarationSymbol, SignatureChange updatedSignature)
private List<SyntaxTrivia> UpdateParamTagsInLeadingTrivia(Document document, CSharpSyntaxNode node, ISymbol declarationSymbol, SignatureChange updatedSignature)
{
if (!node.HasLeadingTrivia)
{
......@@ -683,7 +683,7 @@ private List<SyntaxTrivia> UpdateParamTagsInLeadingTrivia(CSharpSyntaxNode node,
return null;
}
return GetPermutedTrivia(node, permutedParamNodes);
return GetPermutedTrivia(document, node, permutedParamNodes);
}
private List<XmlElementSyntax> VerifyAndPermuteParamNodes(IEnumerable<XmlElementSyntax> paramNodes, ISymbol declarationSymbol, SignatureChange updatedSignature)
......@@ -744,15 +744,25 @@ private List<XmlElementSyntax> VerifyAndPermuteParamNodes(IEnumerable<XmlElement
return permutedParams;
}
private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElementSyntax> permutedParamNodes)
private List<SyntaxTrivia> GetPermutedTrivia(Document document, CSharpSyntaxNode node, List<XmlElementSyntax> permutedParamNodes)
{
var updatedLeadingTrivia = new List<SyntaxTrivia>();
var index = 0;
SyntaxTrivia lastWhiteSpaceTrivia = default;
var lastDocumentationCommentTriviaSyntax = node.GetLeadingTrivia()
.LastOrDefault(t => t.HasStructure && t.GetStructure() is DocumentationCommentTriviaSyntax);
DocumentationCommentTriviaSyntax documentationCommeStructuredTrivia = lastDocumentationCommentTriviaSyntax.GetStructure() as DocumentationCommentTriviaSyntax;
foreach (var trivia in node.GetLeadingTrivia())
{
if (!trivia.HasStructure)
{
if (trivia.IsKind(SyntaxKind.WhitespaceTrivia))
{
lastWhiteSpaceTrivia = trivia;
}
updatedLeadingTrivia.Add(trivia);
continue;
}
......@@ -793,8 +803,10 @@ private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElem
}
}
var newDocComments = SyntaxFactory.DocumentationCommentTrivia(structuredTrivia.Kind(), SyntaxFactory.List(updatedNodeList.AsEnumerable()));
newDocComments = newDocComments.WithEndOfComment(structuredTrivia.EndOfComment);
var newDocComments = SyntaxFactory.DocumentationCommentTrivia(
structuredTrivia.Kind(),
SyntaxFactory.List(updatedNodeList.AsEnumerable()),
structuredTrivia.EndOfComment);
newDocComments = newDocComments.WithLeadingTrivia(structuredTrivia.GetLeadingTrivia()).WithTrailingTrivia(structuredTrivia.GetTrailingTrivia());
var newTrivia = SyntaxFactory.Trivia(newDocComments);
......@@ -810,9 +822,17 @@ private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElem
if (extraNodeList.Any())
{
var extraDocComments = SyntaxFactory.DocumentationCommentTrivia(SyntaxKind.MultiLineDocumentationCommentTrivia, SyntaxFactory.List(extraNodeList.AsEnumerable()));
extraDocComments = extraDocComments.WithEndOfComment(SyntaxFactory.Token(SyntaxKind.EndOfDocumentationCommentToken));
extraDocComments = extraDocComments.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
var extraDocComments = SyntaxFactory.DocumentationCommentTrivia(
SyntaxKind.MultiLineDocumentationCommentTrivia,
SyntaxFactory.List(extraNodeList.AsEnumerable()),
SyntaxFactory.Token(SyntaxKind.EndOfDocumentationCommentToken));
extraDocComments = extraDocComments
.WithLeadingTrivia(SyntaxFactory.DocumentationCommentExterior("/// "))
.WithTrailingTrivia(node.GetTrailingTrivia())
.WithTrailingTrivia(
SyntaxFactory.EndOfLine(document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp)),
lastWhiteSpaceTrivia);
var newTrivia = SyntaxFactory.Trivia(extraDocComments);
updatedLeadingTrivia.Add(newTrivia);
......@@ -821,25 +841,6 @@ private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElem
return updatedLeadingTrivia;
}
private static List<SyntaxToken> GetSeparators<T>(SeparatedSyntaxList<T> arguments, int numSeparatorsToSkip = 0) where T : SyntaxNode
{
var separators = new List<SyntaxToken>();
for (int i = 0; i < arguments.SeparatorCount - numSeparatorsToSkip; i++)
{
if (i >= arguments.SeparatorCount)
{
separators.Add(SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(SyntaxFactory.ElasticSpace));
}
else
{
separators.Add(arguments.GetSeparator(i));
}
}
return separators;
}
public override async Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsFromDelegateInvoke(
SymbolAndProjectId<IMethodSymbol> symbolAndProjectId,
Document document,
......@@ -899,5 +900,8 @@ protected override IUnifiedArgumentSyntax CreateRegularArgumentSyntax<T>(string
return default;
}
protected override SyntaxToken CreateSeparatorSyntaxToken()
=> SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(SyntaxFactory.ElasticSpace);
}
}
......@@ -394,7 +394,6 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
bool isReducedExtensionMethod = false)
{
// 1. Determine which parameters are permutable
var declarationParameters = declarationSymbol.GetParameters().ToList();
var declarationParametersToPermute = GetParametersToPermute(arguments, declarationParameters, isReducedExtensionMethod);
var argumentsToPermute = arguments.Take(declarationParametersToPermute.Count).ToList();
......@@ -418,14 +417,13 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
}
// 3. Sort the arguments that need to be reordered
argumentsToPermute.Sort((a1, a2) => { return parameterToIndexMap[argumentToParameterMap[a1]].CompareTo(parameterToIndexMap[argumentToParameterMap[a2]]); });
// 4. Add names to arguments where necessary.
var newArguments = new List<IUnifiedArgumentSyntax>();
var expectedIndex = 0 + (isReducedExtensionMethod ? 1 : 0);
var seenNamedArgument = false;
IUnifiedArgumentSyntax paramsArrayArgument = default;
foreach (var argument in argumentsToPermute)
{
......@@ -437,24 +435,54 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
continue;
}
if ((seenNamedArgument || actualIndex != expectedIndex) && !argument.IsNamed)
if (!param.IsParams)
{
newArguments.Add(argument.WithName(param.Name).WithAdditionalAnnotations(Formatter.Annotation));
seenNamedArgument = true;
if ((seenNamedArgument || actualIndex != expectedIndex) && !argument.IsNamed)
{
newArguments.Add(argument.WithName(param.Name).WithAdditionalAnnotations(Formatter.Annotation));
seenNamedArgument = true;
}
else
{
newArguments.Add(argument);
}
}
else
{
newArguments.Add(argument);
paramsArrayArgument = argument;
}
seenNamedArgument |= argument.IsNamed;
expectedIndex++;
}
// 5. Add the remaining arguments. These will already have names or be params arguments, but may have been removed.
// 5. Add added arguments (only at end for the moment)
var brandNewParameters = updatedSignature.UpdatedConfiguration.ToListOfParameters().Where(p => p is AddedParameter).Cast<AddedParameter>();
var removedParams = updatedSignature.OriginalConfiguration.ParamsParameter != null && updatedSignature.UpdatedConfiguration.ParamsParameter == null;
foreach (var brandNewParameter in brandNewParameters)
{
newArguments.Add(CreateRegularArgumentSyntax<T>(brandNewParameter.CallsiteValue).WithName(brandNewParameter.ParameterName));
}
// 6. Add the params argument with the first value:
if (paramsArrayArgument != default)
{
var param = argumentToParameterMap[paramsArrayArgument];
var actualIndex = updatedSignature.GetUpdatedIndex(declarationParameters.IndexOf(param));
if (seenNamedArgument && !paramsArrayArgument.IsNamed)
{
newArguments.Add(paramsArrayArgument.WithName(param.Name).WithAdditionalAnnotations(Formatter.Annotation));
seenNamedArgument = true;
}
else
{
newArguments.Add(paramsArrayArgument);
}
}
// 7. Add the remaining arguments. These will already have names or be params arguments, but may have been removed.
var removedParams = updatedSignature.OriginalConfiguration.ParamsParameter != null && updatedSignature.UpdatedConfiguration.ParamsParameter == null;
for (var i = declarationParametersToPermute.Count; i < arguments.Count; i++)
{
if (!arguments[i].IsNamed && removedParams && i >= updatedSignature.UpdatedConfiguration.ToListOfParameters().Count)
......@@ -468,14 +496,6 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
}
}
// 6. Add added arguments (only at end for the moment)
var brandNewParameters = updatedSignature.UpdatedConfiguration.ToListOfParameters().Where(p => p is AddedParameter).Cast<AddedParameter>();
foreach (var brandNewParameter in brandNewParameters)
{
newArguments.Add(CreateRegularArgumentSyntax<T>(brandNewParameter.CallsiteValue).WithName(brandNewParameter.ParameterName));
}
return newArguments;
}
......@@ -578,5 +598,26 @@ protected static int GetParameterIndex<TNode>(SeparatedSyntaxList<TNode> paramet
return parameters.Count - 1;
}
protected List<SyntaxToken> GetSeparators<T>(SeparatedSyntaxList<T> arguments, int numSeparatorsToSkip = 0) where T : SyntaxNode
{
var separators = new List<SyntaxToken>();
for (int i = 0; i < arguments.SeparatorCount - numSeparatorsToSkip; i++)
{
if (i >= arguments.SeparatorCount)
{
separators.Add(CreateSeparatorSyntaxToken());
}
else
{
separators.Add(arguments.GetSeparator(i));
}
}
return separators;
}
protected abstract SyntaxToken CreateSeparatorSyntaxToken();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册