提交 2885542f 编写于 作者: C chborl

Responded to feedback

上级 748c5e43
......@@ -275,6 +275,34 @@ class goo
await TestInRegularAndScriptAsync(text, expected, options: PreferExpressionBodiedAccessorsWhenOnSingleLine);
}
[Fact, Trait(Traits.Feature, Traits.Features.ConvertAutoPropertyToFullProperty)]
public async Task WithExpressionBodyWhenOnSingleLine2()
{
var text = @"
class goo
{
public int G[||]oo
{
get;
set;
}
}
";
var expected = @"
class goo
{
private int _goo;
public int Goo
{
get => _goo;
set => _goo = value;
}
}
";
await TestInRegularAndScriptAsync(text, expected, options: PreferExpressionBodiedAccessorsWhenOnSingleLine);
}
[Fact, Trait(Traits.Feature, Traits.Features.ConvertAutoPropertyToFullProperty)]
public async Task WithExpressionBodyWithTrivia()
{
......
......@@ -20,14 +20,14 @@ Class C
End Class"
Dim expected = "
Class C
Private _test1 As Integer
Private _Test1 As Integer
Public Property Test1 As Integer
Get
Return _test1
Return _Test1
End Get
Set
_test1 = Value
_Test1 = Value
End Set
End Property
End Class"
......@@ -42,14 +42,14 @@ Class C
End Class"
Dim expected = "
Class C
Private _test2 As Integer = 4
Private _Test2 As Integer = 4
Public Property Test2 As Integer
Get
Return _test2
Return _Test2
End Get
Set
_test2 = Value
_Test2 = Value
End Set
End Property
End Class"
......@@ -64,11 +64,11 @@ Class C
End Class"
Dim expected = "
Class C
Private ReadOnly _test5 As String
Private ReadOnly _Test5 As String
Public ReadOnly Property Test5 As String
Get
Return _test5
Return _Test5
End Get
End Property
End Class"
......@@ -83,11 +83,11 @@ Class C
End Class"
Dim expected = "
Class C
Private ReadOnly _test4 As String = ""Initial Value""
Private ReadOnly _Test4 As String = ""Initial Value""
Public ReadOnly Property Test4 As String
Get
Return _test4
Return _Test4
End Get
End Property
End Class"
......@@ -103,14 +103,14 @@ Class C
End Class"
Dim expected = "
Class C
Private _test4 As String
Private _Test4 As String
Private Property Test4 As String
Get
Return _test4
Return _Test4
End Get
Set
_test4 = Value
_Test4 = Value
End Set
End Property
End Class"
......@@ -128,14 +128,14 @@ Class C
End Class"
Dim expected = "
Class C
Private _test1 As Integer
Private _Test1 As Integer
'' Comment before
Public Property Test1 As Integer ''Comment during
Get
Return _test1
Return _Test1
End Get
Set
_test1 = Value
_Test1 = Value
End Set
End Property
'' Comment after
......@@ -153,14 +153,14 @@ End Class"
Dim expected = "
Class C
Private Shared s_test1 As Double
Private Shared _Test1 As Double
Public Shared Property Test1 As Double
Get
Return s_test1
Return _Test1
End Get
Set
s_test1 = Value
_Test1 = Value
End Set
End Property
End Class"
......@@ -176,14 +176,14 @@ End Class"
Dim expected = "
Class C
Private _test4 As Decimal
Private _Test4 As Decimal
Public Overridable Property Test4 As Decimal
Get
Return _test4
Return _Test4
End Get
Set
_test4 = Value
_Test4 = Value
End Set
End Property
End Class"
......
......@@ -96,7 +96,7 @@ internal override SyntaxNode GetProperty(SyntaxToken token)
return accessorDeclarationSyntax
.WithExpressionBody(arrowExpression)
.WithBody(null)
.WithSemicolonToken(semicolonToken)
.WithSemicolonToken(accessorDeclarationSyntax.SemicolonToken)
.WithAdditionalAnnotations(Formatter.Annotation);
}
......
......@@ -163,9 +163,9 @@ private string GenerateFieldName(IPropertySymbol property, ImmutableArray<Naming
var accessorTuple = GetNewAccessors(options, property,fieldName, generator);
var fullProperty = generator
.WithAccessorDeclarations(
GetPropertyWithoutInitializer(property),
accessorTuple.newSetAccessor == null
? new SyntaxNode[] { accessorTuple.newGetAccessor }
GetPropertyWithoutInitializer(property),
accessorTuple.newSetAccessor == null
? new SyntaxNode[] { accessorTuple.newGetAccessor }
: new SyntaxNode[] { accessorTuple.newGetAccessor, accessorTuple.newSetAccessor })
.WithLeadingTrivia(property.GetLeadingTrivia());
fullProperty = ConvertPropertyToExpressionBodyIfDesired(options,fullProperty);
......@@ -190,9 +190,8 @@ private string GenerateFieldName(IPropertySymbol property, ImmutableArray<Naming
private class ConvertAutoPropertyToFullPropertyCodeAction : CodeAction.DocumentChangeAction
{
public ConvertAutoPropertyToFullPropertyCodeAction(
string Title,
Func<CancellationToken,
Task<Document>> createChangedDocument) : base(Title, createChangedDocument)
string title,
Func<CancellationToken, Task<Document>> createChangedDocument) : base(title, createChangedDocument)
{
}
}
......
......@@ -13,6 +13,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ConvertAutoPropertyToFullProperty
Friend Class VisualBasicConvertAutoPropertyToFullPropertyCodeRefactoringProvider
Inherits AbstractConvertAutoPropertyToFullPropertyCodeRefactoringProvider
Private Const Underscore As String = "_"
Friend Overrides Function GetProperty(token As SyntaxToken) As SyntaxNode
Dim containingProperty = token.Parent.FirstAncestorOrSelf(Of PropertyStatementSyntax)
If containingProperty Is Nothing Then
......@@ -79,7 +81,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ConvertAutoPropertyToFullProperty
' In VB, auto properties have an implicit backing field that is named using the property
' name preceded by an underscore. We will use this as the field name so we don't mess up
' any existing references to this field.
Return fieldName
Return Underscore + propertySymbol.Name
End Function
Friend Overrides Function GetTypeBlock(syntaxNode As SyntaxNode) As SyntaxNode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册