Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f4de4bb
Starting work
CyrusNajmabadi Jun 1, 2020
17d2618
Compilable
CyrusNajmabadi Jun 1, 2020
982c7f1
Move member
CyrusNajmabadi Jun 1, 2020
77fb274
Intermediary
CyrusNajmabadi Jun 1, 2020
c10d7f0
Almost there
CyrusNajmabadi Jun 1, 2020
4fcc6b7
Delete code
CyrusNajmabadi Jun 1, 2020
adf254c
remove editor
CyrusNajmabadi Jun 1, 2020
50a40f7
remove editor fie
CyrusNajmabadi Jun 1, 2020
e0a0fc2
make protected
CyrusNajmabadi Jun 1, 2020
1d82710
Tests
CyrusNajmabadi Jun 1, 2020
9b11a0e
Use immutable collections
CyrusNajmabadi Jun 1, 2020
6bcd6c9
Fix c# tests
CyrusNajmabadi Jun 1, 2020
ec0038f
Add VB tests
CyrusNajmabadi Jun 1, 2020
7891a39
Add workitems
CyrusNajmabadi Jun 1, 2020
725f201
Simplify
CyrusNajmabadi Jun 1, 2020
ef6dfbc
Simplify
CyrusNajmabadi Jun 1, 2020
75b7f81
Simplify
CyrusNajmabadi Jun 1, 2020
e6b8687
Simplify
CyrusNajmabadi Jun 1, 2020
fdb0b24
Simplify
CyrusNajmabadi Jun 1, 2020
eff78f3
Add comment
CyrusNajmabadi Jun 1, 2020
0cbda32
Inline
CyrusNajmabadi Jun 1, 2020
c277173
Simplify
CyrusNajmabadi Jun 1, 2020
a861f20
Simplify
CyrusNajmabadi Jun 1, 2020
2d39bcf
Remove loc string
CyrusNajmabadi Jun 1, 2020
824bf30
Simplify
CyrusNajmabadi Jun 1, 2020
5221160
Simplify
CyrusNajmabadi Jun 1, 2020
df915f2
Simplify
CyrusNajmabadi Jun 1, 2020
6ddda48
Change accessibility
CyrusNajmabadi Jun 1, 2020
83f2871
Renames
CyrusNajmabadi Jun 1, 2020
9c8f0f9
Add member back
CyrusNajmabadi Jun 1, 2020
0dbdcf2
INvert
CyrusNajmabadi Jun 1, 2020
b5c63ed
Simplify
CyrusNajmabadi Jun 2, 2020
7a80c18
Simplify more.
CyrusNajmabadi Jun 2, 2020
0f7ebd1
Simplify further
CyrusNajmabadi Jun 2, 2020
9e16aa6
Simplify
CyrusNajmabadi Jun 2, 2020
d9fa000
Simplify
CyrusNajmabadi Jun 2, 2020
394b6c0
REvert
CyrusNajmabadi Jun 3, 2020
b104b88
Merge pull request #44739 from CyrusNajmabadi/genConstructorWithProps
CyrusNajmabadi Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,50 @@ End Class",
End Class")
End Function

<WorkItem(44537, "https://github.com/dotnet/roslyn/issues/44537")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateIntoContainingType_WithProperties() As Task
Await TestInRegularAndScriptAsync(
"Class C
Sub Main()
Dim f = New C([|4|], 5, 6)
End Sub
End Class",
"Class C
Public Sub New(v1 As Integer, v2 As Integer, v3 As Integer)
Me.V1 = v1
Me.V2 = v2
Me.V3 = v3
End Sub

Public ReadOnly Property V1 As Integer
Public ReadOnly Property V2 As Integer
Public ReadOnly Property V3 As Integer

Sub Main()
Dim f = New C(4, 5, 6)
End Sub
End Class", index:=1)
End Function

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestGenerateIntoContainingType_NoMembers() As Task
Await TestInRegularAndScriptAsync(
"Class C
Sub Main()
Dim f = New C([|4|], 5, 6)
End Sub
End Class",
"Class C
Public Sub New(v1 As Integer, v2 As Integer, v3 As Integer)
End Sub

Sub Main()
Dim f = New C(4, 5, 6)
End Sub
End Class", index:=2)
End Function

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructor)>
Public Async Function TestInvokingFromInsideAnotherConstructor() As Task
Await TestInRegularAndScriptAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected override ITypeSymbol GetAttributeArgumentType(
protected override bool IsConversionImplicit(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
=> compilation.ClassifyConversion(sourceType, targetType).IsImplicit;

internal override IMethodSymbol GetDelegatingConstructor(
protected override IMethodSymbol GetDelegatingConstructor(
State state,
SemanticDocument document,
int argumentCount,
Expand Down
9 changes: 6 additions & 3 deletions src/Features/Core/Portable/FeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,6 @@ This version used in: {2}</value>
<data name="Convert_to_full_property" xml:space="preserve">
<value>Convert to full property</value>
</data>
<data name="Generate_constructor_in_0_without_fields" xml:space="preserve">
<value>Generate constructor in '{0}' (without fields)</value>
</data>
<data name="Warning_Method_overrides_symbol_from_metadata" xml:space="preserve">
<value>Warning: Method overrides symbol from metadata</value>
</data>
Expand Down Expand Up @@ -2768,4 +2765,10 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<data name="Document_must_be_contained_in_the_workspace_that_created_this_service" xml:space="preserve">
<value>Document must be contained in the workspace that created this service</value>
</data>
<data name="Generate_constructor_in_0_with_fields" xml:space="preserve">
<value>Generate constructor in '{0}' (with fields)</value>
</data>
<data name="Generate_constructor_in_0_with_properties" xml:space="preserve">
<value>Generate constructor in '{0}' (with properties)</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -42,11 +42,9 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
//
// Otherwise, just generate a normal constructor that assigns any provided
// parameters into fields.
var parameterToExistingFieldMap = new Dictionary<string, ISymbol>();
var parameterToExistingFieldMap = ImmutableDictionary.CreateBuilder<string, ISymbol>();
for (var i = 0; i < _state.Parameters.Length; i++)
{
parameterToExistingFieldMap[_state.Parameters[i].Name] = _state.SelectedMembers[i];
}

var factory = _document.GetLanguageService<SyntaxGenerator>();

Expand All @@ -55,15 +53,16 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
var options = await _document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
var preferThrowExpression = _service.PrefersThrowExpression(options);

var (fields, constructor) = factory.CreateFieldDelegatingConstructor(
var members = factory.CreateMemberDelegatingConstructor(
semanticModel,
_state.ContainingType.Name,
_state.ContainingType,
_state.Parameters,
parameterToExistingFieldMap,
parameterToNewFieldMap: null,
parameterToExistingFieldMap.ToImmutable(),
parameterToNewMemberMap: null,
addNullChecks: _addNullChecks,
preferThrowExpression: preferThrowExpression);
preferThrowExpression: preferThrowExpression,
generateProperties: false);

// If the user has selected a set of members (i.e. TextSpan is not empty), then we will
// choose the right location (i.e. null) to insert the constructor. However, if they're
Expand All @@ -76,7 +75,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
var result = await CodeGenerator.AddMemberDeclarationsAsync(
_document.Project.Solution,
_state.ContainingType,
fields.Concat(constructor),
members,
new CodeGenerationOptions(
contextLocation: syntaxTree.GetLocation(_state.TextSpan),
afterThisLocation: afterThisLocation),
Expand Down

This file was deleted.

Loading