Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c387f4fd
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,发现更多精彩内容 >>
提交
c387f4fd
编写于
7月 12, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify enumeration.
上级
6e36ae87
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
103 addition
and
74 deletion
+103
-74
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs
+2
-5
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ArrayTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.ArrayTypeSymbolKey.cs
+2
-5
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs
+6
-9
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.MethodSymbolKey.cs
...aces/Core/Portable/SymbolKey/SymbolKey.MethodSymbolKey.cs
+6
-15
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ModuleSymbolKey.cs
...aces/Core/Portable/SymbolKey/SymbolKey.ModuleSymbolKey.cs
+4
-7
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.NamedTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.NamedTypeSymbolKey.cs
+4
-7
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.PointerTypeSymbolKey.cs
...Core/Portable/SymbolKey/SymbolKey.PointerTypeSymbolKey.cs
+2
-5
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
+3
-6
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.cs
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.cs
+8
-11
src/Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.Enumeration.cs
...ore/Portable/SymbolKey/SymbolKeyResolution.Enumeration.cs
+61
-0
src/Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.cs
...Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.cs
+5
-4
未找到文件。
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs
浏览文件 @
c387f4fd
...
...
@@ -224,12 +224,9 @@ public static IEnumerable<TSymbol> FindSimilarSymbols<TSymbol>(TSymbol symbol, C
// We may be talking about different compilations. So do not try to resolve locations.
var
result
=
new
HashSet
<
TSymbol
>();
var
resolution
=
key
.
Resolve
(
compilation
,
resolveLocations
:
false
,
cancellationToken
:
cancellationToken
);
foreach
(
var
current
in
resolution
)
foreach
(
var
current
in
resolution
.
OfType
<
TSymbol
>()
)
{
if
(
current
is
TSymbol
typedSymbol
)
{
result
.
Add
(
typedSymbol
);
}
result
.
Add
(
current
);
}
return
result
;
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ArrayTypeSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -18,12 +18,9 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
rank
=
reader
.
ReadInteger
();
using
var
result
=
PooledArrayBuilder
<
IArrayTypeSymbol
>.
GetInstance
(
elementTypeResolution
.
SymbolCount
);
foreach
(
var
symbol
in
elementTypeResolution
)
foreach
(
var
typeSymbol
in
elementTypeResolution
.
OfType
<
ITypeSymbol
>()
)
{
if
(
symbol
is
ITypeSymbol
typeSymbol
)
{
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreateArrayTypeSymbol
(
typeSymbol
,
rank
));
}
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreateArrayTypeSymbol
(
typeSymbol
,
rank
));
}
return
CreateSymbolInfo
(
result
);
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ErrorTypeSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -40,28 +40,25 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
using
var
result
=
PooledArrayBuilder
<
INamedTypeSymbol
>.
GetInstance
();
var
typeArgumentsArray
=
arity
>
0
?
typeArguments
.
Builder
.
ToArray
()
:
null
;
foreach
(
var
container
in
containingSymbolResolution
)
foreach
(
var
container
in
containingSymbolResolution
.
OfType
<
INamespaceOrTypeSymbol
>()
)
{
if
(
container
is
INamespaceOrTypeSymbol
containerTypeOrNS
)
{
result
.
AddIfNotNull
(
Construct
(
reader
,
containerTypeOrNS
,
name
,
arity
,
typeArgumentsArray
));
}
result
.
AddIfNotNull
(
Construct
(
reader
,
container
,
name
,
arity
,
typeArgumentsArray
));
}
// Always ensure at least one error type was created.
if
(
result
.
Count
==
0
)
{
result
.
AddIfNotNull
(
Construct
(
reader
,
container
TypeOrNS
:
null
,
name
,
arity
,
typeArgumentsArray
));
reader
,
container
:
null
,
name
,
arity
,
typeArgumentsArray
));
}
return
CreateSymbolInfo
(
result
);
}
private
static
INamedTypeSymbol
Construct
(
SymbolKeyReader
reader
,
INamespaceOrTypeSymbol
container
TypeOrNS
,
string
name
,
int
arity
,
ITypeSymbol
[]
typeArguments
)
private
static
INamedTypeSymbol
Construct
(
SymbolKeyReader
reader
,
INamespaceOrTypeSymbol
container
,
string
name
,
int
arity
,
ITypeSymbol
[]
typeArguments
)
{
var
result
=
reader
.
Compilation
.
CreateErrorTypeSymbol
(
container
TypeOrNS
,
name
,
arity
);
var
result
=
reader
.
Compilation
.
CreateErrorTypeSymbol
(
container
,
name
,
arity
);
return
typeArguments
!=
null
?
result
.
Construct
(
typeArguments
)
:
result
;
}
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.MethodSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -22,17 +22,11 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
receiverTypeResolution
=
reader
.
ReadSymbolKey
();
using
var
result
=
PooledArrayBuilder
<
IMethodSymbol
>.
GetInstance
();
foreach
(
var
reducedFrom
Symbol
in
reducedFromResolution
)
foreach
(
var
reducedFrom
in
reducedFromResolution
.
OfType
<
IMethodSymbol
>()
)
{
if
(
reducedFromSymbol
is
IMethodSymbol
reducedFrom
)
foreach
(
var
receiverType
in
receiverTypeResolution
.
OfType
<
ITypeSymbol
>()
)
{
foreach
(
var
receiverSymbol
in
receiverTypeResolution
)
{
if
(
receiverSymbol
is
ITypeSymbol
receiverType
)
{
result
.
AddIfNotNull
(
reducedFrom
.
ReduceExtensionMethod
(
receiverType
));
}
}
result
.
AddIfNotNull
(
reducedFrom
.
ReduceExtensionMethod
(
receiverType
));
}
}
...
...
@@ -65,14 +59,11 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
typeArgumentArray
=
typeArguments
.
Builder
.
ToArray
();
using
var
result
=
PooledArrayBuilder
<
IMethodSymbol
>.
GetInstance
();
foreach
(
var
symbol
in
constructedFrom
)
foreach
(
var
method
in
constructedFrom
.
OfType
<
IMethodSymbol
>()
)
{
if
(
symbol
is
IMethodSymbol
method
)
if
(
method
.
TypeParameters
.
Length
==
typeArgumentArray
.
Length
)
{
if
(
method
.
TypeParameters
.
Length
==
typeArgumentArray
.
Length
)
{
result
.
AddIfNotNull
(
method
.
Construct
(
typeArgumentArray
));
}
result
.
AddIfNotNull
(
method
.
Construct
(
typeArgumentArray
));
}
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.ModuleSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -14,14 +14,11 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
containingSymbolResolution
=
reader
.
ReadSymbolKey
();
using
var
result
=
PooledArrayBuilder
<
IModuleSymbol
>.
GetInstance
();
foreach
(
var
containingSymbol
in
containingSymbolResolution
)
foreach
(
var
assembly
in
containingSymbolResolution
.
OfType
<
IAssemblySymbol
>()
)
{
if
(
containingSymbol
is
IAssemblySymbol
assembly
)
{
// Don't check ModuleIds for equality because in practice, no-one uses them,
// and there is no way to set netmodule name programmatically using Roslyn
result
.
AddValuesIfNotNull
(
assembly
.
Modules
);
}
// Don't check ModuleIds for equality because in practice, no-one uses them,
// and there is no way to set netmodule name programmatically using Roslyn
result
.
AddValuesIfNotNull
(
assembly
.
Modules
);
}
return
CreateSymbolInfo
(
result
);
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.NamedTypeSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -43,14 +43,11 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
?
Array
.
Empty
<
ITypeSymbol
>()
:
typeArguments
.
Builder
.
ToArray
();
using
var
result
=
PooledArrayBuilder
<
INamedTypeSymbol
>.
GetInstance
();
foreach
(
var
resolution
in
containingSymbolResolution
)
foreach
(
var
nsOrType
in
containingSymbolResolution
.
OfType
<
INamespaceOrTypeSymbol
>()
)
{
if
(
resolution
is
INamespaceOrTypeSymbol
nsOrType
)
{
Resolve
(
result
,
nsOrType
,
metadataName
,
arity
,
isUnboundGenericType
,
typeArgumentArray
);
}
Resolve
(
result
,
nsOrType
,
metadataName
,
arity
,
isUnboundGenericType
,
typeArgumentArray
);
}
return
CreateSymbolInfo
(
result
);
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.PointerTypeSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -14,12 +14,9 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
var
pointedAtTypeResolution
=
reader
.
ReadSymbolKey
();
using
var
result
=
PooledArrayBuilder
<
IPointerTypeSymbol
>.
GetInstance
(
pointedAtTypeResolution
.
SymbolCount
);
foreach
(
var
symbol
in
pointedAtTypeResolution
)
foreach
(
var
typeSymbol
in
pointedAtTypeResolution
.
OfType
<
ITypeSymbol
>()
)
{
if
(
symbol
is
ITypeSymbol
typeSymbol
)
{
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreatePointerTypeSymbol
(
typeSymbol
));
}
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreatePointerTypeSymbol
(
typeSymbol
));
}
return
CreateSymbolInfo
(
result
);
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -80,13 +80,10 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
using
var
result
=
PooledArrayBuilder
<
INamedTypeSymbol
>.
GetInstance
();
var
elementNames
=
elementNamesBuilder
.
ToImmutable
();
foreach
(
var
symbol
in
underlyingTypeResolution
)
foreach
(
var
namedType
in
underlyingTypeResolution
.
OfType
<
INamedTypeSymbol
>()
)
{
if
(
symbol
is
INamedTypeSymbol
namedType
)
{
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreateTupleTypeSymbol
(
namedType
,
elementNames
,
elementLocations
));
}
result
.
AddIfNotNull
(
reader
.
Compilation
.
CreateTupleTypeSymbol
(
namedType
,
elementNames
,
elementLocations
));
}
return
CreateSymbolInfo
(
result
);
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.cs
浏览文件 @
c387f4fd
...
...
@@ -250,20 +250,17 @@ private static string GetName(string metadataName)
string
metadataNameOpt
)
where
TSymbol
:
ISymbol
{
var
result
=
PooledArrayBuilder
<
TSymbol
>.
GetInstance
();
foreach
(
var
containing
Symbol
in
containingTypeResolution
)
foreach
(
var
containing
Type
in
containingTypeResolution
.
OfType
<
INamedTypeSymbol
>()
)
{
if
(
containingSymbol
is
INamedTypeSymbol
containingType
)
{
var
members
=
metadataNameOpt
==
null
?
containingType
.
GetMembers
()
:
containingType
.
GetMembers
(
metadataNameOpt
);
var
members
=
metadataNameOpt
==
null
?
containingType
.
GetMembers
()
:
containingType
.
GetMembers
(
metadataNameOpt
);
foreach
(
var
member
in
members
)
foreach
(
var
member
in
members
)
{
if
(
member
is
TSymbol
symbol
)
{
if
(
member
is
TSymbol
symbol
)
{
result
.
AddIfNotNull
(
symbol
);
}
result
.
AddIfNotNull
(
symbol
);
}
}
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.Enumerat
or
.cs
→
src/Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.Enumerat
ion
.cs
浏览文件 @
c387f4fd
...
...
@@ -4,12 +4,23 @@ namespace Microsoft.CodeAnalysis
{
internal
partial
struct
SymbolKeyResolution
{
public
struct
Enumerator
public
struct
Enumerable
<
TSymbol
>
where
TSymbol
:
ISymbol
{
private
readonly
SymbolKeyResolution
_resolution
;
internal
Enumerable
(
SymbolKeyResolution
resolution
)
=>
_resolution
=
resolution
;
public
Enumerator
<
TSymbol
>
GetEnumerator
()
=>
new
Enumerator
<
TSymbol
>(
_resolution
);
}
public
struct
Enumerator
<
TSymbol
>
where
TSymbol
:
ISymbol
{
private
readonly
SymbolKeyResolution
_symbolKeyResolution
;
private
int
_index
;
public
Enumerator
(
SymbolKeyResolution
symbolKeyResolution
)
internal
Enumerator
(
SymbolKeyResolution
symbolKeyResolution
)
{
_symbolKeyResolution
=
symbolKeyResolution
;
_index
=
-
1
;
...
...
@@ -17,25 +28,32 @@ public Enumerator(SymbolKeyResolution symbolKeyResolution)
public
bool
MoveNext
()
{
_index
++;
if
(
_symbolKeyResolution
.
Symbol
!=
null
)
{
return
_index
==
0
;
return
++
_index
==
0
&&
_symbolKeyResolution
.
Symbol
is
TSymbol
;
}
while
(++
_index
<
_symbolKeyResolution
.
CandidateSymbols
.
Length
)
{
if
(
_symbolKeyResolution
.
CandidateSymbols
[
_index
]
is
TSymbol
)
{
return
true
;
}
}
return
_index
<
_symbolKeyResolution
.
CandidateSymbols
.
Length
;
return
false
;
}
public
I
Symbol
Current
public
T
Symbol
Current
{
get
{
if
(
_symbolKeyResolution
.
Symbol
!=
null
)
{
return
_symbolKeyResolution
.
Symbol
;
return
(
TSymbol
)
_symbolKeyResolution
.
Symbol
;
}
return
_symbolKeyResolution
.
CandidateSymbols
[
_index
];
return
(
TSymbol
)
_symbolKeyResolution
.
CandidateSymbols
[
_index
];
}
}
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKeyResolution.cs
浏览文件 @
c387f4fd
...
...
@@ -47,9 +47,10 @@ internal SymbolKeyResolution(ImmutableArray<ISymbol> candidateSymbols, Candidate
public
CandidateReason
CandidateReason
{
get
;
}
public
ImmutableArray
<
ISymbol
>
CandidateSymbols
=>
_candidateSymbols
.
NullToEmpty
();
public
Enumerator
GetEnumerator
()
{
return
new
Enumerator
(
this
);
}
public
Enumerator
<
ISymbol
>
GetEnumerator
()
=>
new
Enumerator
<
ISymbol
>(
this
);
internal
Enumerable
<
TSymbol
>
OfType
<
TSymbol
>()
where
TSymbol
:
ISymbol
=>
new
Enumerable
<
TSymbol
>(
this
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录