Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
54d9890c
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,发现更多精彩内容 >>
提交
54d9890c
编写于
10月 10, 2016
作者:
D
David Poeschl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove work for SymbolKind.Local based on offline discussions
上级
5a0f4536
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
63 addition
and
101 deletion
+63
-101
src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs
...harp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs
+40
-47
src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs
.../Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs
+0
-2
src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticStartAnalysisScope.cs
...rtable/DiagnosticAnalyzer/DiagnosticStartAnalysisScope.cs
+4
-21
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb
...asic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb
+14
-14
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
+4
-16
src/Test/Utilities/Shared/Diagnostics/TrackingDiagnosticAnalyzer.cs
...tilities/Shared/Diagnostics/TrackingDiagnosticAnalyzer.cs
+1
-1
未找到文件。
src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs
浏览文件 @
54d9890c
...
...
@@ -1657,15 +1657,13 @@ public partial class C33 { }
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InConstructor
()
public
void
TestParametersAnalyzer_InConstructor
()
{
string
source
=
@"
public class C
{
public C(int a, int b)
{
int c = 0, d = 0;
System.Console.WriteLine(c + d);
}
}
"
;
...
...
@@ -1673,24 +1671,20 @@ public C(int a, int b)
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
4
,
18
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
4
,
25
),
Diagnostic
(
"Local_ID"
,
"c"
).
WithLocation
(
6
,
13
),
Diagnostic
(
"Local_ID"
,
"d"
).
WithLocation
(
6
,
20
));
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
4
,
25
));
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InRegularMethod
()
public
void
TestParametersAnalyzer_InRegularMethod
()
{
string
source
=
@"
public class C
{
void M1(string a, string b)
{
C c = null;
System.Console.WriteLine(c);
}
}
"
;
...
...
@@ -1698,22 +1692,22 @@ void M1(string a, string b)
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
4
,
20
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
4
,
30
),
Diagnostic
(
"Local_ID"
,
"c"
).
WithLocation
(
6
,
11
));
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
4
,
30
));
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/14061"
)
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAndParametersAnalyzer_Lambda
s
()
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
ParametersAnalyzer_InIndexer
s
()
{
string
source
=
@"
public class C
{
void M2()
public int this[int index]
{
System.Func<int, int, int> x = (int a, int b) => b;
get { return 0; }
set { }
}
}
"
;
...
...
@@ -1721,62 +1715,61 @@ void M2()
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Local_ID"
,
"x"
).
WithLocation
(
6
,
36
),
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
6
,
45
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
6
,
52
));
Diagnostic
(
"Parameter_ID"
,
"index"
).
WithLocation
(
4
,
25
));
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/14061"
),
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAndParametersAnalyzer_InAnonymousMethod
s
()
public
void
Test
ParametersAnalyzer_Lambda
s
()
{
string
source
=
@"
public class C
{
void M
3
()
void M
2
()
{
M4(delegate (int x, int y) { })
;
System.Func<int, int, int> x = (int a, int b) => b
;
}
void M4(System.Action<int, int> a) { }
}
"
;
var
tree
=
CSharpSyntaxTree
.
ParseText
(
source
,
path
:
"Source.cs"
);
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
9
,
37
),
Diagnostic
(
"Parameter_ID"
,
"x"
).
WithLocation
(
6
,
26
),
Diagnostic
(
"Parameter_ID"
,
"y"
).
WithLocation
(
6
,
33
));
Diagnostic
(
"Local_ID"
,
"x"
).
WithLocation
(
6
,
36
),
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
6
,
45
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
6
,
52
));
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAndParametersAnalyzer_InIndexer
s
()
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/14061"
)
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
ParametersAnalyzer_InAnonymousMethod
s
()
{
string
source
=
@"
public class C
{
public int this[int index]
void M3()
{
get { return 0; }
set { }
M4(delegate (int x, int y) { });
}
void M4(System.Action<int, int> a) { }
}
"
;
var
tree
=
CSharpSyntaxTree
.
ParseText
(
source
,
path
:
"Source.cs"
);
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"index"
).
WithLocation
(
4
,
25
));
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
9
,
37
),
Diagnostic
(
"Parameter_ID"
,
"x"
).
WithLocation
(
6
,
26
),
Diagnostic
(
"Parameter_ID"
,
"y"
).
WithLocation
(
6
,
33
));
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InDelegateTypes
()
public
void
TestParametersAnalyzer_InDelegateTypes
()
{
string
source
=
@"
public class C
...
...
@@ -1788,14 +1781,14 @@ public class C
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"x"
).
WithLocation
(
4
,
25
),
Diagnostic
(
"Parameter_ID"
,
"y"
).
WithLocation
(
4
,
35
));
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InOperators
()
public
void
TestParametersAnalyzer_InOperators
()
{
string
source
=
@"
public class C
...
...
@@ -1807,13 +1800,13 @@ public class C
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"c"
).
WithLocation
(
4
,
44
));
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InExplicitInterfaceImplementations
()
public
void
TestParametersAnalyzer_InExplicitInterfaceImplementations
()
{
string
source
=
@"
interface I
...
...
@@ -1830,7 +1823,7 @@ public class C : I
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"c"
).
WithLocation
(
9
,
18
),
Diagnostic
(
"Parameter_ID"
,
"d"
).
WithLocation
(
9
,
25
),
...
...
@@ -1839,7 +1832,7 @@ public class C : I
}
[
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InExtensionMethods
()
public
void
TestParametersAnalyzer_InExtensionMethods
()
{
string
source
=
@"
public static class C
...
...
@@ -1851,14 +1844,14 @@ public static class C
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"x"
).
WithLocation
(
4
,
28
),
Diagnostic
(
"Parameter_ID"
,
"y"
).
WithLocation
(
4
,
35
));
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/14061"
),
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)]
public
void
Test
LocalsAnd
ParametersAnalyzer_InLocalFunctions
()
public
void
TestParametersAnalyzer_InLocalFunctions
()
{
string
source
=
@"
public class C
...
...
@@ -1877,7 +1870,7 @@ void M2(int a, int b)
var
compilation
=
CreateCompilationWithMscorlib45
(
new
[]
{
tree
});
compilation
.
VerifyDiagnostics
();
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerFor
LocalsAnd
Parameters
()
};
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
AnalyzerForParameters
()
};
compilation
.
VerifyAnalyzerDiagnostics
(
analyzers
,
null
,
null
,
true
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
4
,
18
),
// ctor
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
4
,
25
),
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs
浏览文件 @
54d9890c
...
...
@@ -1200,8 +1200,6 @@ public struct OperationAnalysisContext
/// </summary>
public
CancellationToken
CancellationToken
=>
_cancellationToken
;
internal
Func
<
Diagnostic
,
bool
>
IsSupportedDiagnostic
=>
_isSupportedDiagnostic
;
public
OperationAnalysisContext
(
IOperation
operation
,
ISymbol
containingSymbol
,
Compilation
compilation
,
AnalyzerOptions
options
,
Action
<
Diagnostic
>
reportDiagnostic
,
Func
<
Diagnostic
,
bool
>
isSupportedDiagnostic
,
CancellationToken
cancellationToken
)
{
_operation
=
operation
;
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticStartAnalysisScope.cs
浏览文件 @
54d9890c
...
...
@@ -609,27 +609,10 @@ public void RegisterSymbolAction(DiagnosticAnalyzer analyzer, Action<SymbolAnaly
this
.
GetOrCreateAnalyzerActions
(
analyzer
).
AddSymbolAction
(
analyzerAction
);
_symbolActions
=
_symbolActions
.
Add
(
analyzerAction
);
// The SymbolAnalyzerAction does not handle SymbolKind.Local or SymbolKind.Parameter
// because the compiler does not make CompilationEvents for them. As a workaround,
// handle them specially by registering further OperationActions (for
// VariableDeclarations) or SymbolActions (for Methods) and utilize the results of
// those to construct the necessary SymbolAnalysisContexts.
if
(
symbolKinds
.
Contains
(
SymbolKind
.
Local
))
{
RegisterOperationAction
(
analyzer
,
opContext
=>
{
var
varDecl
=
(
IVariableDeclaration
)
opContext
.
Operation
;
action
(
new
SymbolAnalysisContext
(
varDecl
.
Variable
,
opContext
.
Compilation
,
opContext
.
Options
,
opContext
.
ReportDiagnostic
,
opContext
.
IsSupportedDiagnostic
,
opContext
.
CancellationToken
));
},
ImmutableArray
.
Create
(
OperationKind
.
VariableDeclaration
));
}
// The SymbolAnalyzerAction does not handle SymbolKind.Parameter because the compiler
// does not make CompilationEvents for them. As a workaround, handle them specially by
// registering further SymbolActions (for Methods) and utilize the results to construct
// the necessary SymbolAnalysisContexts.
if
(
symbolKinds
.
Contains
(
SymbolKind
.
Parameter
))
{
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb
浏览文件 @
54d9890c
...
...
@@ -982,7 +982,7 @@ End Class
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InRegularMethods
()
Public
Sub
TestParametersAnalyzer_InRegularMethods
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -996,13 +996,13 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
18
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
32
))
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InConstructors
()
Public
Sub
TestParametersAnalyzer_InConstructors
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1016,13 +1016,13 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
20
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
34
))
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InIndexers
()
Public
Sub
TestParametersAnalyzer_InIndexers
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1041,14 +1041,14 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
34
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
48
),
Diagnostic
(
"Parameter_ID"
,
"Value"
).
WithLocation
(
6
,
19
))
End
Sub
<
Fact
(
Skip
:
=
"https://github.com/dotnet/roslyn/issues/14062"
),
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InDelegateTypes
()
Public
Sub
TestParametersAnalyzer_InDelegateTypes
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1061,13 +1061,13 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
34
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
48
))
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InOperators
()
Public
Sub
TestParametersAnalyzer_InOperators
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1082,13 +1082,13 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"h1"
).
WithLocation
(
2
,
36
),
Diagnostic
(
"Parameter_ID"
,
"h2"
).
WithLocation
(
2
,
51
))
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InInterfaceImplementations
()
Public
Sub
TestParametersAnalyzer_InInterfaceImplementations
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1107,7 +1107,7 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
11
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
25
),
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
7
,
18
),
...
...
@@ -1115,7 +1115,7 @@ End Class
End
Sub
<
Fact
,
WorkItem
(
8753
,
"https://github.com/dotnet/roslyn/issues/8753"
)
>
Public
Sub
Test
LocalsAnd
ParametersAnalyzer_InParameterizedProperties
()
Public
Sub
TestParametersAnalyzer_InParameterizedProperties
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
...
...
@@ -1132,7 +1132,7 @@ End Class
Dim
comp
=
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerFor
LocalsAnd
Parameters
},
Nothing
,
Nothing
,
False
,
comp
.
VerifyAnalyzerDiagnostics
({
New
AnalyzerForParameters
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
"Parameter_ID"
,
"a"
).
WithLocation
(
2
,
35
),
Diagnostic
(
"Parameter_ID"
,
"b"
).
WithLocation
(
2
,
49
))
End
Sub
...
...
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
浏览文件 @
54d9890c
...
...
@@ -1069,16 +1069,8 @@ private void OnCompilationStart(CompilationStartAnalysisContext context)
}
[
DiagnosticAnalyzer
(
LanguageNames
.
CSharp
,
LanguageNames
.
VisualBasic
)]
public
class
AnalyzerFor
LocalsAnd
Parameters
:
DiagnosticAnalyzer
public
class
AnalyzerForParameters
:
DiagnosticAnalyzer
{
public
static
readonly
DiagnosticDescriptor
LocalDescriptor
=
new
DiagnosticDescriptor
(
"Local_ID"
,
"Local_Title"
,
"Local_Message"
,
"Local_Category"
,
defaultSeverity
:
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
static
readonly
DiagnosticDescriptor
ParameterDescriptor
=
new
DiagnosticDescriptor
(
"Parameter_ID"
,
"Parameter_Title"
,
...
...
@@ -1087,20 +1079,16 @@ public class AnalyzerForLocalsAndParameters : DiagnosticAnalyzer
defaultSeverity
:
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
LocalDescriptor
,
ParameterDescriptor
);
public
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
ParameterDescriptor
);
public
override
void
Initialize
(
AnalysisContext
context
)
{
context
.
RegisterSymbolAction
(
SymbolAction
,
SymbolKind
.
Parameter
,
SymbolKind
.
Local
);
context
.
RegisterSymbolAction
(
SymbolAction
,
SymbolKind
.
Parameter
);
}
private
void
SymbolAction
(
SymbolAnalysisContext
context
)
{
var
diagnostic
=
context
.
Symbol
.
Kind
==
SymbolKind
.
Parameter
?
Diagnostic
.
Create
(
ParameterDescriptor
,
context
.
Symbol
.
Locations
[
0
])
:
Diagnostic
.
Create
(
LocalDescriptor
,
context
.
Symbol
.
Locations
[
0
]);
context
.
ReportDiagnostic
(
diagnostic
);
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
ParameterDescriptor
,
context
.
Symbol
.
Locations
[
0
]));
}
}
}
...
...
src/Test/Utilities/Shared/Diagnostics/TrackingDiagnosticAnalyzer.cs
浏览文件 @
54d9890c
...
...
@@ -77,7 +77,7 @@ public void VerifyAnalyzeSymbolCalledForAllSymbolKinds()
{
var
expectedSymbolKinds
=
new
[]
{
SymbolKind
.
Event
,
SymbolKind
.
Field
,
SymbolKind
.
Local
,
SymbolKind
.
Method
,
SymbolKind
.
NamedType
,
SymbolKind
.
Namespace
,
SymbolKind
.
Parameter
,
SymbolKind
.
Property
SymbolKind
.
Event
,
SymbolKind
.
Field
,
SymbolKind
.
Method
,
SymbolKind
.
NamedType
,
SymbolKind
.
Namespace
,
SymbolKind
.
Parameter
,
SymbolKind
.
Property
};
var
actualSymbolKinds
=
_callLog
.
Where
(
a
=>
FilterByAbstractName
(
a
,
"Symbol"
)).
Where
(
e
=>
e
.
SymbolKind
.
HasValue
).
Select
(
e
=>
e
.
SymbolKind
.
Value
).
Distinct
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录