Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3069891d
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3069891d
编写于
11月 07, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Indent code when converting a property to a method.
上级
f6adbb43
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
113 addition
and
6 deletion
+113
-6
src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs
...placeMethodWithProperty/ReplaceMethodWithPropertyTests.cs
+34
-0
src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs
...acePropertyWithMethods/ReplacePropertyWithMethodsTests.cs
+34
-0
src/EditorFeatures/VisualBasicTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.vb
...acePropertyWithMethods/ReplacePropertyWithMethodsTests.vb
+25
-0
src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs
...rtyWithMethods/CSharpReplacePropertyWithMethodsService.cs
+8
-2
src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs
...yWithMethods/AbstractReplacePropertyWithMethodsService.cs
+1
-1
src/Features/VisualBasic/Portable/ReplacePropertyWithMethods/VisualBasicReplacePropertyWithMethods.vb
...pertyWithMethods/VisualBasicReplacePropertyWithMethods.vb
+11
-3
未找到文件。
src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs
浏览文件 @
3069891d
...
...
@@ -156,6 +156,40 @@ int Foo
compareTokens
:
false
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplaceMethodWithProperty
)]
public
async
Task
TestIndentation
()
{
await
TestAsync
(
@"class C
{
int [||]GetFoo()
{
int count;
foreach (var x in y)
{
count += bar;
}
return count;
}
}"
,
@"class C
{
int Foo
{
get
{
int count;
foreach (var x in y)
{
count += bar;
}
return count;
}
}
}"
,
compareTokens
:
false
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplaceMethodWithProperty
)]
public
async
Task
TestIfDefMethod
()
{
...
...
src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs
浏览文件 @
3069891d
...
...
@@ -637,6 +637,40 @@ private int GetProp()
}"
,
compareTokens
:
false
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplaceMethodWithProperty
)]
public
async
Task
TestIndentation
()
{
await
TestAsync
(
@"class C
{
int [||]Foo
{
get
{
int count;
foreach (var x in y)
{
count += bar;
}
return count;
}
}
}"
,
@"class C
{
int GetFoo()
{
int count;
foreach (var x in y)
{
count += bar;
}
return count;
}
}"
,
compareTokens
:
false
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplacePropertyWithMethods
)]
public
async
Task
TestComputedPropWithTrailingTriviaAfterArrow
()
{
...
...
src/EditorFeatures/VisualBasicTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.vb
浏览文件 @
3069891d
...
...
@@ -27,6 +27,31 @@ end class",
end class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplacePropertyWithMethods
)
>
Public
Async
Function
TestIndentation
()
As
Task
Await
TestAsync
(
"class C
readonly property [||]Prop as integer
get
dim count = 0
for each x in y
count = count + z
next
reutrn count
end get
end property
end class"
,
"class C
Public Function GetProp() As Integer
dim count = 0
for each x in y
count = count + z
next
reutrn count
End Function
end class"
,
compareTokens
:
=
False
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsReplacePropertyWithMethods
)
>
Public
Async
Function
TestPrivateProperty
()
As
Task
Await
TestAsync
(
...
...
src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs
浏览文件 @
3069891d
...
...
@@ -7,6 +7,8 @@
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.ReplacePropertyWithMethods
;
using
Roslyn.Utilities
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.Formatting
;
namespace
Microsoft.CodeAnalysis.CSharp.ReplacePropertyWithMethods
{
...
...
@@ -107,7 +109,7 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
var
statements
=
new
List
<
SyntaxNode
>();
if
(
setAccessorDeclaration
?.
Body
!=
null
)
{
statements
.
AddRange
(
setAccessorDeclaration
?.
Body
?.
Statements
);
statements
.
AddRange
(
setAccessorDeclaration
.
Body
.
Statements
.
Select
(
WithMarkerAndAnnotation
)
);
}
else
if
(
propertyBackingField
!=
null
)
{
...
...
@@ -120,6 +122,10 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
return
generator
.
MethodDeclaration
(
setMethod
,
desiredSetMethodName
,
statements
);
}
private
static
StatementSyntax
WithMarkerAndAnnotation
(
StatementSyntax
statement
)
=>
statement
.
WithPrependedLeadingTrivia
(
SyntaxFactory
.
ElasticMarker
)
.
WithAdditionalAnnotations
(
Formatter
.
Annotation
);
private
static
SyntaxNode
GetGetMethod
(
SyntaxGenerator
generator
,
PropertyDeclarationSyntax
propertyDeclaration
,
...
...
@@ -146,7 +152,7 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
var
getAccessorDeclaration
=
(
AccessorDeclarationSyntax
)
getMethod
.
DeclaringSyntaxReferences
[
0
].
GetSyntax
(
cancellationToken
);
if
(
getAccessorDeclaration
?.
Body
!=
null
)
{
statements
.
AddRange
(
getAccessorDeclaration
.
Body
.
Statements
);
statements
.
AddRange
(
getAccessorDeclaration
.
Body
.
Statements
.
Select
(
WithMarkerAndAnnotation
)
);
}
else
if
(
propertyBackingField
!=
null
)
{
...
...
src/Features/Core/Portable/ReplacePropertyWithMethods/AbstractReplacePropertyWithMethodsService.cs
浏览文件 @
3069891d
...
...
@@ -392,4 +392,4 @@ public ReplaceParentArgs(ReferenceReplacer replacer, GetWriteValue getWriteValue
}
}
}
}
}
\ No newline at end of file
src/Features/VisualBasic/Portable/ReplacePropertyWithMethods/VisualBasicReplacePropertyWithMethods.vb
浏览文件 @
3069891d
Imports
System.Composition
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports
System.Composition
Imports
System.Threading
Imports
Microsoft.CodeAnalysis.Editing
Imports
Microsoft.CodeAnalysis.Formatting
Imports
Microsoft.CodeAnalysis.Host.Mef
Imports
Microsoft.CodeAnalysis.ReplacePropertyWithMethods
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -108,7 +111,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
If
TypeOf
getAccessorDeclaration
?
.
Parent
Is
AccessorBlockSyntax
Then
Dim
block
=
DirectCast
(
getAccessorDeclaration
.
Parent
,
AccessorBlockSyntax
)
statements
.
AddRange
(
block
.
Statements
)
statements
.
AddRange
(
block
.
Statements
.
Select
(
AddressOf
WithMarkerAndAnnotation
)
)
ElseIf
propertyBackingField
IsNot
Nothing
Then
Dim
fieldReference
=
GetFieldReference
(
generator
,
propertyBackingField
)
statements
.
Add
(
generator
.
ReturnStatement
(
fieldReference
))
...
...
@@ -117,6 +120,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
Return
generator
.
MethodDeclaration
(
getMethod
,
desiredGetMethodName
,
statements
)
End
Function
Private
Shared
Function
WithMarkerAndAnnotation
(
statement
As
StatementSyntax
)
As
StatementSyntax
Return
statement
.
WithPrependedLeadingTrivia
(
SyntaxFactory
.
ElasticMarker
).
WithAdditionalAnnotations
(
Formatter
.
Annotation
)
End
Function
Private
Function
GetSetMethod
(
generator
As
SyntaxGenerator
,
propertyStatement
As
PropertyStatementSyntax
,
...
...
@@ -132,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ReplaceMethodWithP
If
TypeOf
setAccessorDeclaration
?
.
Parent
Is
AccessorBlockSyntax
Then
Dim
block
=
DirectCast
(
setAccessorDeclaration
.
Parent
,
AccessorBlockSyntax
)
statements
.
AddRange
(
block
.
Statements
)
statements
.
AddRange
(
block
.
Statements
.
Select
(
AddressOf
WithMarkerAndAnnotation
)
)
ElseIf
propertyBackingField
IsNot
Nothing
Then
Dim
fieldReference
=
GetFieldReference
(
generator
,
propertyBackingField
)
statements
.
Add
(
generator
.
AssignmentStatement
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录