Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
59fe532a
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,发现更多精彩内容 >>
提交
59fe532a
编写于
12月 20, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify and inline
上级
c607bbfd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
82 deletion
+40
-82
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
.../CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
+35
-72
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
...spaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
+3
-4
src/Workspaces/CSharp/Portable/Utilities/CSharpUseExplicitTypeHelper.cs
.../CSharp/Portable/Utilities/CSharpUseExplicitTypeHelper.cs
+1
-3
src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs
.../CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs
+1
-3
未找到文件。
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
浏览文件 @
59fe532a
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.CSharp.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.CodeStyle.TypeStyle
;
...
...
@@ -16,62 +14,57 @@ internal partial class CSharpTypeStyleHelper
{
protected
struct
State
{
p
rivate
readonly
Dictionary
<
UseVarPreference
,
ReportDiagnostic
>
_styleToSeverityMap
;
p
ublic
readonly
UseVarPreference
TypeStylePreference
;
public
UseVarPreference
TypeStylePreference
{
get
;
private
set
;
}
public
bool
IsInIntrinsicTypeContext
{
get
;
private
set
;
}
public
bool
IsTypeApparentInContext
{
get
;
private
set
;
}
public
bool
IsInVariableDeclarationContext
{
get
;
}
private
readonly
ReportDiagnostic
_forBuiltInTypes
;
private
readonly
ReportDiagnostic
_whenTypeIsApparent
;
private
readonly
ReportDiagnostic
_elsewhere
;
private
State
(
bool
isVariableDeclarationContext
)
public
readonly
bool
IsInIntrinsicTypeContext
;
public
readonly
bool
IsTypeApparentInContext
;
public
State
(
SyntaxNode
declaration
,
SemanticModel
semanticModel
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
TypeStylePreference
=
default
;
IsInIntrinsicTypeContext
=
default
;
IsTypeApparentInContext
=
default
;
this
.
IsInVariableDeclarationContext
=
isVariableDeclarationContext
;
_styleToSeverityMap
=
new
Dictionary
<
UseVarPreference
,
ReportDiagnostic
>(
);
}
var
styleForIntrinsicTypes
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarForBuiltInTypes
)
;
var
styleForApparent
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarWhenTypeIsApparent
);
var
styleForElsewhere
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarElsewhere
);
public
static
State
Generate
(
SyntaxNode
declaration
,
SemanticModel
semanticModel
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
var
isVariableDeclarationContext
=
declaration
.
IsKind
(
SyntaxKind
.
VariableDeclaration
);
var
state
=
new
State
(
isVariableDeclarationContext
);
state
.
Initialize
(
declaration
,
semanticModel
,
optionSet
,
cancellationToken
);
return
state
;
}
_forBuiltInTypes
=
styleForIntrinsicTypes
.
Notification
.
Severity
;
_whenTypeIsApparent
=
styleForApparent
.
Notification
.
Severity
;
_elsewhere
=
styleForElsewhere
.
Notification
.
Severity
;
public
ReportDiagnostic
GetDiagnosticSeverityPreference
()
{
if
(
IsInIntrinsicTypeContext
)
{
return
_styleToSeverityMap
[
UseVarPreference
.
ForBuiltInTypes
];
}
else
if
(
IsTypeApparentInContext
)
{
return
_styleToSeverityMap
[
UseVarPreference
.
WhenTypeIsApparent
];
}
else
{
return
_styleToSeverityMap
[
UseVarPreference
.
Elsewhere
];
}
}
var
stylePreferences
=
UseVarPreference
.
None
;
private
void
Initialize
(
SyntaxNode
declaration
,
SemanticModel
semanticModel
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
this
.
TypeStylePreference
=
GetCurrentTypeStylePreferences
(
optionSet
);
if
(
styleForIntrinsicTypes
.
Value
)
stylePreferences
|=
UseVarPreference
.
ForBuiltInTypes
;
if
(
styleForApparent
.
Value
)
stylePreferences
|=
UseVarPreference
.
WhenTypeIsApparent
;
if
(
styleForElsewhere
.
Value
)
stylePreferences
|=
UseVarPreference
.
Elsewhere
;
this
.
TypeStylePreference
=
stylePreferences
;
IsTypeApparentInContext
=
IsInVariableDeclarationContext
&&
IsTypeApparentInDeclaration
((
VariableDeclarationSyntax
)
declaration
,
semanticModel
,
TypeStylePreference
,
cancellationToken
);
declaration
.
IsKind
(
SyntaxKind
.
VariableDeclaration
)
&&
IsTypeApparentInDeclaration
((
VariableDeclarationSyntax
)
declaration
,
semanticModel
,
TypeStylePreference
,
cancellationToken
);
IsInIntrinsicTypeContext
=
IsPredefinedTypeInDeclaration
(
declaration
,
semanticModel
)
||
IsInferredPredefinedType
(
declaration
,
semanticModel
);
IsPredefinedTypeInDeclaration
(
declaration
,
semanticModel
)
||
IsInferredPredefinedType
(
declaration
,
semanticModel
);
}
public
ReportDiagnostic
GetDiagnosticSeverityPreference
()
=>
IsInIntrinsicTypeContext
?
_forBuiltInTypes
:
IsTypeApparentInContext
?
_whenTypeIsApparent
:
_elsewhere
;
/// <summary>
/// Returns true if type information could be gleaned by simply looking at the given statement.
/// This typically means that the type name occurs in right hand side of an assignment.
...
...
@@ -159,36 +152,6 @@ private TypeSyntax GetTypeSyntaxFromDeclaration(SyntaxNode declarationStatement)
DeclarationExpressionSyntax
declExpr
=>
declExpr
.
Type
,
_
=>
null
,
};
private
UseVarPreference
GetCurrentTypeStylePreferences
(
OptionSet
optionSet
)
{
var
stylePreferences
=
UseVarPreference
.
None
;
var
styleForIntrinsicTypes
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarForBuiltInTypes
);
var
styleForApparent
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarWhenTypeIsApparent
);
var
styleForElsewhere
=
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
VarElsewhere
);
_styleToSeverityMap
.
Add
(
UseVarPreference
.
ForBuiltInTypes
,
styleForIntrinsicTypes
.
Notification
.
Severity
);
_styleToSeverityMap
.
Add
(
UseVarPreference
.
WhenTypeIsApparent
,
styleForApparent
.
Notification
.
Severity
);
_styleToSeverityMap
.
Add
(
UseVarPreference
.
Elsewhere
,
styleForElsewhere
.
Notification
.
Severity
);
if
(
styleForIntrinsicTypes
.
Value
)
{
stylePreferences
|=
UseVarPreference
.
ForBuiltInTypes
;
}
if
(
styleForApparent
.
Value
)
{
stylePreferences
|=
UseVarPreference
.
WhenTypeIsApparent
;
}
if
(
styleForElsewhere
.
Value
)
{
stylePreferences
|=
UseVarPreference
.
Elsewhere
;
}
return
stylePreferences
;
}
}
}
}
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
浏览文件 @
59fe532a
...
...
@@ -50,8 +50,7 @@ public bool CanConvert()
internal
abstract
partial
class
CSharpTypeStyleHelper
{
protected
abstract
bool
IsStylePreferred
(
SemanticModel
semanticModel
,
OptionSet
optionSet
,
State
state
,
CancellationToken
cancellationToken
);
protected
abstract
bool
IsStylePreferred
(
in
State
state
);
public
virtual
TypeStyleResult
AnalyzeTypeName
(
TypeSyntax
typeName
,
SemanticModel
semanticModel
,
...
...
@@ -65,9 +64,9 @@ internal abstract partial class CSharpTypeStyleHelper
return
default
;
}
var
state
=
State
.
Gener
ate
(
var
state
=
new
St
ate
(
declaration
,
semanticModel
,
optionSet
,
cancellationToken
);
var
isStylePreferred
=
this
.
IsStylePreferred
(
semanticModel
,
optionSet
,
state
,
cancellationToken
);
var
isStylePreferred
=
this
.
IsStylePreferred
(
in
state
);
var
severity
=
state
.
GetDiagnosticSeverityPreference
();
return
new
TypeStyleResult
(
...
...
src/Workspaces/CSharp/Portable/Utilities/CSharpUseExplicitTypeHelper.cs
浏览文件 @
59fe532a
...
...
@@ -18,9 +18,7 @@ private CSharpUseExplicitTypeHelper()
{
}
protected
override
bool
IsStylePreferred
(
SemanticModel
semanticModel
,
OptionSet
optionSet
,
State
state
,
CancellationToken
cancellationToken
)
protected
override
bool
IsStylePreferred
(
in
State
state
)
{
var
stylePreferences
=
state
.
TypeStylePreference
;
...
...
src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs
浏览文件 @
59fe532a
...
...
@@ -71,9 +71,7 @@ protected override bool ShouldAnalyzeForEachStatement(ForEachStatementSyntax for
return
base
.
ShouldAnalyzeForEachStatement
(
forEachStatement
,
semanticModel
,
cancellationToken
);
}
protected
override
bool
IsStylePreferred
(
SemanticModel
semanticModel
,
OptionSet
optionSet
,
State
state
,
CancellationToken
cancellationToken
)
protected
override
bool
IsStylePreferred
(
in
State
state
)
{
var
stylePreferences
=
state
.
TypeStylePreference
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录