Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7177e45f
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,发现更多精彩内容 >>
提交
7177e45f
编写于
6月 28, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify null checks
上级
7c5642ec
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
51 addition
and
103 deletion
+51
-103
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
...EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
+2
-2
src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs
...ualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs
+21
-41
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+6
-12
src/Workspaces/CSharp/Portable/Formatting/FormattingHelpers.cs
...orkspaces/CSharp/Portable/Formatting/FormattingHelpers.cs
+13
-23
src/Workspaces/CSharp/Portable/Formatting/Rules/SuppressFormattingRule.cs
...Sharp/Portable/Formatting/Rules/SuppressFormattingRule.cs
+6
-12
src/Workspaces/Core/Portable/Options/Option`1.cs
src/Workspaces/Core/Portable/Options/Option`1.cs
+1
-6
src/Workspaces/Core/Portable/Options/PerLanguageOption.cs
src/Workspaces/Core/Portable/Options/PerLanguageOption.cs
+1
-6
src/Workspaces/Core/Portable/Shared/NormalizedTextSpanCollection.cs
...aces/Core/Portable/Shared/NormalizedTextSpanCollection.cs
+1
-1
未找到文件。
src/EditorFeatures/Test/CodeGeneration/CodeGenerationTests.cs
浏览文件 @
7177e45f
...
...
@@ -629,7 +629,7 @@ private static ImmutableArray<ISymbol> GetSymbols(ImmutableArray<Func<SemanticMo
private
static
Func
<
SemanticModel
,
INamedTypeSymbol
>
GetTypeSymbol
(
string
typeMetadataName
)
{
return
s
=>
s
==
null
?
null
:
s
.
Compilation
.
GetTypeByMetadataName
(
typeMetadataName
);
return
s
=>
s
?
.
Compilation
.
GetTypeByMetadataName
(
typeMetadataName
);
}
internal
static
IEnumerable
<
SyntaxToken
>
CreateModifierTokens
(
Editing
.
DeclarationModifiers
modifiers
,
string
language
)
...
...
@@ -781,7 +781,7 @@ internal class TestContext : IDisposable
public
static
async
Task
<
TestContext
>
CreateAsync
(
string
initial
,
string
expected
,
string
forceLanguage
=
null
,
bool
ignoreResult
=
false
)
{
var
language
=
forceLanguage
!=
null
?
forceLanguage
:
GetLanguage
(
initial
);
var
language
=
forceLanguage
??
GetLanguage
(
initial
);
var
isVisualBasic
=
language
==
LanguageNames
.
VisualBasic
;
var
workspace
=
CreateWorkspaceFromFile
(
initial
.
NormalizeLineEndings
(),
isVisualBasic
,
null
,
null
);
var
semanticModel
=
await
workspace
.
CurrentSolution
.
Projects
.
Single
().
Documents
.
Single
().
GetSemanticModelAsync
();
...
...
src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs
浏览文件 @
7177e45f
...
...
@@ -269,17 +269,12 @@ public override IEnumerable<SyntaxNode> GetOptionNodes(SyntaxNode parent)
}
public
override
IEnumerable
<
SyntaxNode
>
GetImportNodes
(
SyntaxNode
parent
)
{
switch
(
parent
.
Kind
())
=>
parent
.
Kind
()
switch
{
case
SyntaxKind
.
CompilationUnit
:
return
((
CompilationUnitSyntax
)
parent
).
Usings
;
case
SyntaxKind
.
NamespaceDeclaration
:
return
((
NamespaceDeclarationSyntax
)
parent
).
Usings
;
default
:
return
SpecializedCollections
.
EmptyEnumerable
<
SyntaxNode
>();
}
}
SyntaxKind
.
CompilationUnit
=>
((
CompilationUnitSyntax
)
parent
).
Usings
,
SyntaxKind
.
NamespaceDeclaration
=>
((
NamespaceDeclarationSyntax
)
parent
).
Usings
,
_
=>
SpecializedCollections
.
EmptyEnumerable
<
SyntaxNode
>(),
};
private
static
IEnumerable
<
SyntaxNode
>
GetAttributeNodes
(
SyntaxList
<
AttributeListSyntax
>
attributeDeclarationList
)
{
...
...
@@ -1507,21 +1502,14 @@ public override bool IsAccessorNode(SyntaxNode node)
}
public
override
MethodKind
GetAccessorKind
(
SyntaxNode
node
)
{
switch
(
node
.
Kind
())
=>
node
.
Kind
()
switch
{
case
SyntaxKind
.
GetAccessorDeclaration
:
return
MethodKind
.
PropertyGet
;
case
SyntaxKind
.
SetAccessorDeclaration
:
return
MethodKind
.
PropertySet
;
case
SyntaxKind
.
AddAccessorDeclaration
:
return
MethodKind
.
EventAdd
;
case
SyntaxKind
.
RemoveAccessorDeclaration
:
return
MethodKind
.
EventRemove
;
default
:
throw
Exceptions
.
ThrowEUnexpected
();
}
}
SyntaxKind
.
GetAccessorDeclaration
=>
MethodKind
.
PropertyGet
,
SyntaxKind
.
SetAccessorDeclaration
=>
MethodKind
.
PropertySet
,
SyntaxKind
.
AddAccessorDeclaration
=>
MethodKind
.
EventAdd
,
SyntaxKind
.
RemoveAccessorDeclaration
=>
MethodKind
.
EventRemove
,
_
=>
throw
Exceptions
.
ThrowEUnexpected
(),
};
private
static
SyntaxKind
GetAccessorSyntaxKind
(
MethodKind
methodKind
)
{
...
...
@@ -2919,23 +2907,15 @@ private Document DeleteMember(Document document, SyntaxNode node)
}
public
override
Document
Delete
(
Document
document
,
SyntaxNode
node
)
{
switch
(
node
.
Kind
())
{
case
SyntaxKind
.
VariableDeclarator
:
return
Delete
(
document
,
(
VariableDeclaratorSyntax
)
node
);
case
SyntaxKind
.
EnumMemberDeclaration
:
return
Delete
(
document
,
(
EnumMemberDeclarationSyntax
)
node
);
case
SyntaxKind
.
Attribute
:
return
Delete
(
document
,
(
AttributeSyntax
)
node
);
case
SyntaxKind
.
AttributeArgument
:
return
Delete
(
document
,
(
AttributeArgumentSyntax
)
node
);
case
SyntaxKind
.
Parameter
:
return
Delete
(
document
,
(
ParameterSyntax
)
node
);
default
:
return
DeleteMember
(
document
,
node
);
}
}
=>
node
.
Kind
()
switch
{
SyntaxKind
.
VariableDeclarator
=>
Delete
(
document
,
(
VariableDeclaratorSyntax
)
node
),
SyntaxKind
.
EnumMemberDeclaration
=>
Delete
(
document
,
(
EnumMemberDeclarationSyntax
)
node
),
SyntaxKind
.
Attribute
=>
Delete
(
document
,
(
AttributeSyntax
)
node
),
SyntaxKind
.
AttributeArgument
=>
Delete
(
document
,
(
AttributeArgumentSyntax
)
node
),
SyntaxKind
.
Parameter
=>
Delete
(
document
,
(
ParameterSyntax
)
node
),
_
=>
DeleteMember
(
document
,
node
),
};
public
override
string
GetMethodXml
(
SyntaxNode
node
,
SemanticModel
semanticModel
)
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
7177e45f
...
...
@@ -2923,19 +2923,13 @@ private static SyntaxNode AddBaseList(SyntaxNode declaration, BaseListSyntax bas
}
private
static
BaseListSyntax
GetBaseList
(
SyntaxNode
declaration
)
{
switch
(
declaration
.
Kind
())
=>
declaration
.
Kind
()
switch
{
case
SyntaxKind
.
ClassDeclaration
:
return
((
ClassDeclarationSyntax
)
declaration
).
BaseList
;
case
SyntaxKind
.
StructDeclaration
:
return
((
StructDeclarationSyntax
)
declaration
).
BaseList
;
case
SyntaxKind
.
InterfaceDeclaration
:
return
((
InterfaceDeclarationSyntax
)
declaration
).
BaseList
;
default
:
return
null
;
}
}
SyntaxKind
.
ClassDeclaration
=>
((
ClassDeclarationSyntax
)
declaration
).
BaseList
,
SyntaxKind
.
StructDeclaration
=>
((
StructDeclarationSyntax
)
declaration
).
BaseList
,
SyntaxKind
.
InterfaceDeclaration
=>
((
InterfaceDeclarationSyntax
)
declaration
).
BaseList
,
_
=>
null
,
};
private
static
SyntaxNode
WithBaseList
(
SyntaxNode
declaration
,
BaseListSyntax
baseList
)
=>
declaration
.
Kind
()
switch
...
...
src/Workspaces/CSharp/Portable/Formatting/FormattingHelpers.cs
浏览文件 @
7177e45f
...
...
@@ -287,29 +287,19 @@ public static bool IsCloseParenInStatement(this SyntaxToken token)
return
false
;
}
switch
(
statement
)
{
case
IfStatementSyntax
ifStatement
:
return
ifStatement
.
CloseParenToken
.
Equals
(
token
);
case
SwitchStatementSyntax
switchStatement
:
return
switchStatement
.
CloseParenToken
.
Equals
(
token
);
case
WhileStatementSyntax
whileStatement
:
return
whileStatement
.
CloseParenToken
.
Equals
(
token
);
case
DoStatementSyntax
doStatement
:
return
doStatement
.
CloseParenToken
.
Equals
(
token
);
case
ForStatementSyntax
forStatement
:
return
forStatement
.
CloseParenToken
.
Equals
(
token
);
case
CommonForEachStatementSyntax
foreachStatement
:
return
foreachStatement
.
CloseParenToken
.
Equals
(
token
);
case
LockStatementSyntax
lockStatement
:
return
lockStatement
.
CloseParenToken
.
Equals
(
token
);
case
UsingStatementSyntax
usingStatement
:
return
usingStatement
.
CloseParenToken
.
Equals
(
token
);
case
FixedStatementSyntax
fixedStatement
:
return
fixedStatement
.
CloseParenToken
.
Equals
(
token
);
}
return
false
;
return
statement
switch
{
IfStatementSyntax
ifStatement
=>
ifStatement
.
CloseParenToken
.
Equals
(
token
),
SwitchStatementSyntax
switchStatement
=>
switchStatement
.
CloseParenToken
.
Equals
(
token
),
WhileStatementSyntax
whileStatement
=>
whileStatement
.
CloseParenToken
.
Equals
(
token
),
DoStatementSyntax
doStatement
=>
doStatement
.
CloseParenToken
.
Equals
(
token
),
ForStatementSyntax
forStatement
=>
forStatement
.
CloseParenToken
.
Equals
(
token
),
CommonForEachStatementSyntax
foreachStatement
=>
foreachStatement
.
CloseParenToken
.
Equals
(
token
),
LockStatementSyntax
lockStatement
=>
lockStatement
.
CloseParenToken
.
Equals
(
token
),
UsingStatementSyntax
usingStatement
=>
usingStatement
.
CloseParenToken
.
Equals
(
token
),
FixedStatementSyntax
fixedStatement
=>
fixedStatement
.
CloseParenToken
.
Equals
(
token
),
_
=>
false
,
};
}
public
static
bool
IsDotInMemberAccessOrQualifiedName
(
this
SyntaxToken
token
)
...
...
src/Workspaces/CSharp/Portable/Formatting/Rules/SuppressFormattingRule.cs
浏览文件 @
7177e45f
...
...
@@ -330,18 +330,12 @@ private void AddInitializerSuppressOperations(List<SuppressOperation> list, Synt
}
private
InitializerExpressionSyntax
GetInitializerNode
(
SyntaxNode
node
)
{
switch
(
node
)
=>
node
switch
{
case
ObjectCreationExpressionSyntax
objectCreationNode
:
return
objectCreationNode
.
Initializer
;
case
ArrayCreationExpressionSyntax
arrayCreationNode
:
return
arrayCreationNode
.
Initializer
;
case
ImplicitArrayCreationExpressionSyntax
implicitArrayNode
:
return
implicitArrayNode
.
Initializer
;
}
return
null
;
}
ObjectCreationExpressionSyntax
objectCreationNode
=>
objectCreationNode
.
Initializer
,
ArrayCreationExpressionSyntax
arrayCreationNode
=>
arrayCreationNode
.
Initializer
,
ImplicitArrayCreationExpressionSyntax
implicitArrayNode
=>
implicitArrayNode
.
Initializer
,
_
=>
null
,
};
}
}
src/Workspaces/Core/Portable/Options/Option`1.cs
浏览文件 @
7177e45f
...
...
@@ -67,18 +67,13 @@ internal Option(string feature, OptionGroup group, string name, T defaultValue,
throw
new
ArgumentNullException
(
nameof
(
feature
));
}
if
(
group
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
group
));
}
if
(
string
.
IsNullOrWhiteSpace
(
name
))
{
throw
new
ArgumentException
(
nameof
(
name
));
}
this
.
Feature
=
feature
;
this
.
Group
=
group
;
this
.
Group
=
group
??
throw
new
ArgumentNullException
(
nameof
(
group
))
;
this
.
Name
=
name
;
this
.
DefaultValue
=
defaultValue
;
this
.
StorageLocations
=
storageLocations
.
ToImmutableArray
();
...
...
src/Workspaces/Core/Portable/Options/PerLanguageOption.cs
浏览文件 @
7177e45f
...
...
@@ -62,18 +62,13 @@ internal PerLanguageOption(string feature, OptionGroup group, string name, T def
throw
new
ArgumentNullException
(
nameof
(
feature
));
}
if
(
group
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
group
));
}
if
(
string
.
IsNullOrWhiteSpace
(
name
))
{
throw
new
ArgumentException
(
nameof
(
name
));
}
this
.
Feature
=
feature
;
this
.
Group
=
group
;
this
.
Group
=
group
??
throw
new
ArgumentNullException
(
nameof
(
group
))
;
this
.
Name
=
name
;
this
.
DefaultValue
=
defaultValue
;
this
.
StorageLocations
=
storageLocations
.
ToImmutableArray
();
...
...
src/Workspaces/Core/Portable/Shared/NormalizedTextSpanCollection.cs
浏览文件 @
7177e45f
...
...
@@ -348,7 +348,7 @@ public static NormalizedTextSpanCollection Difference(NormalizedTextSpanCollecti
return
true
;
}
if
(
object
.
ReferenceEquals
(
left
,
null
)
||
object
.
ReferenceEquals
(
right
,
null
)
)
if
(
left
is
null
||
right
is
null
)
{
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录