Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
9b4f5dc1
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,发现更多精彩内容 >>
提交
9b4f5dc1
编写于
4月 29, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify
上级
6e4766a7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
69 deletion
+38
-69
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs
...ortable/FindSymbols/FindReferences/DependentTypeFinder.cs
+31
-62
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_DerivedClasses.cs
...bols/FindReferences/DependentTypeFinder_DerivedClasses.cs
+2
-2
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_DerivedInterfaces.cs
...s/FindReferences/DependentTypeFinder_DerivedInterfaces.cs
+3
-3
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_ImplementingTypes.cs
...s/FindReferences/DependentTypeFinder_ImplementingTypes.cs
+2
-2
未找到文件。
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs
浏览文件 @
9b4f5dc1
...
...
@@ -37,17 +37,14 @@ namespace Microsoft.CodeAnalysis.FindSymbols
/// </summary>
internal
static
partial
class
DependentTypeFinder
{
// Static helpers so we can pass delegates around without allocations.
private
static
readonly
Func
<
Location
,
bool
>
s_isInMetadata
=
loc
=>
loc
.
IsInMetadata
;
private
static
readonly
Func
<
Location
,
bool
>
s_isInSource
=
loc
=>
loc
.
IsInSource
;
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isInterface
=
t
=>
t
?.
TypeKind
==
TypeKind
.
Interface
;
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isNonSealedClass
=
t
=>
t
?.
TypeKind
==
TypeKind
.
Class
&&
!
t
.
IsSealed
;
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isInterfaceOrNonSealedClass
=
t
=>
s_isInterface
(
t
)
||
s_isNonSealedClass
(
t
);
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isInterface
=
t
=>
t
?.
TypeKind
==
TypeKind
.
Interface
;
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isNonSealedClass
=
t
=>
t
?.
TypeKind
==
TypeKind
.
Class
&&
!
t
.
IsSealed
;
private
static
readonly
Func
<
INamedTypeSymbol
,
bool
>
s_isInterfaceOrNonSealedClass
=
t
=>
s_isInterface
(
t
)
||
s_isNonSealedClass
(
t
);
private
static
readonly
ObjectPool
<
SymbolSet
>
s_setPool
=
new
ObjectPool
<
SymbolSet
>(
()
=>
new
SymbolSet
(
SymbolEquivalenceComparer
.
Instance
));
...
...
@@ -160,7 +157,7 @@ internal static partial class DependentTypeFinder
INamedTypeSymbol
type
,
Solution
solution
,
IImmutableSet
<
Project
>
projects
,
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
typeMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
typeMatches
,
Func
<
INamedTypeSymbol
,
bool
>
shouldContinueSearching
,
bool
transitive
,
CancellationToken
cancellationToken
)
...
...
@@ -246,7 +243,7 @@ internal static partial class DependentTypeFinder
SymbolSet
currentMetadataTypes
,
SymbolSet
currentSourceAndMetadataTypes
,
Project
project
,
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
typeMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
typeMatches
,
Func
<
INamedTypeSymbol
,
bool
>
shouldContinueSearching
,
bool
transitive
,
CancellationToken
cancellationToken
)
...
...
@@ -255,12 +252,13 @@ internal static partial class DependentTypeFinder
Debug
.
Assert
(
project
.
SupportsCompilation
);
// First see what derived metadata types we might find in this project.
// This is only necessary if we started with a metadata type.
if
(
searchInMetadata
)
var
foundTypes
=
CreateSymbolAndProjectIdSet
();
try
{
var
foundMetadataTypes
=
CreateSymbolAndProjectIdSet
();
try
// First see what derived metadata types we might find in this project. This is only necessary if we started
// with a metadata type (i.e. a source type could not have a descendant type found in metadata, but a
// metadata type could have descendant types in source and metadata).
if
(
searchInMetadata
)
{
await
AddMetadataTypesInProjectAsync
(
currentMetadataTypes
,
...
...
@@ -268,10 +266,10 @@ internal static partial class DependentTypeFinder
typeMatches
,
shouldContinueSearching
,
transitive
,
found
Metadata
Types
,
foundTypes
,
cancellationToken
).
ConfigureAwait
(
false
);
foreach
(
var
foundType
in
found
Metadata
Types
)
foreach
(
var
foundType
in
foundTypes
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -287,26 +285,20 @@ internal static partial class DependentTypeFinder
}
}
}
finally
{
s_setPool
.
ClearAndFree
(
foundMetadataTypes
);
}
}
// Now search the project and see what source types we can find.
var
foundSourceTypes
=
CreateSymbolAndProjectIdSet
();
try
{
// Now search the project and see what source types we can find.
foundTypes
.
Clear
();
await
AddSourceTypesInProjectAsync
(
currentSourceAndMetadataTypes
,
project
,
typeMatches
,
shouldContinueSearching
,
transitive
,
found
Source
Types
,
foundTypes
,
cancellationToken
).
ConfigureAwait
(
false
);
foreach
(
var
foundType
in
found
Source
Types
)
foreach
(
var
foundType
in
foundTypes
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -321,7 +313,7 @@ internal static partial class DependentTypeFinder
}
finally
{
s_setPool
.
ClearAndFree
(
found
Source
Types
);
s_setPool
.
ClearAndFree
(
foundTypes
);
}
}
...
...
@@ -445,7 +437,7 @@ internal static partial class DependentTypeFinder
private
static
async
Task
AddMetadataTypesInProjectAsync
(
SymbolSet
metadataTypes
,
Project
project
,
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
metadataTypeMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
metadataTypeMatches
,
Func
<
INamedTypeSymbol
,
bool
>
shouldContinueSearching
,
bool
transitive
,
SymbolSet
result
,
...
...
@@ -497,7 +489,7 @@ internal static partial class DependentTypeFinder
private
static
async
Task
FindImmediateMatchingMetadataTypesInMetadataReferenceAsync
(
SymbolSet
metadataTypes
,
Project
project
,
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
metadataTypeTransitivelyMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
metadataTypeTransitivelyMatches
,
Compilation
compilation
,
PortableExecutableReference
reference
,
SymbolSet
result
,
...
...
@@ -528,7 +520,7 @@ internal static partial class DependentTypeFinder
{
if
(
derivedType
!=
null
&&
derivedType
.
Locations
.
Any
(
s_isInMetadata
)
&&
metadataTypeTransitivelyMatches
(
metadataTypes
,
derivedType
))
metadataTypeTransitivelyMatches
(
derivedType
,
metadataTypes
))
{
result
.
Add
(
derivedType
);
}
...
...
@@ -536,38 +528,15 @@ internal static partial class DependentTypeFinder
}
}
private
static
bool
TypeHasBaseTypeInSet
(
SymbolSet
set
,
INamedTypeSymbol
type
,
bool
transitive
)
{
if
(
transitive
)
{
for
(
var
current
=
type
.
BaseType
;
current
!=
null
;
current
=
current
.
BaseType
)
{
if
(
set
.
Contains
(
current
.
OriginalDefinition
))
{
return
true
;
}
}
return
false
;
}
else
{
return
set
.
Contains
(
type
.
BaseType
?.
OriginalDefinition
);
}
}
private
static
bool
TypeHasBaseTypeInSet
(
INamedTypeSymbol
type
,
SymbolSet
set
)
=>
set
.
Contains
(
type
.
BaseType
?.
OriginalDefinition
);
private
static
bool
TypeHasInterfaceInSet
(
SymbolSet
set
,
INamedTypeSymbol
type
,
bool
transitive
)
private
static
bool
TypeHasInterfaceInSet
(
INamedTypeSymbol
type
,
SymbolSet
set
)
{
var
interfaces
=
transitive
?
type
.
AllInterfaces
:
type
.
Interfaces
;
foreach
(
var
interfaceType
in
interfaces
)
foreach
(
var
interfaceType
in
type
.
Interfaces
)
{
if
(
set
.
Contains
(
interfaceType
.
OriginalDefinition
))
{
return
true
;
}
}
return
false
;
...
...
@@ -576,7 +545,7 @@ internal static partial class DependentTypeFinder
private
static
async
Task
AddSourceTypesInProjectAsync
(
SymbolSet
sourceAndMetadataTypes
,
Project
project
,
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
sourceTypeMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
sourceTypeMatches
,
Func
<
INamedTypeSymbol
,
bool
>
shouldContinueSearching
,
bool
transitive
,
SymbolSet
finalResult
,
...
...
@@ -655,7 +624,7 @@ internal static partial class DependentTypeFinder
}
private
static
async
Task
AddTypesThatDeriveFromNameAsync
(
Func
<
SymbolSet
,
INamedTypeSymbol
,
bool
>
sourceTypeMatches
,
Func
<
INamedTypeSymbol
,
SymbolSet
,
bool
>
sourceTypeMatches
,
ConcurrentSet
<
SemanticModel
>
cachedModels
,
SymbolSet
typesToSearchFor
,
ProjectIndex
index
,
...
...
@@ -672,7 +641,7 @@ internal static partial class DependentTypeFinder
var
resolvedType
=
info
.
TryResolve
(
semanticModel
,
cancellationToken
);
if
(
resolvedType
is
INamedTypeSymbol
namedType
&&
sourceTypeMatches
(
typesToSearchFor
,
namedType
))
sourceTypeMatches
(
namedType
,
typesToSearchFor
))
{
result
.
Add
(
namedType
);
}
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_DerivedClasses.cs
浏览文件 @
9b4f5dc1
...
...
@@ -40,8 +40,8 @@ internal static partial class DependentTypeFinder
{
if
(
s_isNonSealedClass
(
type
))
{
static
bool
TypeMatches
(
SymbolSet
set
,
INamedTypeSymbol
metadataType
)
=>
TypeHasBaseTypeInSet
(
set
,
metadataType
,
transitive
:
false
);
static
bool
TypeMatches
(
INamedTypeSymbol
type
,
SymbolSet
set
)
=>
TypeHasBaseTypeInSet
(
type
,
set
);
return
DescendInheritanceTreeAsync
(
type
,
solution
,
projects
,
typeMatches
:
TypeMatches
,
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_DerivedInterfaces.cs
浏览文件 @
9b4f5dc1
...
...
@@ -36,10 +36,10 @@ internal static partial class DependentTypeFinder
CancellationToken
cancellationToken
)
{
// Only an interface can be implemented.
if
(
type
?.
TypeKind
==
TypeKind
.
Interface
)
if
(
s_isInterface
(
type
)
)
{
static
bool
TypeMatches
(
SymbolSet
s
,
INamedTypeSymbol
t
)
=>
s_isInterface
(
t
)
&&
TypeHasInterfaceInSet
(
s
,
t
,
transitive
:
false
);
static
bool
TypeMatches
(
INamedTypeSymbol
type
,
SymbolSet
se
t
)
=>
s_isInterface
(
t
ype
)
&&
TypeHasInterfaceInSet
(
type
,
set
);
return
DescendInheritanceTreeAsync
(
type
,
solution
,
projects
,
typeMatches
:
TypeMatches
,
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder_ImplementingTypes.cs
浏览文件 @
9b4f5dc1
...
...
@@ -54,8 +54,8 @@ internal static partial class DependentTypeFinder
// 'Base' match and will add to the set. Then, we'll look for types that have 'Base' in their
// inheritance chain, and we need to match that by looking in the .BaseType inheritance chain when
// looking at 'Derived'.
static
bool
TypeMatches
(
SymbolSet
s
,
INamedTypeSymbol
t
)
=>
TypeHasBaseTypeInSet
(
s
,
t
,
transitive
:
false
)
||
TypeHasInterfaceInSet
(
s
,
t
,
transitive
:
false
);
static
bool
TypeMatches
(
INamedTypeSymbol
type
,
SymbolSet
se
t
)
=>
TypeHasBaseTypeInSet
(
type
,
set
)
||
TypeHasInterfaceInSet
(
type
,
set
);
// As long as we keep hitting derived interfaces or implementing non-sealed classes we need to keep
// looking (as those types themselves may have more derived classes that would b implementations of this
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录