Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
03803fc6
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,发现更多精彩内容 >>
未验证
提交
03803fc6
编写于
10月 10, 2018
作者:
I
Ivan Basov
提交者:
GitHub
10月 10, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix System.ArgumentOutOfRangeException in FindLeafNodeAndPartner (#28382)
上级
d5a69b47
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
207 addition
and
8 deletion
+207
-8
src/EditorFeatures/CSharpTest/EditAndContinue/SyntaxUtilitiesTests.cs
...atures/CSharpTest/EditAndContinue/SyntaxUtilitiesTests.cs
+92
-0
src/EditorFeatures/VisualBasicTest/EditAndContinue/SyntaxUtilitiesTests.vb
...s/VisualBasicTest/EditAndContinue/SyntaxUtilitiesTests.vb
+80
-0
src/Features/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
...atures/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
+20
-4
src/Features/VisualBasic/Portable/EditAndContinue/SyntaxUtilities.vb
...s/VisualBasic/Portable/EditAndContinue/SyntaxUtilities.vb
+15
-4
未找到文件。
src/EditorFeatures/CSharpTest/EditAndContinue/SyntaxUtilitiesTests.cs
浏览文件 @
03803fc6
...
...
@@ -2,6 +2,7 @@
using
System.Linq
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Xunit
;
using
SyntaxUtilities
=
Microsoft
.
CodeAnalysis
.
CSharp
.
EditAndContinue
.
SyntaxUtilities
;
...
...
@@ -59,5 +60,96 @@ static void Main(string[] args)
"
;
VerifySyntaxMap
(
source1
,
source2
);
}
[
Fact
]
public
void
FindLeafNodeAndPartner1
()
{
var
leftRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
@"
using System;
class C
{
public void M()
{
if (0 == 1)
{
Console.WriteLine(0);
}
}
}
"
).
GetRoot
();
var
leftPosition
=
leftRoot
.
DescendantNodes
().
OfType
<
LiteralExpressionSyntax
>().
ElementAt
(
2
).
SpanStart
;
// 0 within Console.WriteLine(0)
var
rightRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
@"
using System;
class C
{
public void M()
{
if (0 == 1)
{
if (2 == 3)
{
Console.WriteLine(0);
}
}
}
}
"
).
GetRoot
();
SyntaxUtilities
.
FindLeafNodeAndPartner
(
leftRoot
,
leftPosition
,
rightRoot
,
out
SyntaxNode
leftNode
,
out
SyntaxNode
rightNodeOpt
);
Assert
.
Equal
(
"0"
,
leftNode
.
ToString
());
Assert
.
Null
(
rightNodeOpt
);
}
[
Fact
]
public
void
FindLeafNodeAndPartner2
()
{
// Check that the method does not fail even if the index of the child (4)
// is greater than the count of children on the corresponding (from the upper side) node (3).
var
leftRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
@"
using System;
class C
{
public void M()
{
if (0 == 1)
{
Console.WriteLine(0);
Console.WriteLine(1);
Console.WriteLine(2);
Console.WriteLine(3);
}
}
}
"
).
GetRoot
();
var
leftPosition
=
leftRoot
.
DescendantNodes
().
OfType
<
LiteralExpressionSyntax
>().
ElementAt
(
5
).
SpanStart
;
// 3 within Console.WriteLine(3)
var
rightRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
@"
using System;
class C
{
public void M()
{
if (0 == 1)
{
if (2 == 3)
{
Console.WriteLine(0);
Console.WriteLine(1);
Console.WriteLine(2);
Console.WriteLine(3);
}
}
}
}
"
).
GetRoot
();
SyntaxUtilities
.
FindLeafNodeAndPartner
(
leftRoot
,
leftPosition
,
rightRoot
,
out
SyntaxNode
leftNode
,
out
SyntaxNode
rightNodeOpt
);
Assert
.
Equal
(
"3"
,
leftNode
.
ToString
());
Assert
.
Null
(
rightNodeOpt
);
}
}
}
src/EditorFeatures/VisualBasicTest/EditAndContinue/SyntaxUtilitiesTests.vb
浏览文件 @
03803fc6
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports
SyntaxUtilities
=
Microsoft
.
CodeAnalysis
.
VisualBasic
.
EditAndContinue
.
SyntaxUtilities
Namespace
Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EditAndContinue
...
...
@@ -47,5 +48,84 @@ End Class
"
VerifySyntaxMap
(
source1
,
source2
)
End
Sub
<
Fact
>
Public
Sub
FindLeafNodeAndPartner1
()
Dim
leftRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
"
Imports System;
Class C
Public Sub M()
If 0 = 1 Then
Console.WriteLine(0)
End If
End Sub
End Class
"
).
GetRoot
()
Dim
leftPosition
=
leftRoot
.
DescendantNodes
().
OfType
(
Of
LiteralExpressionSyntax
).
ElementAt
(
2
).
SpanStart
'0 within Console.WriteLine(0)
Dim
rightRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
"
Imports System;
Class C
Public Sub M()
If 0 = 1 Then
If 2 = 3 Then
Console.WriteLine(0)
End If
End If
End Sub
End Class
"
).
GetRoot
()
Dim
leftNode
As
SyntaxNode
=
Nothing
Dim
rightNodeOpt
As
SyntaxNode
=
Nothing
SyntaxUtilities
.
FindLeafNodeAndPartner
(
leftRoot
,
leftPosition
,
rightRoot
,
leftNode
,
rightNodeOpt
)
Assert
.
Equal
(
"0"
,
leftNode
.
ToString
())
Assert
.
Null
(
rightNodeOpt
)
End
Sub
<
Fact
>
Public
Sub
FindLeafNodeAndPartner2
()
' Check that the method does Not fail even if the index of the child (4)
' is greater than the count of children on the corresponding (from the upper side) node (3).
Dim
leftRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
"
Imports System;
Class C
Public Sub M()
If 0 = 1 Then
Console.WriteLine(0)
Console.WriteLine(1)
Console.WriteLine(2)
Console.WriteLine(3)
End If
End Sub
End Class
"
).
GetRoot
()
Dim
leftPosition
=
leftRoot
.
DescendantNodes
().
OfType
(
Of
LiteralExpressionSyntax
).
ElementAt
(
5
).
SpanStart
'3 within Console.WriteLine(3)
Dim
rightRoot
=
SyntaxFactory
.
ParseSyntaxTree
(
"
Imports System;
Class C
Public Sub M()
If 0 = 1 Then
If 2 = 3 Then
Console.WriteLine(0)
Console.WriteLine(1)
Console.WriteLine(2)
Console.WriteLine(3)
End If
End If
End Sub
End Class
"
).
GetRoot
()
Dim
leftNode
As
SyntaxNode
=
Nothing
Dim
rightNodeOpt
As
SyntaxNode
=
Nothing
SyntaxUtilities
.
FindLeafNodeAndPartner
(
leftRoot
,
leftPosition
,
rightRoot
,
leftNode
,
rightNodeOpt
)
Assert
.
Equal
(
"3"
,
leftNode
.
ToString
())
Assert
.
Null
(
rightNodeOpt
)
End
Sub
End
Class
End
Namespace
src/Features/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
浏览文件 @
03803fc6
...
...
@@ -114,20 +114,36 @@ public static void AssertIsBody(SyntaxNode syntax, bool allowLambda)
Debug
.
Assert
(
false
);
}
public
static
void
FindLeafNodeAndPartner
(
SyntaxNode
leftRoot
,
int
leftPosition
,
SyntaxNode
rightRoot
,
out
SyntaxNode
leftNode
,
out
SyntaxNode
rightNode
)
public
static
void
FindLeafNodeAndPartner
(
SyntaxNode
leftRoot
,
int
leftPosition
,
SyntaxNode
rightRoot
,
out
SyntaxNode
leftNode
,
out
SyntaxNode
rightNode
Opt
)
{
leftNode
=
leftRoot
;
rightNode
=
rightRoot
;
rightNode
Opt
=
rightRoot
;
while
(
true
)
{
Debug
.
Assert
(
leftNode
.
RawKind
==
rightNode
.
RawKind
);
if
(
rightNodeOpt
!=
null
&&
leftNode
.
RawKind
!=
rightNodeOpt
.
RawKind
)
{
rightNodeOpt
=
null
;
}
var
leftChild
=
leftNode
.
ChildThatContainsPosition
(
leftPosition
,
out
var
childIndex
);
if
(
leftChild
.
IsToken
)
{
return
;
}
rightNode
=
rightNode
.
ChildNodesAndTokens
()[
childIndex
].
AsNode
();
if
(
rightNodeOpt
!=
null
)
{
var
rightNodeChildNodesAndTokens
=
rightNodeOpt
.
ChildNodesAndTokens
();
if
(
childIndex
>=
0
&&
childIndex
<
rightNodeChildNodesAndTokens
.
Count
)
{
rightNodeOpt
=
rightNodeChildNodesAndTokens
[
childIndex
].
AsNode
();
}
else
{
rightNodeOpt
=
null
;
}
}
leftNode
=
leftChild
.
AsNode
();
}
}
...
...
src/Features/VisualBasic/Portable/EditAndContinue/SyntaxUtilities.vb
浏览文件 @
03803fc6
...
...
@@ -67,18 +67,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
leftPosition
As
Integer
,
rightRoot
As
SyntaxNode
,
<
Out
>
ByRef
leftNode
As
SyntaxNode
,
<
Out
>
ByRef
rightNode
As
SyntaxNode
)
<
Out
>
ByRef
rightNode
Opt
As
SyntaxNode
)
leftNode
=
leftRoot
rightNode
=
rightRoot
rightNode
Opt
=
rightRoot
While
True
Debug
.
Assert
(
leftNode
.
RawKind
=
rightNode
.
RawKind
)
If
rightNodeOpt
IsNot
Nothing
AndAlso
leftNode
.
RawKind
<>
rightNodeOpt
.
RawKind
Then
rightNodeOpt
=
Nothing
End
If
Dim
childIndex
As
Integer
=
0
Dim
leftChild
=
leftNode
.
ChildThatContainsPosition
(
leftPosition
,
childIndex
)
If
leftChild
.
IsToken
Then
Return
End
If
rightNode
=
rightNode
.
ChildNodesAndTokens
()(
childIndex
).
AsNode
()
If
rightNodeOpt
IsNot
Nothing
Then
Dim
rightNodeChildNodesAndTokens
=
rightNodeOpt
.
ChildNodesAndTokens
()
If
childIndex
>=
0
AndAlso
childIndex
<
rightNodeChildNodesAndTokens
.
Count
Then
rightNodeOpt
=
rightNodeChildNodesAndTokens
(
childIndex
).
AsNode
()
Else
rightNodeOpt
=
Nothing
End
If
End
If
leftNode
=
leftChild
.
AsNode
()
End
While
End
Sub
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录