Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code for generating constructors from class-decl, it will be provided by another refactoring. #19481

Merged
merged 14 commits into from
May 15, 2017
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<Compile Include="ConvertToInterpolatedString\ConvertPlaceholderToInterpolatedStringTests.cs" />
<Compile Include="CodeActions\EncapsulateField\EncapsulateFieldTests.cs" />
<Compile Include="CodeActions\ExtractMethod\ExtractMethodTests.cs" />
<Compile Include="CodeActions\GenerateDefaultConstructors\GenerateDefaultConstructorsTests.cs" />
<Compile Include="GenerateDefaultConstructors\GenerateDefaultConstructorsTests.cs" />
<Compile Include="Diagnostics\UpgradeProject\UpgradeProjectTests.cs" />
<Compile Include="Completion\CompletionProviders\DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs" />
<Compile Include="GenerateFromMembers\AddConstructorParametersFromMembers\AddConstructorParametersFromMembersTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2316,66 +2316,6 @@ public Base(bool val = false)
}");
}

[WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests moved.

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)]
public async Task TestGenerateFromDerivedClass()
{
await TestInRegularAndScriptAsync(
@"class Base
{
public Base(string value)
{
}
}

class [||]Derived : Base
{
}",
@"class Base
{
public Base(string value)
{
}
}

class Derived : Base
{
public Derived(string value) : base(value)
{
}
}");
}

[WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)]
public async Task TestGenerateFromDerivedClass2()
{
await TestInRegularAndScriptAsync(
@"class Base
{
public Base(int a, string value = null)
{
}
}

class [||]Derived : Base
{
}",
@"class Base
{
public Base(int a, string value = null)
{
}
}

class Derived : Base
{
public Derived(int a, string value = null) : base(a, value)
{
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)]
public async Task TestGenerateWithIncorrectConstructorArguments_Crash()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CodeRefactorings.GenerateDefaultConstructors;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.GenerateDefaultConstructors;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.GenerateDefaultConstructors
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.GenerateDefaultConstructors
{
public class GenerateDefaultConstructorsTests : AbstractCSharpCodeActionTest
{
Expand Down Expand Up @@ -590,7 +591,7 @@ protected Program(SerializationInfo info, StreamingContext context) : base(info,
{
}
}",
index: 3,
index: 4,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because GenrateDefaultConstructors now offers to generate the no arg constructor, the indices increased here.

ignoreTrivia: false);
}

Expand Down Expand Up @@ -728,10 +729,6 @@ public Program()
{
}

public Program()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. If you expand the code above htis, you'll see we were generating the default constructor twice.

{
}

public Program(string message) : base(message)
{
}
Expand Down Expand Up @@ -806,6 +803,66 @@ class B
public B((int a, string b) x)
{
}
}");
}

[WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)]
public async Task TestGenerateFromDerivedClass()
{
await TestInRegularAndScriptAsync(
@"class Base
{
public Base(string value)
{
}
}

class [||]Derived : Base
{
}",
@"class Base
{
public Base(string value)
{
}
}

class Derived : Base
{
public Derived(string value) : base(value)
{
}
}");
}

[WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)]
public async Task TestGenerateFromDerivedClass2()
{
await TestInRegularAndScriptAsync(
@"class Base
{
public Base(int a, string value = null)
{
}
}

class [||]Derived : Base
{
}",
@"class Base
{
public Base(int a, string value = null)
{
}
}

class Derived : Base
{
public Derived(int a, string value = null) : base(a, value)
{
}
}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
<Compile Include="ConvertToInterpolatedString\ConvertPlaceholderToInterpolatedStringTests.vb" />
<Compile Include="CodeActions\EncapsulateField\EncapsulateFieldTests.vb" />
<Compile Include="CodeActions\ExtractMethod\ExtractMethodTests.vb" />
<Compile Include="CodeActions\GenerateDefaultConstructors\GenerateDefaultConstructorsTests.vb" />
<Compile Include="GenerateDefaultConstructors\GenerateDefaultConstructorsTests.vb" />
<Compile Include="AddConstructorParametersFromMembers\AddConstructorParametersFromMembersTests.vb" />
<Compile Include="GenerateConstructorFromMembers\GenerateConstructorFromMembersTests.vb" />
<Compile Include="GenerateEqualsAndGetHashCodeFromMembers\GenerateEqualsAndGetHashCodeFromMembersTests.vb" />
Expand Down Expand Up @@ -276,7 +276,7 @@
<Compile Include="Diagnostics\ExitContinue\ExitContinueCodeActionTests.vb" />
<Compile Include="Diagnostics\FixIncorrectFunctionReturnType\FixIncorrectFunctionReturnTypeTests.vb" />
<Compile Include="Diagnostics\FullyQualify\FullyQualifyTests.vb" />
<Compile Include="Diagnostics\GenerateConstructor\GenerateConstructorTests.vb" />
<Compile Include="GenerateConstructor\GenerateConstructorTests.vb" />
<Compile Include="Diagnostics\GenerateEndConstruct\GenerateEndConstructTests.vb" />
<Compile Include="Diagnostics\GenerateEnumMember\GenerateEnumMemberTests.vb" />
<Compile Include="Diagnostics\GenerateEvent\GenerateEventTests.vb" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic.Diagnostics
Imports Microsoft.CodeAnalysis.VisualBasic.GenerateConstructor

Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.GenerateConstructor
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.GenerateConstructor
Public Class GenerateConstructorTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest

Expand Down Expand Up @@ -1528,98 +1529,6 @@ End Class")
End Function
End Class

<WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests moved.

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateInDerivedType1() As Task
Await TestInRegularAndScriptAsync(
"
Public Class Base
Public Sub New(a As String)

End Sub
End Class

Public Class [||]Derived
Inherits Base

End Class",
"
Public Class Base
Public Sub New(a As String)

End Sub
End Class

Public Class Derived
Inherits Base

Public Sub New(a As String)
MyBase.New(a)
End Sub
End Class")
End Function

<WorkItem(6541, "https://github.com/dotnet/Roslyn/issues/6541")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateInDerivedType2() As Task
Await TestInRegularAndScriptAsync(
"
Public Class Base
Public Sub New(a As Integer, Optional b As String = Nothing)

End Sub
End Class

Public Class [||]Derived
Inherits Base

End Class",
"
Public Class Base
Public Sub New(a As Integer, Optional b As String = Nothing)

End Sub
End Class

Public Class Derived
Inherits Base

Public Sub New(a As Integer, Optional b As String = Nothing)
MyBase.New(a, b)
End Sub
End Class")
End Function

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateInDerivedType_InvalidClassStatement() As Task
Await TestInRegularAndScriptAsync(
"
Public Class Base
Public Sub New(a As Integer, Optional b As String = Nothing)

End Sub
End Class

Public Class [|;;|]Derived
Inherits Base

End Class",
"
Public Class Base
Public Sub New(a As Integer, Optional b As String = Nothing)

End Sub
End Class

Public Class ;;Derived
Inherits Base

Public Sub New(a As Integer, Optional b As String = Nothing)
MyBase.New(a, b)
End Sub
End Class")
End Function

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateConstructorNotOfferedForDuplicate() As Task
Await TestMissingInRegularAndScriptAsync(
Expand Down
Loading