Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a23ff109
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,发现更多精彩内容 >>
提交
a23ff109
编写于
11月 14, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
11月 14, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev15-rc2' into valueTuple4
上级
e68ac8f8
6526861d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
51 addition
and
5 deletion
+51
-5
src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs
...AnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs
+19
-0
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalysisState.cs
...mpilers/Core/Portable/DiagnosticAnalyzer/AnalysisState.cs
+4
-2
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerActionCounts.cs
.../Core/Portable/DiagnosticAnalyzer/AnalyzerActionCounts.cs
+2
-0
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
...pilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
+6
-1
src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs
...e/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs
+2
-2
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
+18
-0
未找到文件。
src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs
浏览文件 @
a23ff109
...
...
@@ -4,11 +4,13 @@
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Roslyn.Test.Utilities
;
using
Roslyn.Utilities
;
using
Xunit
;
using
static
Microsoft
.
CodeAnalysis
.
CommonDiagnosticAnalyzers
;
namespace
Microsoft.CodeAnalysis.UnitTests.Diagnostics
{
...
...
@@ -45,5 +47,22 @@ public void GetEffectiveDiagnostics()
AssertEx
.
Equal
(
new
[]
{
d1
},
filtered
);
}
[
Fact
]
public
void
GetAnalyzerTelemetry
()
{
var
compilation
=
CSharpCompilation
.
Create
(
"c"
,
options
:
new
CSharpCompilationOptions
(
OutputKind
.
DynamicallyLinkedLibrary
));
DiagnosticAnalyzer
analyzer
=
new
AnalyzerWithDisabledRules
();
var
analyzers
=
ImmutableArray
.
Create
(
analyzer
);
var
analyzerOptions
=
new
AnalyzerOptions
(
ImmutableArray
<
AdditionalText
>.
Empty
);
var
compWithAnalyzers
=
new
CompilationWithAnalyzers
(
compilation
,
analyzers
,
analyzerOptions
,
CancellationToken
.
None
);
var
analysisResult
=
compWithAnalyzers
.
GetAnalysisResultAsync
(
CancellationToken
.
None
).
Result
;
Assert
.
Empty
(
analysisResult
.
CompilationDiagnostics
);
// Even though the analyzer registers a symbol action, it should never be invoked because all of its rules are disabled.
var
analyzerTelemetry
=
compWithAnalyzers
.
GetAnalyzerTelemetryInfoAsync
(
analyzer
,
CancellationToken
.
None
).
Result
;
Assert
.
Equal
(
0
,
analyzerTelemetry
.
SymbolActionsCount
);
}
}
}
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalysisState.cs
浏览文件 @
a23ff109
...
...
@@ -51,6 +51,7 @@ internal partial class AnalysisState
private
readonly
HashSet
<
SyntaxTree
>
_treesWithGeneratedSourceEvents
;
private
readonly
HashSet
<
ISymbol
>
_partialSymbolsWithGeneratedSourceEvents
;
private
readonly
CompilationData
_compilationData
;
private
readonly
CompilationOptions
_compilationOptions
;
private
bool
_compilationStartGenerated
;
private
bool
_compilationEndGenerated
;
...
...
@@ -63,11 +64,12 @@ internal partial class AnalysisState
private
readonly
ObjectPool
<
HashSet
<
CompilationEvent
>>
_compilationEventsPool
;
private
readonly
HashSet
<
CompilationEvent
>
_pooledEventsWithAnyActionsSet
;
public
AnalysisState
(
ImmutableArray
<
DiagnosticAnalyzer
>
analyzers
,
CompilationData
compilationData
)
public
AnalysisState
(
ImmutableArray
<
DiagnosticAnalyzer
>
analyzers
,
CompilationData
compilationData
,
CompilationOptions
compilationOptions
)
{
_gate
=
new
object
();
_analyzerStateMap
=
CreateAnalyzerStateMap
(
analyzers
,
out
_analyzerStates
);
_compilationData
=
compilationData
;
_compilationOptions
=
compilationOptions
;
_pendingSourceEvents
=
new
Dictionary
<
SyntaxTree
,
HashSet
<
CompilationEvent
>>();
_pendingNonSourceEvents
=
new
HashSet
<
CompilationEvent
>();
_lazyAnalyzerActionCountsMap
=
null
;
...
...
@@ -402,7 +404,7 @@ private async Task EnsureAnalyzerActionCountsInitializedAsync(AnalyzerDriver dri
var
builder
=
ImmutableDictionary
.
CreateBuilder
<
DiagnosticAnalyzer
,
AnalyzerActionCounts
>();
foreach
(
var
analyzer
in
_analyzerStateMap
.
Keys
)
{
var
actionCounts
=
await
driver
.
GetAnalyzerActionCountsAsync
(
analyzer
,
cancellationToken
).
ConfigureAwait
(
false
);
var
actionCounts
=
await
driver
.
GetAnalyzerActionCountsAsync
(
analyzer
,
_compilationOptions
,
cancellationToken
).
ConfigureAwait
(
false
);
builder
.
Add
(
analyzer
,
actionCounts
);
}
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerActionCounts.cs
浏览文件 @
a23ff109
...
...
@@ -7,6 +7,8 @@ namespace Microsoft.CodeAnalysis.Diagnostics.Telemetry
/// </summary>
internal
class
AnalyzerActionCounts
{
internal
static
readonly
AnalyzerActionCounts
Empty
=
new
AnalyzerActionCounts
(
null
);
internal
AnalyzerActionCounts
(
AnalyzerActions
analyzerActions
)
:
this
(
analyzerActions
?.
CompilationStartActionsCount
??
0
,
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
浏览文件 @
a23ff109
...
...
@@ -1298,9 +1298,14 @@ protected bool IsGeneratedCode(SyntaxTree tree)
protected
bool
DoNotAnalyzeGeneratedCode
=>
_doNotAnalyzeGeneratedCode
;
internal
async
Task
<
AnalyzerActionCounts
>
GetAnalyzerActionCountsAsync
(
DiagnosticAnalyzer
analyzer
,
CancellationToken
cancellationToken
)
internal
async
Task
<
AnalyzerActionCounts
>
GetAnalyzerActionCountsAsync
(
DiagnosticAnalyzer
analyzer
,
C
ompilationOptions
compilationOptions
,
C
ancellationToken
cancellationToken
)
{
var
executor
=
analyzerExecutor
.
WithCancellationToken
(
cancellationToken
);
if
(
IsDiagnosticAnalyzerSuppressed
(
analyzer
,
compilationOptions
,
analyzerManager
,
executor
))
{
return
AnalyzerActionCounts
.
Empty
;
}
var
analyzerActions
=
await
analyzerManager
.
GetAnalyzerActionsAsync
(
analyzer
,
executor
).
ConfigureAwait
(
false
);
return
new
AnalyzerActionCounts
(
analyzerActions
);
}
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs
浏览文件 @
a23ff109
...
...
@@ -129,7 +129,7 @@ private CompilationWithAnalyzers(Compilation compilation, ImmutableArray<Diagnos
_cancellationToken
=
cancellationToken
;
_compilationData
=
new
CompilationData
(
_compilation
);
_analysisState
=
new
AnalysisState
(
analyzers
,
_compilationData
);
_analysisState
=
new
AnalysisState
(
analyzers
,
_compilationData
,
_compilation
.
Options
);
_analysisResultBuilder
=
new
AnalysisResultBuilder
(
analysisOptions
.
LogAnalyzerExecutionTime
,
analyzers
);
_driverPool
=
new
ObjectPool
<
AnalyzerDriver
>(()
=>
_compilation
.
AnalyzerForLanguage
(
analyzers
,
AnalyzerManager
.
Instance
));
_executingConcurrentTreeTasksOpt
=
analysisOptions
.
ConcurrentAnalysis
?
new
Dictionary
<
SyntaxTree
,
Tuple
<
Task
,
CancellationTokenSource
>>()
:
null
;
...
...
@@ -412,7 +412,7 @@ private async Task ComputeAnalyzerDiagnosticsWithoutStateTrackingAsync(Cancellat
var
analyzerActionCounts
=
new
Dictionary
<
DiagnosticAnalyzer
,
AnalyzerActionCounts
>(
analyzers
.
Length
);
foreach
(
var
analyzer
in
analyzers
)
{
var
actionCounts
=
await
driver
.
GetAnalyzerActionCountsAsync
(
analyzer
,
cancellationToken
).
ConfigureAwait
(
false
);
var
actionCounts
=
await
driver
.
GetAnalyzerActionCountsAsync
(
analyzer
,
c
ompilation
.
Options
,
c
ancellationToken
).
ConfigureAwait
(
false
);
analyzerActionCounts
.
Add
(
analyzer
,
actionCounts
);
}
Func
<
DiagnosticAnalyzer
,
AnalyzerActionCounts
>
getAnalyzerActionCounts
=
analyzer
=>
analyzerActionCounts
[
analyzer
];
...
...
src/Test/Utilities/Desktop/CommonDiagnosticAnalyzers.cs
浏览文件 @
a23ff109
...
...
@@ -384,6 +384,24 @@ public sealed class AnalyzerWithNoActions : DiagnosticAnalyzer
public
override
void
Initialize
(
AnalysisContext
context
)
{
}
}
[
DiagnosticAnalyzer
(
LanguageNames
.
CSharp
,
LanguageNames
.
VisualBasic
)]
public
sealed
class
AnalyzerWithDisabledRules
:
DiagnosticAnalyzer
{
public
static
readonly
DiagnosticDescriptor
Rule
=
new
DiagnosticDescriptor
(
"ID1"
,
"Title1"
,
"Message1"
,
"Category1"
,
defaultSeverity
:
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
false
);
public
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
Rule
);
public
override
void
Initialize
(
AnalysisContext
context
)
{
context
.
RegisterSymbolAction
(
_
=>
{
},
SymbolKind
.
NamedType
);
}
}
[
DiagnosticAnalyzer
(
LanguageNames
.
CSharp
,
LanguageNames
.
VisualBasic
)]
public
sealed
class
EnsureNoMergedNamespaceSymbolAnalyzer
:
DiagnosticAnalyzer
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录