Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
8d70d17d
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
8d70d17d
编写于
7月 31, 2018
作者:
C
Carol Hu
提交者:
GitHub
7月 31, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add check for symbol.IsOverride when renaming a symbol (#28952)
Add check for symbol.IsOverride when renaming a symbol
上级
367e08d8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
3 deletion
+164
-3
src/EditorFeatures/Test2/Rename/CSharp/OverrideTests.vb
src/EditorFeatures/Test2/Rename/CSharp/OverrideTests.vb
+141
-0
src/Workspaces/Core/Portable/Rename/RenameUtilities.cs
src/Workspaces/Core/Portable/Rename/RenameUtilities.cs
+23
-3
未找到文件。
src/EditorFeatures/Test2/Rename/CSharp/OverrideTests.vb
0 → 100644
浏览文件 @
8d70d17d
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Namespace
Microsoft.CodeAnalysis.Editor.UnitTests.Rename.CSharp
<
[
UseExportProvider
]
>
Public
Class
OverrideTests
Private
ReadOnly
_outputHelper
As
Abstractions
.
ITestOutputHelper
Public
Sub
New
(
outputHelper
As
Abstractions
.
ITestOutputHelper
)
_outputHelper
=
outputHelper
End
Sub
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Rename
)
>
Public
Sub
RenameOverrideMemberFromDerivedClass
()
Using
result
=
RenameEngineResult
.
Create
(
_outputHelper
,
<
Workspace
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary1"
CommonReferences
=
"true"
>
<
Document
>
namespace
ClassLibrary1
{
public
class
Class1
{
public
virtual
void
[|
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary2"
CommonReferences
=
"true"
>
<
ProjectReference
>
ClassLibrary1
</
ProjectReference
>
<
Document
>
namespace
ClassLibrary2
{
public
class
Class2
:
ClassLibrary1
.
Class1
{
public
override
void
[|$$
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
,
renameTo
:
=
"A"
)
End
Using
End
Sub
<
WorkItem
(
25682
,
"https://github.com/dotnet/roslyn/issues/25682"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Rename
)
>
Public
Sub
RenameOverrideMemberFromDerivedClassWhenMemberIsPrivate
()
Using
result
=
RenameEngineResult
.
Create
(
_outputHelper
,
<
Workspace
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary1"
CommonReferences
=
"true"
>
<
Document
>
namespace
ClassLibrary1
{
public
class
Class1
{
public
virtual
void
[|
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary2"
CommonReferences
=
"true"
>
<
ProjectReference
>
ClassLibrary1
</
ProjectReference
>
<
Document
>
namespace
ClassLibrary2
{
public
class
Class2
:
ClassLibrary1
.
Class1
{
override
void
[|$$
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
,
renameTo
:
=
"A"
)
End
Using
End
Sub
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Rename
)
>
Public
Sub
RenameOverrideMemberFromDerivedClass_abstract_virtual
()
Using
result
=
RenameEngineResult
.
Create
(
_outputHelper
,
<
Workspace
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary1"
CommonReferences
=
"true"
>
<
Document
>
namespace
ClassLibrary1
{
public
abstract
class
Class1
{
public
abstract
void
M
()
;
}
}
</
Document
>
</
Project
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary2"
CommonReferences
=
"true"
>
<
ProjectReference
>
ClassLibrary1
</
ProjectReference
>
<
Document
>
namespace
ClassLibrary2
{
public
class
Class2
:
ClassLibrary1
.
Class1
{
virtual
void
[|$$
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
,
renameTo
:
=
"A"
)
End
Using
End
Sub
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Rename
)
>
Public
Sub
RenameOverrideMemberFromDerivedClass_abstract_override
()
Using
result
=
RenameEngineResult
.
Create
(
_outputHelper
,
<
Workspace
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary1"
CommonReferences
=
"true"
>
<
Document
>
namespace
ClassLibrary1
{
public
abstract
class
Class1
{
public
virtual
void
[|
M
|]
()
;
}
}
</
Document
>
</
Project
>
<
Project
Language
=
"C#"
AssemblyName
=
"ClassLibrary2"
CommonReferences
=
"true"
>
<
ProjectReference
>
ClassLibrary1
</
ProjectReference
>
<
Document
>
namespace
ClassLibrary2
{
public
class
Class2
:
ClassLibrary1
.
Class1
{
override
void
[|$$
M
|]
()
{
}
}
}
</
Document
>
</
Project
>
</
Workspace
>
,
renameTo
:
=
"A"
)
End
Using
End
Sub
End
Class
End
Namespace
src/Workspaces/Core/Portable/Rename/RenameUtilities.cs
浏览文件 @
8d70d17d
...
...
@@ -84,6 +84,7 @@ internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbo
.
Concat
(
documentsOfRenameSymbolDeclaration
.
First
().
Id
)
.
Select
(
d
=>
d
.
ProjectId
).
Distinct
();
// perf optimization: only look in declaring project when possible
if
(
ShouldRenameOnlyAffectDeclaringProject
(
symbol
))
{
var
isSubset
=
renameLocations
.
Select
(
l
=>
l
.
DocumentId
.
ProjectId
).
Distinct
().
Except
(
projectIdsOfRenameSymbolDeclaration
).
IsEmpty
();
...
...
@@ -92,7 +93,7 @@ internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbo
}
else
{
// We are trying to figure out the projects that directly depend on the project that contains the declaration for
// We are trying to figure out the projects that directly depend on the project that contains the declaration for
// the rename symbol. Other projects should not be affected by the rename.
var
relevantProjects
=
projectIdsOfRenameSymbolDeclaration
.
Concat
(
projectIdsOfRenameSymbolDeclaration
.
SelectMany
(
p
=>
solution
.
GetProjectDependencyGraph
().
GetProjectsThatDirectlyDependOnThisProject
(
p
))).
Distinct
();
...
...
@@ -108,8 +109,27 @@ internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbo
/// </summary>
private
static
bool
ShouldRenameOnlyAffectDeclaringProject
(
ISymbol
symbol
)
{
// Explicit interface implementations can cascade to other projects
return
symbol
.
DeclaredAccessibility
==
Accessibility
.
Private
&&
!
symbol
.
ExplicitInterfaceImplementations
().
Any
();
if
(
symbol
.
DeclaredAccessibility
!=
Accessibility
.
Private
)
{
// non-private members can influence other projects.
return
false
;
}
if
(
symbol
.
ExplicitInterfaceImplementations
().
Any
())
{
// Explicit interface implementations can cascade to other projects
return
false
;
}
if
(
symbol
.
IsOverride
)
{
// private-overrides aren't actually legal. But if we see one, we tolerate it and search other projects in case
// they override it.
// https://github.com/dotnet/roslyn/issues/25682
return
false
;
}
return
true
;
}
internal
static
TokenRenameInfo
GetTokenRenameInfo
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录