Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
54505f0e
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,发现更多精彩内容 >>
提交
54505f0e
编写于
3月 17, 2015
作者:
K
Kevin Pilch-Bisson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1327 from Pilchie/Fix1297
Handle null AccessorList in expression bodied properties
上级
55aab78c
0d713477
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
43 deletion
+66
-43
src/EditorFeatures/CSharp/Completion/CompletionProviders/OverrideCompletionProvider.cs
...pletion/CompletionProviders/OverrideCompletionProvider.cs
+10
-12
src/EditorFeatures/CSharp/LineSeparators/CSharpLineSeparatorService.cs
...tures/CSharp/LineSeparators/CSharpLineSeparatorService.cs
+11
-30
src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs
...rFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs
+44
-0
src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs
...spaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs
+1
-1
未找到文件。
src/EditorFeatures/CSharp/Completion/CompletionProviders/OverrideCompletionProvider.cs
浏览文件 @
54505f0e
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.Completion.CompletionProviders
namespace
Microsoft.CodeAnalysis.Editor.CSharp.Completion.CompletionProviders
{
{
...
@@ -217,27 +218,24 @@ protected override int GetTargetCaretPosition(SyntaxNode caretTarget)
...
@@ -217,27 +218,24 @@ protected override int GetTargetCaretPosition(SyntaxNode caretTarget)
return
lastStatement
.
GetLocation
().
SourceSpan
.
End
;
return
lastStatement
.
GetLocation
().
SourceSpan
.
End
;
}
}
}
}
else
if
(
caretTarget
is
PropertyDeclarationSyntax
)
else
if
(
caretTarget
is
Base
PropertyDeclarationSyntax
)
{
{
// property: no accesors; move to the end of the declaration
// property: no accessors; move to the end of the declaration
var
propertyDeclaration
=
(
PropertyDeclarationSyntax
)
caretTarget
;
var
propertyDeclaration
=
(
BasePropertyDeclarationSyntax
)
caretTarget
;
if
(!
propertyDeclaration
.
AccessorList
.
Accessors
.
Any
())
if
(
propertyDeclaration
.
AccessorList
!=
null
&&
propertyDeclaration
.
AccessorList
.
Accessors
.
Any
())
{
return
propertyDeclaration
.
GetLocation
().
SourceSpan
.
End
;
}
else
{
{
// move to the end of the last statement of the first accessor
// move to the end of the last statement of the first accessor
var
firstAccessorStatement
=
propertyDeclaration
.
AccessorList
.
Accessors
.
First
().
Body
.
Statements
.
Last
();
var
firstAccessorStatement
=
propertyDeclaration
.
AccessorList
.
Accessors
.
First
().
Body
.
Statements
.
Last
();
return
firstAccessorStatement
.
GetLocation
().
SourceSpan
.
End
;
return
firstAccessorStatement
.
GetLocation
().
SourceSpan
.
End
;
}
}
else
{
return
propertyDeclaration
.
GetLocation
().
SourceSpan
.
End
;
}
}
}
else
else
{
{
// indexer: move to the end of the last statement
throw
ExceptionUtilities
.
Unreachable
;
var
indexerDeclaration
=
(
IndexerDeclarationSyntax
)
caretTarget
;
var
firstAccessorStatement
=
indexerDeclaration
.
AccessorList
.
Accessors
.
First
().
Body
.
Statements
.
Last
();
return
firstAccessorStatement
.
GetLocation
().
SourceSpan
.
End
;
}
}
}
}
}
}
...
...
src/EditorFeatures/CSharp/LineSeparators/CSharpLineSeparatorService.cs
浏览文件 @
54505f0e
...
@@ -148,47 +148,28 @@ private static bool IsBadMethod(SyntaxNode node)
...
@@ -148,47 +148,28 @@ private static bool IsBadMethod(SyntaxNode node)
private
static
bool
IsBadProperty
(
SyntaxNode
node
)
private
static
bool
IsBadProperty
(
SyntaxNode
node
)
{
{
var
propDecl
=
node
as
PropertyDeclarationSyntax
;
return
IsBadAccessorList
(
node
as
PropertyDeclarationSyntax
);
if
(
propDecl
!=
null
)
{
if
(
propDecl
.
AccessorList
.
OpenBraceToken
.
IsMissing
||
propDecl
.
AccessorList
.
CloseBraceToken
.
IsMissing
)
{
return
true
;
}
}
return
false
;
}
}
private
static
bool
IsBadEvent
(
SyntaxNode
node
)
private
static
bool
IsBadEvent
(
SyntaxNode
node
)
{
{
var
eventDecl
=
node
as
EventDeclarationSyntax
;
return
IsBadAccessorList
(
node
as
EventDeclarationSyntax
);
if
(
eventDecl
!=
null
)
{
if
(
eventDecl
.
AccessorList
.
OpenBraceToken
.
IsMissing
||
eventDecl
.
AccessorList
.
CloseBraceToken
.
IsMissing
)
{
return
true
;
}
}
return
false
;
}
}
private
static
bool
IsBadIndexer
(
SyntaxNode
node
)
private
static
bool
IsBadIndexer
(
SyntaxNode
node
)
{
{
var
indexerDecl
=
node
as
IndexerDeclarationSyntax
;
return
IsBadAccessorList
(
node
as
IndexerDeclarationSyntax
);
if
(
indexerDecl
!=
null
)
}
private
static
bool
IsBadAccessorList
(
BasePropertyDeclarationSyntax
baseProperty
)
{
if
(
baseProperty
?.
AccessorList
==
null
)
{
{
if
(
indexerDecl
.
AccessorList
.
OpenBraceToken
.
IsMissing
||
return
false
;
indexerDecl
.
AccessorList
.
CloseBraceToken
.
IsMissing
)
{
return
true
;
}
}
}
return
false
;
return
baseProperty
.
AccessorList
.
OpenBraceToken
.
IsMissing
||
baseProperty
.
AccessorList
.
CloseBraceToken
.
IsMissing
;
}
}
private
static
bool
IsBadConstructor
(
SyntaxNode
node
)
private
static
bool
IsBadConstructor
(
SyntaxNode
node
)
...
...
src/EditorFeatures/CSharpTest/LineSeparators/LineSeparatorTests.cs
浏览文件 @
54505f0e
...
@@ -414,6 +414,50 @@ static void Main(string[] args)
...
@@ -414,6 +414,50 @@ static void Main(string[] args)
AssertTagsOnBracesOrSemicolons
(
file
,
2
,
4
);
AssertTagsOnBracesOrSemicolons
(
file
,
2
,
4
);
}
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
LineSeparators
)]
[
WorkItem
(
1297
,
"https://github.com/dotnet/roslyn/issues/1297"
)]
public
void
ExpressionBodiedProperty
()
{
AssertTagsOnBracesOrSemicolons
(
@"class C
{
int Prop => 3;
void M()
{
}
}"
,
0
,
2
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
LineSeparators
)]
[
WorkItem
(
1297
,
"https://github.com/dotnet/roslyn/issues/1297"
)]
public
void
ExpressionBodiedIndexer
()
{
AssertTagsOnBracesOrSemicolons
(
@"class C
{
int this[int i] => 3;
void M()
{
}
}"
,
0
,
2
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
LineSeparators
)]
[
WorkItem
(
1297
,
"https://github.com/dotnet/roslyn/issues/1297"
)]
public
void
ExpressionBodiedEvent
()
{
// This is not valid code, and parses all wrong, but just in case a user writes it. Note
// the 3 is because there is a skipped } in the event declaration.
AssertTagsOnBracesOrSemicolons
(
@"class C
{
event EventHandler MyEvent => 3;
void M()
{
}
}"
,
3
);
}
#
region
Negative
(
incomplete
)
tests
#
region
Negative
(
incomplete
)
tests
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
LineSeparators
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
LineSeparators
)]
...
...
src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs
浏览文件 @
54505f0e
...
@@ -1156,7 +1156,7 @@ public static IEnumerable<SyntaxNode> GetBodies(this SyntaxNode node)
...
@@ -1156,7 +1156,7 @@ public static IEnumerable<SyntaxNode> GetBodies(this SyntaxNode node)
}
}
var
property
=
node
as
BasePropertyDeclarationSyntax
;
var
property
=
node
as
BasePropertyDeclarationSyntax
;
if
(
property
!=
null
)
if
(
property
!=
null
&&
property
.
AccessorList
!=
null
)
{
{
return
property
.
AccessorList
.
Accessors
.
Select
(
a
=>
a
.
Body
).
WhereNotNull
();
return
property
.
AccessorList
.
Accessors
.
Select
(
a
=>
a
.
Body
).
WhereNotNull
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录