Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
10e4e3b0
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,发现更多精彩内容 >>
提交
10e4e3b0
编写于
9月 08, 2015
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add an (internal) overload to Rename to allow features to rename a subset of locations.
上级
e9dbd805
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
50 deletion
+61
-50
src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs
...table/EncapsulateField/AbstractEncapsulateFieldService.cs
+43
-48
src/Workspaces/Core/Portable/Rename/Renamer.cs
src/Workspaces/Core/Portable/Rename/Renamer.cs
+18
-2
未找到文件。
src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs
浏览文件 @
10e4e3b0
...
...
@@ -180,7 +180,8 @@ private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document do
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
compilation
=
semanticModel
.
Compilation
;
field
=
field
.
GetSymbolKey
().
Resolve
(
compilation
,
cancellationToken
:
cancellationToken
).
Symbol
as
IFieldSymbol
;
Solution
solutionNeedingProperty
=
null
;
var
solutionNeedingProperty
=
solution
;
// We couldn't resolve field after annotating its declaration. Bail
if
(
field
==
null
)
...
...
@@ -188,53 +189,9 @@ private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document do
return
null
;
}
if
(
updateReferences
)
{
var
locationsToIgnore
=
SpecializedCollections
.
EmptySet
<
TextSpan
>();
var
optionSet
=
document
.
Project
.
Solution
.
Workspace
.
Options
;
if
(
field
.
IsReadOnly
)
{
var
locationSet
=
await
RenameLocationSet
.
FindAsync
(
field
,
document
.
Project
.
Solution
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
var
constructorSyntaxes
=
GetConstructorNodes
(
field
.
ContainingType
);
var
locations
=
locationSet
.
Locations
.
Where
(
l
=>
constructorSyntaxes
.
Any
(
c
=>
c
.
Span
.
IntersectsWith
(
l
.
Location
.
SourceSpan
)));
if
(
locations
.
Any
())
{
locationsToIgnore
=
locations
.
Select
(
l
=>
l
.
Location
.
SourceSpan
).
ToSet
();
locationSet
=
new
RenameLocationSet
(
locations
.
ToSet
(),
field
,
document
.
Project
.
Solution
,
locationSet
.
ReferencedSymbols
,
locationSet
.
ImplicitLocations
);
var
resolution
=
await
ConflictResolver
.
ResolveConflictsAsync
(
locationSet
,
field
.
Name
,
finalFieldName
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
document
=
resolution
.
NewSolution
.
GetDocument
(
document
.
Id
);
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
compilation
=
semanticModel
.
Compilation
;
field
=
field
.
GetSymbolKey
().
Resolve
(
compilation
,
cancellationToken
:
cancellationToken
).
Symbol
as
IFieldSymbol
;
}
}
var
renameLocationSet
=
await
RenameLocationSet
.
FindAsync
(
field
,
document
.
Project
.
Solution
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
renameLocationSet
=
new
RenameLocationSet
(
renameLocationSet
.
Locations
.
Where
(
l
=>
!
locationsToIgnore
.
Contains
(
l
.
Location
.
SourceSpan
)).
ToSet
(),
renameLocationSet
.
Symbol
,
renameLocationSet
.
Solution
,
renameLocationSet
.
ReferencedSymbols
,
renameLocationSet
.
ImplicitLocations
);
if
(
renameLocationSet
.
Locations
.
Any
()
||
renameLocationSet
.
ImplicitLocations
.
Any
())
{
var
conflictResolution
=
await
ConflictResolver
.
ResolveConflictsAsync
(
renameLocationSet
,
field
.
Name
,
generatedPropertyName
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(!
conflictResolution
.
ReplacementTextValid
)
{
return
null
;
}
solutionNeedingProperty
=
conflictResolution
.
NewSolution
;
document
=
solutionNeedingProperty
.
GetDocument
(
document
.
Id
);
}
}
else
{
solutionNeedingProperty
=
document
.
Project
.
Solution
;
document
=
solutionNeedingProperty
.
GetDocument
(
document
.
Id
);
}
solutionNeedingProperty
=
await
UpdateReferencesAsync
(
updateReferences
,
solution
,
document
,
field
,
finalFieldName
,
generatedPropertyName
,
cancellationToken
).
ConfigureAwait
(
false
);
document
=
solutionNeedingProperty
.
GetDocument
(
document
.
Id
);
var
markFieldPrivate
=
field
.
DeclaredAccessibility
!=
Accessibility
.
Private
;
var
rewrittenFieldDeclaration
=
await
RewriteFieldNameAndAccessibility
(
finalFieldName
,
markFieldPrivate
,
document
,
declarationAnnotation
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -267,6 +224,44 @@ private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document do
return
new
Result
(
solutionWithProperty
,
originalField
.
ToDisplayString
(),
originalField
.
GetGlyph
());
}
private
async
Task
<
Solution
>
UpdateReferencesAsync
(
bool
updateReferences
,
Solution
solution
,
Document
document
,
IFieldSymbol
field
,
string
finalFieldName
,
string
generatedPropertyName
,
CancellationToken
cancellationToken
)
{
if
(!
updateReferences
)
{
return
solution
;
}
var
locationsToIgnore
=
SpecializedCollections
.
EmptySet
<
TextSpan
>();
var
optionSet
=
document
.
Project
.
Solution
.
Workspace
.
Options
;
if
(
field
.
IsReadOnly
)
{
// Inside the constructor we want to rename references the field to the final field name.
var
constructorSyntaxes
=
GetConstructorNodes
(
field
.
ContainingType
).
ToSet
();
if
(
finalFieldName
!=
field
.
Name
&&
constructorSyntaxes
.
Count
>
0
)
{
solution
=
await
Renamer
.
RenameSymbolAsync
(
solution
,
field
,
finalFieldName
,
solution
.
Workspace
.
Options
,
location
=>
constructorSyntaxes
.
Any
(
c
=>
c
.
Span
.
IntersectsWith
(
location
.
SourceSpan
)),
cancellationToken
).
ConfigureAwait
(
false
);
document
=
solution
.
GetDocument
(
document
.
Id
);
var
compilation
=
await
document
.
Project
.
GetCompilationAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
field
=
field
.
GetSymbolKey
().
Resolve
(
compilation
,
cancellationToken
:
cancellationToken
).
Symbol
as
IFieldSymbol
;
}
// Outside the constructor we want to rename references to the field to final property name.
solution
=
await
Renamer
.
RenameSymbolAsync
(
solution
,
field
,
generatedPropertyName
,
solution
.
Workspace
.
Options
,
location
=>
!
constructorSyntaxes
.
Any
(
c
=>
c
.
Span
.
IntersectsWith
(
location
.
SourceSpan
)),
cancellationToken
).
ConfigureAwait
(
false
);
return
solution
;
}
else
{
// Just rename everything.
return
await
Renamer
.
RenameSymbolAsync
(
solution
,
field
,
generatedPropertyName
,
solution
.
Workspace
.
Options
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
internal
abstract
IEnumerable
<
SyntaxNode
>
GetConstructorNodes
(
INamedTypeSymbol
containingType
);
protected
async
Task
<
Solution
>
AddPropertyAsync
(
Document
document
,
Solution
destinationSolution
,
IFieldSymbol
field
,
IPropertySymbol
property
,
CancellationToken
cancellationToken
)
...
...
src/Workspaces/Core/Portable/Rename/Renamer.cs
浏览文件 @
10e4e3b0
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Rename.ConflictEngine
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Rename
{
public
static
class
Renamer
{
public
static
async
Task
<
Solution
>
RenameSymbolAsync
(
Solution
solution
,
ISymbol
symbol
,
string
newName
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
public
static
Task
<
Solution
>
RenameSymbolAsync
(
Solution
solution
,
ISymbol
symbol
,
string
newName
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
return
RenameSymbolAsync
(
solution
,
symbol
,
newName
,
optionSet
,
filter
:
null
,
cancellationToken
:
cancellationToken
);
}
internal
static
async
Task
<
Solution
>
RenameSymbolAsync
(
Solution
solution
,
ISymbol
symbol
,
string
newName
,
OptionSet
optionSet
,
Func
<
Location
,
bool
>
filter
,
CancellationToken
cancellationToken
)
{
if
(
solution
==
null
)
{
...
...
@@ -30,7 +38,15 @@ public static async Task<Solution> RenameSymbolAsync(Solution solution, ISymbol
optionSet
=
optionSet
??
solution
.
Workspace
.
Options
;
var
renameLocationSet
=
await
RenameLocationSet
.
FindAsync
(
symbol
,
solution
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
var
conflictResolution
=
await
ConflictEngine
.
ConflictResolver
.
ResolveConflictsAsync
(
renameLocationSet
,
symbol
.
Name
,
newName
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
filter
!=
null
)
{
renameLocationSet
=
new
RenameLocationSet
(
renameLocationSet
.
Locations
.
Where
(
loc
=>
filter
(
loc
.
Location
)).
ToSet
(),
renameLocationSet
.
Symbol
,
renameLocationSet
.
Solution
,
renameLocationSet
.
ReferencedSymbols
,
renameLocationSet
.
ImplicitLocations
);
}
var
conflictResolution
=
await
ConflictResolver
.
ResolveConflictsAsync
(
renameLocationSet
,
symbol
.
Name
,
newName
,
optionSet
,
cancellationToken
).
ConfigureAwait
(
false
);
return
conflictResolution
.
NewSolution
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录