Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
58917650
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
58917650
编写于
5月 22, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly 'go to implementation' when there are abstract overrides in the hierarchy.
上级
75084293
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
23 deletion
+55
-23
src/EditorFeatures/Test2/GoToImplementation/GoToImplementationTests.vb
...tures/Test2/GoToImplementation/GoToImplementationTests.vb
+26
-0
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs
...paces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs
+24
-17
src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
...aces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
+5
-6
未找到文件。
src/EditorFeatures/Test2/GoToImplementation/GoToImplementationTests.vb
浏览文件 @
58917650
...
...
@@ -413,5 +413,31 @@ class D : C
Await
TestAsync
(
workspace
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
GoToImplementation
)
>
<
WorkItem
(
19700
,
"https://github.com/dotnet/roslyn/issues/19700"
)
>
Public
Async
Function
TestWithIntermediateAbstractOverrides
()
As
Task
Dim
workspace
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
>
abstract
class
A
{
public
virtual
void
$$[|
M
|]
()
{
}
}
abstract
class
B
:
A
{
public
abstract
override
void
M
()
;
}
sealed
class
C1
:
B
{
public
override
void
[|
M
|]
()
{
}
}
sealed
class
C2
:
A
{
public
override
void
[|
M
|]
()
=>
base
.
M
()
;
}
</
Document
>
</
Project
>
</
Workspace
>
Await
TestAsync
(
workspace
)
End
Function
End
Class
End
Namespace
\ No newline at end of file
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs
浏览文件 @
58917650
...
...
@@ -32,41 +32,48 @@ public static partial class SymbolFinder
internal
static
async
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
FindOverridesAsync
(
SymbolAndProjectId
symbolAndProjectId
,
Solution
solution
,
IImmutableSet
<
Project
>
projects
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
// Method can only have overrides if its a virtual, abstract or override and is not
// sealed.
var
symbol
=
symbolAndProjectId
.
Symbol
;
var
results
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
var
symbol
=
symbolAndProjectId
.
Symbol
?.
OriginalDefinition
;
if
(
symbol
.
IsOverridable
())
{
// To find the overrides, we need to walk down the type hierarchy and check all
// derived types. TODO(cyrusn): This seems extremely costly. Is there any way to
// speed this up?
var
containingType
=
symbol
.
ContainingType
.
OriginalDefinition
;
// derived types.
var
containingType
=
symbol
.
ContainingType
;
var
derivedTypes
=
await
FindDerivedClassesAsync
(
symbolAndProjectId
.
WithSymbol
(
containingType
),
solution
,
projects
,
cancellationToken
).
ConfigureAwait
(
false
);
var
results
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
foreach
(
var
type
in
derivedTypes
)
{
foreach
(
var
m
in
GetMembers
(
type
,
symbol
.
Name
))
foreach
(
var
m
in
type
.
Symbol
.
GetMembers
(
symbol
.
Name
))
{
var
sourceMember
=
await
FindSourceDefinitionAsync
(
m
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
var
bestMember
=
sourceMember
.
Symbol
!=
null
?
sourceMember
:
m
;
var
member
=
bestMember
.
Symbol
;
if
(
member
!=
null
&&
member
.
IsOverride
&&
member
.
OverriddenMember
()
!=
null
&&
OriginalSymbolsMatch
(
member
.
OverriddenMember
().
OriginalDefinition
,
symbol
.
OriginalDefinition
,
solution
,
cancellationToken
))
var
bestMember
=
sourceMember
??
m
;
if
(
IsOverride
(
solution
,
bestMember
,
symbol
,
cancellationToken
))
{
results
.
Add
(
bestMember
);
results
.
Add
(
new
SymbolAndProjectId
(
bestMember
,
type
.
ProjectId
)
);
}
}
}
}
return
results
.
ToImmutableAndFree
();
return
results
.
ToImmutableAndFree
();
}
private
static
bool
IsOverride
(
Solution
solution
,
ISymbol
member
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
{
for
(
var
current
=
member
;
current
!=
null
;
current
=
current
.
OverriddenMember
())
{
if
(
OriginalSymbolsMatch
(
current
.
OverriddenMember
(),
symbol
.
OriginalDefinition
,
solution
,
cancellationToken
))
{
return
true
;
}
}
return
ImmutableArray
<
SymbolAndProjectId
>.
Empty
;
return
false
;
}
/// <summary>
...
...
src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs
浏览文件 @
58917650
...
...
@@ -102,12 +102,11 @@ public static ImmutableArray<ISymbol> ExplicitInterfaceImplementations(this ISym
public
static
bool
IsOverridable
(
this
ISymbol
symbol
)
{
return
symbol
!=
null
&&
symbol
.
ContainingType
!=
null
&&
symbol
.
ContainingType
.
TypeKind
==
TypeKind
.
Class
&&
(
symbol
.
IsVirtual
||
symbol
.
IsAbstract
||
symbol
.
IsOverride
)
&&
!
symbol
.
IsSealed
;
// Members can only have overrides if they are virtual, abstract or override and is not
// sealed.
return
symbol
?.
ContainingType
?.
TypeKind
==
TypeKind
.
Class
&&
(
symbol
.
IsVirtual
||
symbol
.
IsAbstract
||
symbol
.
IsOverride
)
&&
!
symbol
.
IsSealed
;
}
public
static
bool
IsImplementableMember
(
this
ISymbol
symbol
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录