Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0dbf0b99
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,发现更多精彩内容 >>
提交
0dbf0b99
编写于
9月 19, 2019
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address review comments
上级
b5d8348b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
28 deletion
+80
-28
src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
...atures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
+44
-0
src/Features/CSharp/Portable/MoveToNamespace/CSharpMoveToNamespaceService.cs
.../Portable/MoveToNamespace/CSharpMoveToNamespaceService.cs
+7
-12
src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs
...ortable/MoveToNamespace/AbstractMoveToNamespaceService.cs
+29
-16
未找到文件。
src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
浏览文件 @
0dbf0b99
...
...
@@ -1162,6 +1162,50 @@ public Task MoveToNamespace_MoveOneTypeInGlobalNamespace()
class MyClass2
{
}"
,
expectedSuccess
:
false
);
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MoveToNamespace
)]
[
WorkItem
(
980758
,
"https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758"
)]
public
Task
MoveToNamespace_PartialTypesInNamesapce_SelectType
()
=>
TestMoveToNamespaceAsync
(
@"namespace NS
{
partial class MyClass[||]
{
}
partial class MyClass
{
}
}"
,
expectedSuccess
:
false
);
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MoveToNamespace
)]
[
WorkItem
(
980758
,
"https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758"
)]
public
Task
MoveToNamespace_PartialTypesInNamesapce_SelectNamespace
()
=>
TestMoveToNamespaceAsync
(
@"namespace NS[||]
{
partial class MyClass
{
}
partial class MyClass
{
}
}"
,
expectedSuccess
:
false
);
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MoveToNamespace
)]
[
WorkItem
(
980758
,
"https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980758"
)]
public
Task
MoveToNamespace_PartialTypesInGlobalNamesapce
()
=>
TestMoveToNamespaceAsync
(
@"partial class MyClass[||]
{
}
partial class MyClass
{
}"
,
expectedSuccess
:
false
);
}
...
...
src/Features/CSharp/Portable/MoveToNamespace/CSharpMoveToNamespaceService.cs
浏览文件 @
0dbf0b99
...
...
@@ -5,6 +5,7 @@
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.MoveToNamespace
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp.MoveToNamespace
{
...
...
@@ -20,19 +21,13 @@ internal class CSharpMoveToNamespaceService :
{
}
protected
override
string
GetNamespaceName
(
NamespaceDeclarationSyntax
namespaceSyntax
)
=>
namespaceSyntax
.
Name
.
ToString
();
protected
override
string
GetNamespaceName
(
TypeDeclarationSyntax
typeDeclarationSyntax
)
{
var
namespaceDecl
=
typeDeclarationSyntax
.
FirstAncestorOrSelf
<
NamespaceDeclarationSyntax
>();
if
(
namespaceDecl
==
null
)
protected
override
string
GetNamespaceName
(
SyntaxNode
container
)
=>
container
switch
{
return
string
.
Empty
;
}
return
GetNamespaceName
(
namespaceDecl
);
}
NamespaceDeclarationSyntax
namespaceSyntax
=>
namespaceSyntax
.
Name
.
ToString
(),
CompilationUnitSyntax
compilationUnit
=>
string
.
Empty
,
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
container
)
};
protected
override
bool
IsContainedInNamespaceDeclaration
(
NamespaceDeclarationSyntax
namespaceDeclaration
,
int
position
)
{
...
...
src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs
浏览文件 @
0dbf0b99
...
...
@@ -33,8 +33,7 @@ internal abstract class AbstractMoveToNamespaceService<TCompilationUnitSyntax, T
where
TNamedTypeDeclarationSyntax
:
SyntaxNode
{
protected
abstract
string
GetNamespaceName
(
TNamespaceDeclarationSyntax
namespaceSyntax
);
protected
abstract
string
GetNamespaceName
(
TNamedTypeDeclarationSyntax
namedTypeSyntax
);
protected
abstract
string
GetNamespaceName
(
SyntaxNode
namespaceSyntax
);
protected
abstract
bool
IsContainedInNamespaceDeclaration
(
TNamespaceDeclarationSyntax
namespaceSyntax
,
int
position
);
public
IMoveToNamespaceOptionsService
OptionsService
{
get
;
}
...
...
@@ -95,16 +94,19 @@ protected AbstractMoveToNamespaceService(IMoveToNamespaceOptionsService moveToNa
}
// The underlying ChangeNamespace service doesn't support nested namespace decalration.
if
(
GetNamespaceInSpineCount
(
declarationSyntax
)
>
1
)
if
(
GetNamespaceInSpineCount
(
declarationSyntax
)
==
1
)
{
return
MoveToNamespaceAnalysisResult
.
Invalid
;
}
else
{
var
namespaceName
=
GetNamespaceName
(
declarationSyntax
);
var
namespaces
=
await
GetNamespacesAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
MoveToNamespaceAnalysisResult
(
document
,
declarationSyntax
,
namespaceName
,
namespaces
.
ToImmutableArray
(),
MoveToNamespaceAnalysisResult
.
ContainerType
.
Namespace
);
var
changeNamespaceService
=
document
.
GetLanguageService
<
IChangeNamespaceService
>();
if
(
await
changeNamespaceService
.
CanChangeNamespaceAsync
(
document
,
declarationSyntax
,
cancellationToken
).
ConfigureAwait
(
false
))
{
var
namespaceName
=
GetNamespaceName
(
declarationSyntax
);
var
namespaces
=
await
GetNamespacesAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
MoveToNamespaceAnalysisResult
(
document
,
declarationSyntax
,
namespaceName
,
namespaces
.
ToImmutableArray
(),
MoveToNamespaceAnalysisResult
.
ContainerType
.
Namespace
);
}
}
return
MoveToNamespaceAnalysisResult
.
Invalid
;
}
private
async
Task
<
MoveToNamespaceAnalysisResult
>
TryAnalyzeNamedTypeAsync
(
...
...
@@ -118,14 +120,16 @@ protected AbstractMoveToNamespaceService(IMoveToNamespaceOptionsService moveToNa
return
MoveToNamespaceAnalysisResult
.
Invalid
;
}
SyntaxNode
container
=
null
;
// Moving one of the many members declared in global namespace is not currently supported,
// but if it's the only member declared, then that's fine.
if
(
namespaceInSpineCount
==
0
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
container
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
if
(
syntaxFacts
.
GetMembersOfCompilationUnit
(
root
).
Count
>
1
)
if
(
syntaxFacts
.
GetMembersOfCompilationUnit
(
container
).
Count
>
1
)
{
return
MoveToNamespaceAnalysisResult
.
Invalid
;
}
...
...
@@ -133,14 +137,23 @@ protected AbstractMoveToNamespaceService(IMoveToNamespaceOptionsService moveToNa
if
(
node
is
TNamedTypeDeclarationSyntax
namedTypeDeclarationSyntax
)
{
var
namespaceName
=
GetNamespaceName
(
namedTypeDeclarationSyntax
);
var
namespaces
=
await
GetNamespacesAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
MoveToNamespaceAnalysisResult
(
document
,
namedTypeDeclarationSyntax
,
namespaceName
,
namespaces
.
ToImmutableArray
(),
MoveToNamespaceAnalysisResult
.
ContainerType
.
NamedType
);
// If we are inside a namespace declaration, then find it as the container.
container
??=
GetContainingNamespace
(
namedTypeDeclarationSyntax
);
var
changeNamespaceService
=
document
.
GetLanguageService
<
IChangeNamespaceService
>();
if
(
await
changeNamespaceService
.
CanChangeNamespaceAsync
(
document
,
container
,
cancellationToken
).
ConfigureAwait
(
false
))
{
var
namespaces
=
await
GetNamespacesAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
MoveToNamespaceAnalysisResult
(
document
,
namedTypeDeclarationSyntax
,
GetNamespaceName
(
container
),
namespaces
.
ToImmutableArray
(),
MoveToNamespaceAnalysisResult
.
ContainerType
.
NamedType
);
}
}
return
null
;
return
MoveToNamespaceAnalysisResult
.
Invalid
;
}
private
static
TNamespaceDeclarationSyntax
GetContainingNamespace
(
TNamedTypeDeclarationSyntax
namedTypeSyntax
)
=>
namedTypeSyntax
.
FirstAncestorOrSelf
<
TNamespaceDeclarationSyntax
>();
private
static
int
GetNamespaceInSpineCount
(
SyntaxNode
node
)
=>
node
.
AncestorsAndSelf
().
OfType
<
TNamespaceDeclarationSyntax
>().
Count
()
+
node
.
DescendantNodes
().
OfType
<
TNamespaceDeclarationSyntax
>().
Count
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录