Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0d8b154f
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,发现更多精彩内容 >>
提交
0d8b154f
编写于
1月 26, 2016
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make registering OperationKind.None not to return any operation.
上级
855a58b5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
86 addition
and
2 deletion
+86
-2
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
+1
-1
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
...Sharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
+20
-0
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
...ore/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
+37
-0
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
+1
-1
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
...Basic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
+27
-0
未找到文件。
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
浏览文件 @
0d8b154f
...
...
@@ -71,7 +71,7 @@ public Collector(List<IOperation> nodes)
public
override
BoundNode
Visit
(
BoundNode
node
)
{
IOperation
operation
=
node
as
IOperation
;
if
(
operation
!=
null
)
if
(
operation
!=
null
&&
operation
.
Kind
!=
OperationKind
.
None
)
{
this
.
_nodes
.
Add
(
operation
);
// Certain child-operation of following operation kinds do not occur in bound nodes,
...
...
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
浏览文件 @
0d8b154f
...
...
@@ -1154,5 +1154,25 @@ public void M1()
Diagnostic
(
ParamsArrayTestAnalyzer
.
LongParamsDescriptor
.
Id
,
"new int[] { 2, 3, 4, 5, 6 }"
).
WithLocation
(
17
,
15
)
);
}
[
Fact
]
public
void
NoneOperationCSharp
()
{
// BoundStatementList is OperationKind.None
const
string
source
=
@"
class C
{
public void M0()
{
int x = 0;
int y = x++;
int z = y++;
}
}
"
;
CreateCompilationWithMscorlib45
(
source
)
.
VerifyDiagnostics
()
.
VerifyAnalyzerDiagnostics
(
new
DiagnosticAnalyzer
[]
{
new
NoneOperationTestAnalyzer
()
},
null
,
null
,
false
);
}
}
}
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
0d8b154f
...
...
@@ -1066,4 +1066,41 @@ private static long IntegralValue(object value)
return
0
;
}
}
/// <summary>Analyzer used to test None IOperations.</summary>
public
class
NoneOperationTestAnalyzer
:
DiagnosticAnalyzer
{
private
const
string
ReliabilityCategory
=
"Reliability"
;
// We should not see this warning triggered by any code
public
static
readonly
DiagnosticDescriptor
NoneOperationDescriptor
=
new
DiagnosticDescriptor
(
"NoneOperation"
,
"None operation found"
,
"an IOperation of None kind is found"
,
ReliabilityCategory
,
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
sealed
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
{
get
{
return
ImmutableArray
.
Create
(
NoneOperationDescriptor
);
}
}
public
sealed
override
void
Initialize
(
AnalysisContext
context
)
{
context
.
RegisterOperationAction
(
(
operationContext
)
=>
{
Report
(
operationContext
,
operationContext
.
Operation
.
Syntax
,
NoneOperationDescriptor
);
},
// None kind is only supposed to be used internally and will not actually register actions.
OperationKind
.
None
);
}
private
static
void
Report
(
OperationAnalysisContext
context
,
SyntaxNode
syntax
,
DiagnosticDescriptor
descriptor
)
{
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
syntax
.
GetLocation
()));
}
}
}
\ No newline at end of file
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
浏览文件 @
0d8b154f
...
...
@@ -35,7 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public
Overrides
Function
Visit
(
node
As
BoundNode
)
As
BoundNode
Dim
operation
=
TryCast
(
node
,
IOperation
)
If
operation
IsNot
Nothing
Then
If
operation
IsNot
Nothing
AndAlso
operation
.
Kind
<>
OperationKind
.
None
Then
Me
.
_nodes
.
Add
(
operation
)
' Certain child-operation of following operation kinds do not occur in bound nodes,
' and those child-operation nodes have to be added explicitly.
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
浏览文件 @
0d8b154f
...
...
@@ -1210,5 +1210,32 @@ End Class
Diagnostic
(
ParamsArrayTestAnalyzer
.
LongParamsDescriptor
.
Id
,
"New Integer() { 2, 3, 4, 5, 6 }"
).
WithLocation
(
13
,
15
),
Diagnostic
(
ParamsArrayTestAnalyzer
.
LongParamsDescriptor
.
Id
,
"New Integer() { 2, 3, 4, 5, 6 }"
).
WithLocation
(
13
,
15
))
End
Sub
<
Fact
>
Public
Sub
NoneOperationVisualBasic
()
' BoundCaseStatement is OperationKind.None
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
Class
C
Public
Sub
M1
(
x
as
Integer
)
Select
Case
x
Case
1
,
2
Exit
Select
Case
=
10
Exit
Select
Case
Else
Exit
Select
End
Select
End
Sub
End
Class
]]
>
</
file
>
</
compilation
>
Dim
comp
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
NoneOperationTestAnalyzer
},
Nothing
,
Nothing
,
False
)
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录