Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a7afaa62
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,发现更多精彩内容 >>
提交
a7afaa62
编写于
4月 29, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract type
上级
4fb54744
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
97 addition
and
72 deletion
+97
-72
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.KeyEqualityComparer.cs
...FindReferences/DependentTypeFinder.KeyEqualityComparer.cs
+65
-0
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs
...ortable/FindSymbols/FindReferences/DependentTypeFinder.cs
+32
-72
未找到文件。
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.KeyEqualityComparer.cs
0 → 100644
浏览文件 @
a7afaa62
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Runtime.CompilerServices
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.FindSymbols
{
// Must cache using SymbolKey+ProjectId. That's because the same symbol key may be found among many projects, but
// the same operation on the same symbol key might produce different results depending on which project it was found
// in. For example, each symbol's project may have a different set of downstream dependent projects. As such,
// there may be a different set of related symbols found for each.
internal
static
partial
class
DependentTypeFinder
{
private
class
KeyEqualityComparer
:
IEqualityComparer
<(
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)>
{
public
static
readonly
KeyEqualityComparer
Instance
=
new
KeyEqualityComparer
();
private
KeyEqualityComparer
()
{
}
public
bool
Equals
((
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
x
,
(
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
y
)
{
var
(
xSymbolKey
,
xProjectId
,
xProjects
)
=
x
;
var
(
ySymbolKey
,
yProjectId
,
yProjects
)
=
y
;
if
(!
xSymbolKey
.
Equals
(
ySymbolKey
))
return
false
;
if
(!
xProjectId
.
Equals
(
yProjectId
))
return
false
;
if
(
xProjects
is
null
)
return
yProjects
is
null
;
if
(
yProjects
is
null
)
return
false
;
return
xProjects
.
SetEquals
(
yProjects
);
}
public
int
GetHashCode
((
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
obj
)
{
var
(
symbolKey
,
projectId
,
projects
)
=
obj
;
var
projectsHash
=
0
;
if
(
projects
!=
null
)
{
foreach
(
var
project
in
projects
)
projectsHash
+=
project
.
GetHashCode
();
}
return
Hash
.
Combine
(
symbolKey
.
GetHashCode
(),
Hash
.
Combine
(
projectId
,
projectsHash
));
}
}
}
}
src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs
浏览文件 @
a7afaa62
...
@@ -471,8 +471,6 @@ private static void AddRange(SymbolSet foundTypes, SymbolSet result)
...
@@ -471,8 +471,6 @@ private static void AddRange(SymbolSet foundTypes, SymbolSet result)
// As long as there are new types to search for, keep looping.
// As long as there are new types to search for, keep looping.
while
(
typesToSearchFor
.
Count
>
0
)
while
(
typesToSearchFor
.
Count
>
0
)
{
{
tempBuffer
.
Clear
();
foreach
(
var
reference
in
compilation
.
References
.
OfType
<
PortableExecutableReference
>())
foreach
(
var
reference
in
compilation
.
References
.
OfType
<
PortableExecutableReference
>())
{
{
cancellationToken
.
ThrowIfCancellationRequested
();
cancellationToken
.
ThrowIfCancellationRequested
();
...
@@ -483,19 +481,8 @@ private static void AddRange(SymbolSet foundTypes, SymbolSet result)
...
@@ -483,19 +481,8 @@ private static void AddRange(SymbolSet foundTypes, SymbolSet result)
cancellationToken
).
ConfigureAwait
(
false
);
cancellationToken
).
ConfigureAwait
(
false
);
}
}
// Clear out the information about the types we're looking for. We'll
PropagateTemporaryResults
(
// fill these in if we discover any more types that we need to keep searching
result
,
typesToSearchFor
,
tempBuffer
,
transitive
,
shouldContinueSearching
);
// for.
typesToSearchFor
.
Clear
();
foreach
(
var
derivedType
in
tempBuffer
)
{
if
(
result
.
Add
(
derivedType
))
{
if
(
transitive
&&
shouldContinueSearching
(
derivedType
))
typesToSearchFor
.
Add
(
derivedType
);
}
}
}
}
}
}
...
@@ -582,8 +569,6 @@ private static bool TypeHasInterfaceInSet(INamedTypeSymbol type, SymbolSet set)
...
@@ -582,8 +569,6 @@ private static bool TypeHasInterfaceInSet(INamedTypeSymbol type, SymbolSet set)
// As long as there are new types to search for, keep looping.
// As long as there are new types to search for, keep looping.
while
(
typesToSearchFor
.
Count
>
0
)
while
(
typesToSearchFor
.
Count
>
0
)
{
{
tempBuffer
.
Clear
();
foreach
(
var
type
in
typesToSearchFor
)
foreach
(
var
type
in
typesToSearchFor
)
{
{
cancellationToken
.
ThrowIfCancellationRequested
();
cancellationToken
.
ThrowIfCancellationRequested
();
...
@@ -634,20 +619,40 @@ private static bool TypeHasInterfaceInSet(INamedTypeSymbol type, SymbolSet set)
...
@@ -634,20 +619,40 @@ private static bool TypeHasInterfaceInSet(INamedTypeSymbol type, SymbolSet set)
cancellationToken
).
ConfigureAwait
(
false
);
cancellationToken
).
ConfigureAwait
(
false
);
}
}
// Clear out the information about the types we're looking for. We'll
PropagateTemporaryResults
(
// fill these in if we discover any more types that we need to keep searching
result
,
typesToSearchFor
,
tempBuffer
,
transitive
,
shouldContinueSearching
);
// for.
}
typesToSearchFor
.
Clear
();
}
/// <summary>
/// Moves all the types in <paramref name="tempBuffer"/> to <paramref name="result"/>. If these are types we
/// haven't seen before, and the caller says we <paramref name="shouldContinueSearching"/> on them, then add
/// them to <paramref name="typesToSearchFor"/> for the next round of searching.
/// </summary>
private
static
void
PropagateTemporaryResults
(
SymbolSet
result
,
SymbolSet
typesToSearchFor
,
SymbolSet
tempBuffer
,
bool
transitive
,
Func
<
INamedTypeSymbol
,
bool
>
shouldContinueSearching
)
{
// Clear out the information about the types we're looking for. We'll
// fill these in if we discover any more types that we need to keep searching
// for.
typesToSearchFor
.
Clear
();
foreach
(
var
derivedType
in
tempBuffer
)
foreach
(
var
derivedType
in
tempBuffer
)
{
// See if it's a type we've never seen before.
if
(
result
.
Add
(
derivedType
))
{
{
if
(
result
.
Add
(
derivedType
))
// If we should keep going, add it to the next batch of items we'll search for in this project.
{
if
(
transitive
&&
shouldContinueSearching
(
derivedType
))
if
(
transitive
&&
shouldContinueSearching
(
derivedType
))
typesToSearchFor
.
Add
(
derivedType
);
typesToSearchFor
.
Add
(
derivedType
);
}
}
}
}
}
tempBuffer
.
Clear
();
}
}
private
static
async
Task
AddSourceTypesThatDeriveFromNameAsync
(
private
static
async
Task
AddSourceTypesThatDeriveFromNameAsync
(
...
@@ -714,50 +719,5 @@ public static PooledDisposer<PooledHashSet<INamedTypeSymbol>> GetSymbolSet(out S
...
@@ -714,50 +719,5 @@ public static PooledDisposer<PooledHashSet<INamedTypeSymbol>> GetSymbolSet(out S
instance
=
pooledInstance
;
instance
=
pooledInstance
;
return
new
PooledDisposer
<
PooledHashSet
<
INamedTypeSymbol
>>(
pooledInstance
);
return
new
PooledDisposer
<
PooledHashSet
<
INamedTypeSymbol
>>(
pooledInstance
);
}
}
private
class
KeyEqualityComparer
:
IEqualityComparer
<(
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)>
{
public
static
readonly
KeyEqualityComparer
Instance
=
new
KeyEqualityComparer
();
private
KeyEqualityComparer
()
{
}
public
bool
Equals
((
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
x
,
(
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
y
)
{
var
(
xSymbolKey
,
xProjectId
,
xProjects
)
=
x
;
var
(
ySymbolKey
,
yProjectId
,
yProjects
)
=
y
;
if
(!
xSymbolKey
.
Equals
(
ySymbolKey
))
return
false
;
if
(!
xProjectId
.
Equals
(
yProjectId
))
return
false
;
if
(
xProjects
is
null
)
return
yProjects
is
null
;
if
(
yProjects
is
null
)
return
false
;
return
xProjects
.
SetEquals
(
yProjects
);
}
public
int
GetHashCode
((
SymbolKey
,
ProjectId
,
IImmutableSet
<
Project
>)
obj
)
{
var
(
symbolKey
,
projectId
,
projects
)
=
obj
;
var
projectsHash
=
0
;
if
(
projects
!=
null
)
{
foreach
(
var
project
in
projects
)
projectsHash
+=
project
.
GetHashCode
();
}
return
Hash
.
Combine
(
symbolKey
.
GetHashCode
(),
Hash
.
Combine
(
projectId
,
projectsHash
));
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录