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

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 13, 2017

Fixes #19041

@CyrusNajmabadi CyrusNajmabadi added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label May 13, 2017
@CyrusNajmabadi
Copy link
Member Author

Retest windows_release_vs-integration_prtest please

@@ -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.

@@ -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.

@CyrusNajmabadi
Copy link
Member Author

Tagging @dotnet/roslyn-ide @sharwell

This addresses a bunch of complexity that had crept into the set of components we have that are all responsible for some part of the overall 'generate constructor' feature. Code was misplaced and was making things much more complex. It was also bleeding out to the user in confusing ways (i.e. offering the same sort of constructor in multiple ways, or just generating duplicate constructors at times).

I've simplified things, squashed several bugs, and tried to comment things to make it clearer what the overall responsibilities are here.

The specific components we have (and which i have cleaned up) are:

  1. We have a CodeFixProvider responsible for seeing things like "new MyType(x, y, z)" and generating a constructor in MyType that accepts those parameters if none exists. This is 'GenerateConstructor', and is very related to GenerateMethod.
  2. We have a CodeRefactoringProvider responsible for allowing the user to pick a set of members (either with a selection, or a WPF control), and to make a constructor from it. This is 'GenerateConstructorFromMembers'.
  3. We have a CodeRefactoringProvider responsible for generating the constructors for a type that then hook up to the base-type's constructors, to save you time having ot manually generate them. This is called 'GenerateDefaultConstructors', though it could probably get a better name since this really isn't about 'Default'.

@@ -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.

@@ -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.

@@ -27,8 +28,7 @@ Imports System.Collections.Generic
Imports System.Linq
Class Program
Inherits Exception
Public Sub New(message As String)
MyBase.New(message)
Public Sub New()
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 changes are expected given that this feature now will offer to generate the default constructor if the base type has one as well.

@@ -60,35 +51,6 @@ protected override bool IsClassDeclarationGeneration(SemanticDocument document,
return false;
}

protected override bool TryInitializeClassDeclarationGenerationState(
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed anymore GenerateConstructor is responsible for the "new MyFoo(x, y, z)" cases, not the "class D : BaseType" cases. Those are handled elsewhere.


var syntaxTree = document.SyntaxTree;
var node = document.Root.FindToken(textSpan.Start).GetAncestor<TypeSyntax>();
if (node != null)
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 the same, just indented differently.

@CyrusNajmabadi CyrusNajmabadi removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label May 14, 2017
@CyrusNajmabadi
Copy link
Member Author

Tagging @MattGertz

Customer scenario

IDE shows too many 'fix' options in some cases, with some of the options being effective duplicates of the others.

Bugs this fixes:

Fixes #19041

Workarounds, if any

None.

Risk

Low.

Performance impact

Low.

Is this a regression from a previous update?

Yes.

Root cause analysis:

As we added more and more refactorings we ended up duplicating a bit of featureset across a few of them.

How was the bug found?

Internal usage.

@CyrusNajmabadi CyrusNajmabadi merged commit a3ccae5 into dotnet:master May 15, 2017
@CyrusNajmabadi CyrusNajmabadi deleted the constructorWork branch May 15, 2017 22:45
@sharwell
Copy link
Member

Awesome. Small detail but they all add up 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants