未验证 提交 119aec27 编写于 作者: J Jinu 提交者: GitHub

Merge pull request #23693 from zaytsev-victor/Fixed16975

"Generate method" refactoring enabled if method name is equal to imported type.
......@@ -7514,5 +7514,215 @@ void Main()
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName1()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
class Goo { }",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
class Goo { }",
parseOptions: TestOptions.Regular);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName2()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
interface Goo { }",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
interface Goo { }",
parseOptions: TestOptions.Regular);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName3()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
struct Goo { }",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
struct Goo { }",
parseOptions: TestOptions.Regular);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName4()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
delegate void Goo()",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
delegate void Goo()",
parseOptions: TestOptions.Regular);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName5()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
namespace Goo { }",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
namespace Goo { }",
parseOptions: TestOptions.Regular);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
[WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")]
public async Task TestWithSameMethodNameAsTypeName6()
{
await TestAsync(
@"using System;
class C
{
public void M1()
{
[|Goo|]();
}
}
enum Goo { One }",
@"using System;
class C
{
public void M1()
{
Goo();
}
private void Goo()
{
throw new NotImplementedException();
}
}
enum Goo { One }",
parseOptions: TestOptions.Regular);
}
}
}
......@@ -4191,6 +4191,183 @@ Class Program
End Class")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName1() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Enum Goo
One
End Enum",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Enum Goo
One
End Enum")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName2() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Delegate Sub Goo()",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Delegate Sub Goo()")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName3() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Class Goo
End Class",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Class Goo
End Class")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName4() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Structure Goo
End Structure",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Structure Goo
End Structure")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName5() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Interface Goo
End Interface",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Interface Goo
End Interface")
End Function
<WorkItem(16975, "https://github.com/dotnet/roslyn/issues/16975")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)>
Public Async Function TestWithSameMethodNameAsTypeName6() As Task
Await TestInRegularAndScriptAsync(
"Imports System
Class C
Sub Bar()
[|Goo|]()
End Sub
End Class
Namespace Goo
End Namespace",
"Imports System
Class C
Sub Bar()
Goo()
End Sub
Private Sub Goo()
Throw New NotImplementedException()
End Sub
End Class
Namespace Goo
End Namespace")
End Function
Public Class GenerateConversionTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest
......
......@@ -30,6 +30,7 @@ internal static class GenerateMethodDiagnosticIds
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 CS1739 = nameof(CS1739); // error CS1739: The best overload for 'M' does not have a parameter named 'x'
private const string CS7036 = nameof(CS7036); // error CS7036: There is no argument given that corresponds to the required formal parameter 'x' of 'C.M(int)'
private const string CS1955 = nameof(CS1955); // error CS1955: Non-invocable member 'Goo' cannot be used like a method.
public static readonly ImmutableArray<string> FixableDiagnosticIds =
ImmutableArray.Create(
......@@ -45,7 +46,8 @@ internal static class GenerateMethodDiagnosticIds
CS1503,
CS1660,
CS1739,
CS7036);
CS7036,
CS1955);
}
[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.GenerateMethod), Shared]
......
......@@ -30,10 +30,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateMethod
Friend Const BC32045 As String = "BC32045" ' error BC32045: 'Private Sub Blah()' has no type parameters and so cannot have type arguments.
Friend Const BC32087 As String = "BC32087" ' error BC32087: Overload resolution failed because no accessible 'Blah' accepts this number of type arguments.
Friend Const BC36625 As String = "BC36625" ' error BC36625: Lambda expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.
Friend Const BC30107 As String = "BC30107" ' error BC30107: 'Foo' is an Enum type and cannot be used as an expression.
Friend Const BC30108 As String = "BC30108" ' error BC30108: 'Foo' is a type and cannot be used as an expression.
Friend Const BC30109 As String = "BC30109" ' error BC30109: 'Foo' is a class type and cannot be used as an expression.
Friend Const BC30110 As String = "BC30110" ' error BC30110: 'Foo' is a structure type and cannot be used as an expression.
Friend Const BC30111 As String = "BC30111" ' error BC30111: 'Foo' is an interface type and cannot be used as an expression.
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30518, BC30519, BC30520, BC30521, BC30057, BC30112, BC30451, BC30455, BC30456, BC30401, BC30516, BC32016, BC32045, BC32087, BC36625)
Return ImmutableArray.Create(BC30518, BC30519, BC30520, BC30521, BC30057, BC30112, BC30451, BC30455, BC30456, BC30401, BC30516, BC32016, BC32045, BC32087, BC36625, BC30107, BC30108, BC30109, BC30110, BC30111)
End Get
End Property
......
......@@ -24,9 +24,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateMember.GenerateMethod
End Function
Public Shared Function IsValidSymbol(symbol As ISymbol, semanticModel As SemanticModel) As Boolean
' We want to still generate a method even if this is a Namespace symbol because unknown method calls without
' parenthesis are bound as namespaces by the VB compiler.
Return symbol.Kind = SymbolKind.Namespace Or AreSpecialOptionsActive(semanticModel)
' We want to still generate a method even if this is a Namespace or NamedType symbol because unknown method calls without
' parenthesis are bound as namespaces or named types by the VB compiler.
Return symbol.Kind = SymbolKind.Namespace Or symbol.Kind = SymbolKind.NamedType Or AreSpecialOptionsActive(semanticModel)
End Function
End Class
End Namespace
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册