Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fd183af6
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,发现更多精彩内容 >>
提交
fd183af6
编写于
12月 05, 2018
作者:
A
Andrew Hall (METAL)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restore async name. Add SymbolMapping type to reduce clutter
上级
b2fbde4e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
21 deletion
+38
-21
src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs
...table/ExtractInterface/AbstractExtractInterfaceService.cs
+37
-20
src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs
...tractInterface/ExtractInterfaceCodeRefactoringProvider.cs
+1
-1
未找到文件。
src/Features/Core/Portable/ExtractInterface/AbstractExtractInterfaceService.cs
浏览文件 @
fd183af6
...
...
@@ -24,6 +24,26 @@ namespace Microsoft.CodeAnalysis.ExtractInterface
{
internal
abstract
class
AbstractExtractInterfaceService
:
ILanguageService
{
private
struct
SymbolMapping
{
public
SymbolMapping
(
Dictionary
<
ISymbol
,
SyntaxAnnotation
>
symbolToDeclarationAnnotationMap
,
Solution
annotatedSolution
,
List
<
DocumentId
>
documentIds
,
SyntaxAnnotation
typeNodeAnnotation
)
{
SymbolToDeclarationAnnotationMap
=
symbolToDeclarationAnnotationMap
;
AnnotatedSolution
=
annotatedSolution
;
DocumentIds
=
documentIds
;
TypeNodeAnnotation
=
typeNodeAnnotation
;
}
public
Dictionary
<
ISymbol
,
SyntaxAnnotation
>
SymbolToDeclarationAnnotationMap
{
get
;
}
public
Solution
AnnotatedSolution
{
get
;
}
public
List
<
DocumentId
>
DocumentIds
{
get
;
}
public
SyntaxAnnotation
TypeNodeAnnotation
{
get
;
}
}
internal
abstract
Task
<
SyntaxNode
>
GetTypeDeclarationAsync
(
Document
document
,
int
position
,
...
...
@@ -45,7 +65,7 @@ internal abstract class AbstractExtractInterfaceService : ILanguageService
internal
abstract
bool
ShouldIncludeAccessibilityModifier
(
SyntaxNode
typeNode
);
public
async
Task
<
ImmutableArray
<
ExtractInterfaceCodeAction
>>
GetExtractInterfaceCodeAction
(
Document
document
,
TextSpan
span
,
CancellationToken
cancellationToken
)
public
async
Task
<
ImmutableArray
<
ExtractInterfaceCodeAction
>>
GetExtractInterfaceCodeAction
Async
(
Document
document
,
TextSpan
span
,
CancellationToken
cancellationToken
)
{
var
typeAnalysisResult
=
await
AnalyzeTypeAtPositionAsync
(
document
,
span
.
Start
,
TypeDiscoveryRule
.
TypeNameOnly
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -175,16 +195,18 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
Solution
solution
,
string
containingNamespaceDisplay
,
INamedTypeSymbol
extractedInterfaceSymbol
,
ExtractInterfaceTypeAnalysisResult
refactoringResult
,
ExtractInterfaceOptionsResult
extractInterfaceOptions
,
CancellationToken
cancellationToken
)
{
var
(
symbolToDeclarationAnnotationMap
,
annotatedSolution
,
documentIds
,
typeNodeSyntaxAnnotation
)
=
CreateSymbolToDeclarationAnnotationMap
(
var
symbolMapping
=
CreateSymbolToDeclarationAnnotationMap
(
extractInterfaceOptions
.
IncludedMembers
,
solution
,
refactoringResult
.
TypeNode
,
cancellationToken
);
var
interfaceDocumentId
=
DocumentId
.
CreateNewId
(
refactoringResult
.
DocumentToExtractFrom
.
Project
.
Id
,
debugName
:
extractInterfaceOptions
.
FileName
);
var
unformattedInterfaceDocument
=
GetUnformattedInterfaceDocument
(
a
nnotatedSolution
,
symbolMapping
.
A
nnotatedSolution
,
containingNamespaceDisplay
,
extractInterfaceOptions
.
FileName
,
refactoringResult
.
DocumentToExtractFrom
.
Folders
,
...
...
@@ -199,13 +221,13 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
var
completedSolution
=
GetSolutionWithOriginalTypeUpdated
(
solutionWithFormattedInterfaceDocument
,
d
ocumentIds
,
symbolMapping
.
D
ocumentIds
,
refactoringResult
.
DocumentToExtractFrom
.
Id
,
typeNodeSyntax
Annotation
,
symbolMapping
.
TypeNode
Annotation
,
refactoringResult
.
TypeToExtractFrom
,
extractedInterfaceSymbol
,
extractInterfaceOptions
.
IncludedMembers
,
symbolToDeclarationAnnotationMap
,
symbol
Mapping
.
Symbol
ToDeclarationAnnotationMap
,
cancellationToken
);
return
new
ExtractInterfaceResult
(
...
...
@@ -219,20 +241,20 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
ExtractInterfaceOptionsResult
extractInterfaceOptions
,
CancellationToken
cancellationToken
)
{
// Track all of the symbols we need to modify, which includes the original type declaration being modified
var
(
symbolToDeclarationAnnotationMap
,
annotatedSolution
,
documentIds
,
typeNodeSyntaxAnnotation
)
=
CreateSymbolToDeclarationAnnotationMap
(
var
symbolMapping
=
CreateSymbolToDeclarationAnnotationMap
(
extractInterfaceOptions
.
IncludedMembers
,
solution
,
refactoringResult
.
TypeNode
,
cancellationToken
);
var
document
=
a
nnotatedSolution
.
GetDocument
(
refactoringResult
.
DocumentToExtractFrom
.
Id
);
var
document
=
symbolMapping
.
A
nnotatedSolution
.
GetDocument
(
refactoringResult
.
DocumentToExtractFrom
.
Id
);
var
originalRoot
=
document
.
GetSyntaxRootSynchronously
(
cancellationToken
);
var
typeDeclaration
=
originalRoot
.
GetAnnotatedNodes
(
typeNodeSyntax
Annotation
).
Single
();
var
typeDeclaration
=
originalRoot
.
GetAnnotatedNodes
(
symbolMapping
.
TypeNode
Annotation
).
Single
();
var
trackedDocument
=
document
.
WithSyntaxRoot
(
originalRoot
.
TrackNodes
(
typeDeclaration
));
var
currentRoot
=
trackedDocument
.
GetSyntaxRootSynchronously
(
cancellationToken
);
var
editor
=
new
SyntaxEditor
(
currentRoot
,
a
nnotatedSolution
.
Workspace
);
var
editor
=
new
SyntaxEditor
(
currentRoot
,
symbolMapping
.
A
nnotatedSolution
.
Workspace
);
// Generate the interface syntax node, which will be inserted above the type it's extracted from
var
codeGenService
=
trackedDocument
.
GetLanguageService
<
ICodeGenerationService
>();
...
...
@@ -245,10 +267,10 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
// After the interface is inserted, update the original type to show it implements the new interface
var
completedSolution
=
GetSolutionWithOriginalTypeUpdated
(
unformattedSolution
,
d
ocumentIds
,
refactoringResult
.
DocumentToExtractFrom
.
Id
,
typeNodeSyntax
Annotation
,
unformattedSolution
,
symbolMapping
.
D
ocumentIds
,
refactoringResult
.
DocumentToExtractFrom
.
Id
,
symbolMapping
.
TypeNode
Annotation
,
refactoringResult
.
TypeToExtractFrom
,
extractedInterfaceSymbol
,
extractInterfaceOptions
.
IncludedMembers
,
symbolToDeclarationAnnotationMap
,
cancellationToken
);
extractInterfaceOptions
.
IncludedMembers
,
symbol
Mapping
.
Symbol
ToDeclarationAnnotationMap
,
cancellationToken
);
return
new
ExtractInterfaceResult
(
succeeded
:
true
,
...
...
@@ -256,12 +278,7 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
navigationDocumentId
:
refactoringResult
.
DocumentToExtractFrom
.
Id
);
}
private
(
Dictionary
<
ISymbol
,
SyntaxAnnotation
>
symbolToDeclarationAnnotationMap
,
Solution
annotatedSolution
,
List
<
DocumentId
>
documentIds
,
SyntaxAnnotation
typeNodeAnnotation
)
CreateSymbolToDeclarationAnnotationMap
(
private
SymbolMapping
CreateSymbolToDeclarationAnnotationMap
(
IEnumerable
<
ISymbol
>
includedMembers
,
Solution
solution
,
SyntaxNode
typeNode
,
...
...
@@ -300,7 +317,7 @@ public ExtractInterfaceResult ExtractInterfaceFromAnalyzedType(ExtractInterfaceT
annotatedSolution
=
document
.
WithSyntaxRoot
(
root
.
Value
).
Project
.
Solution
;
}
return
(
symbolToDeclarationAnnotationMap
,
annotatedSolution
,
documentIds
,
typeNodeAnnotation
);
return
new
SymbolMapping
(
symbolToDeclarationAnnotationMap
,
annotatedSolution
,
documentIds
,
typeNodeAnnotation
);
}
internal
ExtractInterfaceOptionsResult
GetExtractInterfaceOptions
(
...
...
src/Features/Core/Portable/ExtractInterface/ExtractInterfaceCodeRefactoringProvider.cs
浏览文件 @
fd183af6
...
...
@@ -14,7 +14,7 @@ internal class ExtractInterfaceCodeRefactoringProvider : CodeRefactoringProvider
public
sealed
override
async
Task
ComputeRefactoringsAsync
(
CodeRefactoringContext
context
)
{
var
service
=
context
.
Document
.
GetLanguageService
<
AbstractExtractInterfaceService
>();
var
actions
=
await
service
.
GetExtractInterfaceCodeAction
(
context
.
Document
,
context
.
Span
,
context
.
CancellationToken
).
ConfigureAwait
(
false
);
var
actions
=
await
service
.
GetExtractInterfaceCodeAction
Async
(
context
.
Document
,
context
.
Span
,
context
.
CancellationToken
).
ConfigureAwait
(
false
);
context
.
RegisterRefactorings
(
actions
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录