Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b9f84c15
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,发现更多精彩内容 >>
提交
b9f84c15
编写于
3月 14, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests.
上级
92fba2bd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
9 deletion
+90
-9
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
...aces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
+1
-3
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
+18
-3
src/Workspaces/CoreTest/SymbolKeyTests.cs
src/Workspaces/CoreTest/SymbolKeyTests.cs
+71
-3
未找到文件。
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs
浏览文件 @
b9f84c15
...
...
@@ -537,9 +537,7 @@ public Location ReadLocation()
}
public
ImmutableArray
<
Location
>
ReadLocationArray
()
{
return
ReadArray
(
_readLocation
);
}
=>
ReadArray
(
_readLocation
);
#
endregion
}
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
浏览文件 @
b9f84c15
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Linq
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis
{
...
...
@@ -14,7 +16,6 @@ public static void Create(INamedTypeSymbol symbol, SymbolKeyWriter visitor)
{
Debug
.
Assert
(
symbol
.
IsTupleType
);
var
friendlyNames
=
ArrayBuilder
<
string
>.
GetInstance
();
var
locations
=
ArrayBuilder
<
Location
>.
GetInstance
();
...
...
@@ -54,7 +55,7 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
{
var
elementTypes
=
reader
.
ReadSymbolKeyArray
().
SelectAsArray
(
r
=>
r
.
GetAnySymbol
()
as
ITypeSymbol
);
var
elementNames
=
reader
.
ReadStringArray
();
var
elementLocations
=
reader
.
ReadLocationArray
(
);
var
elementLocations
=
ReadElementLocations
(
reader
);
if
(!
elementTypes
.
Any
(
t
=>
t
==
null
))
{
...
...
@@ -73,7 +74,8 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
{
var
underlyingTypeResolution
=
reader
.
ReadSymbolKey
();
var
elementNames
=
reader
.
ReadStringArray
();
var
elementLocations
=
reader
.
ReadLocationArray
();
var
elementLocations
=
ReadElementLocations
(
reader
);
try
{
var
result
=
GetAllSymbols
<
INamedTypeSymbol
>(
underlyingTypeResolution
).
Select
(
...
...
@@ -87,6 +89,19 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
return
new
SymbolKeyResolution
(
reader
.
Compilation
.
ObjectType
);
}
private
static
ImmutableArray
<
Location
>
ReadElementLocations
(
SymbolKeyReader
reader
)
{
// Compiler API requires that all the locations are non-null, or that there is a default
// immutable array passed in.
var
elementLocations
=
reader
.
ReadLocationArray
();
if
(
elementLocations
.
All
(
loc
=>
loc
==
null
))
{
elementLocations
=
default
(
ImmutableArray
<
Location
>);
}
return
elementLocations
;
}
}
}
}
\ No newline at end of file
src/Workspaces/CoreTest/SymbolKeyTests.cs
浏览文件 @
b9f84c15
...
...
@@ -647,6 +647,74 @@ object LocalFunction<T>()
Assert
.
True
(
tested
);
}
[
Fact
,
WorkItem
(
17702
,
"https://github.com/dotnet/roslyn/issues/17702"
)]
public
void
TestTupleWithLocalTypeReferences1
()
{
var
source
=
@"
using System.Linq;
class C
{
void Method((C, int) t)
{
}
}"
;
// Tuples store locations along with them. But we can only recover those locations
// if we're re-resolving into a compilation with the same files.
var
compilation1
=
GetCompilation
(
source
,
LanguageNames
.
CSharp
,
"File1.cs"
);
var
compilation2
=
GetCompilation
(
source
,
LanguageNames
.
CSharp
,
"File2.cs"
);
var
symbol
=
GetAllSymbols
(
compilation1
.
GetSemanticModel
(
compilation1
.
SyntaxTrees
.
Single
()),
n
=>
n
is
CSharp
.
Syntax
.
MethodDeclarationSyntax
).
Single
();
// Ensure we don't crash getting these symbol keys.
var
id
=
SymbolKey
.
ToString
(
symbol
);
Assert
.
NotNull
(
id
);
var
found
=
SymbolKey
.
Resolve
(
id
,
compilation2
).
GetAnySymbol
();
Assert
.
NotNull
(
found
);
Assert
.
Equal
(
symbol
.
Name
,
found
.
Name
);
Assert
.
Equal
(
symbol
.
Kind
,
found
.
Kind
);
var
method
=
found
as
IMethodSymbol
;
Assert
.
True
(
method
.
Parameters
[
0
].
Type
.
IsTupleType
);
}
[
Fact
,
WorkItem
(
17702
,
"https://github.com/dotnet/roslyn/issues/17702"
)]
public
void
TestTupleWithLocalTypeReferences2
()
{
var
source
=
@"
using System.Linq;
class C
{
void Method((C a, int b) t)
{
}
}"
;
// Tuples store locations along with them. But we can only recover those locations
// if we're re-resolving into a compilation with the same files.
var
compilation1
=
GetCompilation
(
source
,
LanguageNames
.
CSharp
,
"File1.cs"
);
var
compilation2
=
GetCompilation
(
source
,
LanguageNames
.
CSharp
,
"File2.cs"
);
var
symbol
=
GetAllSymbols
(
compilation1
.
GetSemanticModel
(
compilation1
.
SyntaxTrees
.
Single
()),
n
=>
n
is
CSharp
.
Syntax
.
MethodDeclarationSyntax
).
Single
();
// Ensure we don't crash getting these symbol keys.
var
id
=
SymbolKey
.
ToString
(
symbol
);
Assert
.
NotNull
(
id
);
var
found
=
SymbolKey
.
Resolve
(
id
,
compilation2
).
GetAnySymbol
();
Assert
.
NotNull
(
found
);
Assert
.
Equal
(
symbol
.
Name
,
found
.
Name
);
Assert
.
Equal
(
symbol
.
Kind
,
found
.
Kind
);
var
method
=
found
as
IMethodSymbol
;
Assert
.
True
(
method
.
Parameters
[
0
].
Type
.
IsTupleType
);
}
private
void
TestRoundTrip
(
IEnumerable
<
ISymbol
>
symbols
,
Compilation
compilation
,
Func
<
ISymbol
,
object
>
fnId
=
null
)
{
foreach
(
var
symbol
in
symbols
)
...
...
@@ -674,7 +742,7 @@ private void TestRoundTrip(ISymbol symbol, Compilation compilation, Func<ISymbol
}
}
private
Compilation
GetCompilation
(
string
source
,
string
language
)
private
Compilation
GetCompilation
(
string
source
,
string
language
,
string
path
=
""
)
{
var
references
=
new
[]
{
...
...
@@ -684,12 +752,12 @@ private Compilation GetCompilation(string source, string language)
if
(
language
==
LanguageNames
.
CSharp
)
{
var
tree
=
CSharp
.
SyntaxFactory
.
ParseSyntaxTree
(
source
);
var
tree
=
CSharp
.
SyntaxFactory
.
ParseSyntaxTree
(
source
,
path
:
path
);
return
CSharp
.
CSharpCompilation
.
Create
(
"Test"
,
syntaxTrees
:
new
[]
{
tree
},
references
:
references
);
}
else
if
(
language
==
LanguageNames
.
VisualBasic
)
{
var
tree
=
VisualBasic
.
SyntaxFactory
.
ParseSyntaxTree
(
source
);
var
tree
=
VisualBasic
.
SyntaxFactory
.
ParseSyntaxTree
(
source
,
path
:
path
);
return
VisualBasic
.
VisualBasicCompilation
.
Create
(
"Test"
,
syntaxTrees
:
new
[]
{
tree
},
references
:
references
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录