Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
63f23e38
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,发现更多精彩内容 >>
提交
63f23e38
编写于
4月 14, 2020
作者:
D
David Poeschl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Nullable enable the CSharpChangeSignatureServices
上级
e5f08146
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
78 addition
and
37 deletion
+78
-37
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
.../Portable/ChangeSignature/CSharpChangeSignatureService.cs
+77
-36
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
...ortable/ChangeSignature/AbstractChangeSignatureService.cs
+1
-1
未找到文件。
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
浏览文件 @
63f23e38
...
...
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#
nullable
enable
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
...
...
@@ -94,8 +96,8 @@ public CSharpChangeSignatureService()
public
override
async
Task
<(
ISymbol
symbol
,
int
selectedIndex
)>
GetInvocationSymbolAsync
(
Document
document
,
int
position
,
bool
restrictToDeclarations
,
CancellationToken
cancellationToken
)
{
var
tree
=
await
document
.
GetSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
tree
=
await
document
.
Get
Required
SyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
Get
Required
SyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
token
=
root
.
FindToken
(
position
!=
tree
.
Length
?
position
:
Math
.
Max
(
0
,
position
-
1
));
...
...
@@ -106,6 +108,11 @@ public CSharpChangeSignatureService()
position
=
token
.
Span
.
End
;
}
if
(
token
.
Parent
==
null
)
{
return
default
;
}
var
matchingNode
=
GetMatchingNode
(
token
.
Parent
,
restrictToDeclarations
);
if
(
matchingNode
==
null
)
{
...
...
@@ -125,7 +132,7 @@ public CSharpChangeSignatureService()
return
default
;
}
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbol
=
semanticModel
.
GetDeclaredSymbol
(
matchingNode
,
cancellationToken
);
if
(
symbol
!=
null
)
{
...
...
@@ -133,11 +140,11 @@ public CSharpChangeSignatureService()
return
(
symbol
,
selectedIndex
);
}
if
(
matchingNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
objectCreation
)
&&
if
(
matchingNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
?
objectCreation
)
&&
token
.
Parent
.
AncestorsAndSelf
().
Any
(
a
=>
a
==
objectCreation
.
Type
))
{
var
typeSymbol
=
semanticModel
.
GetSymbolInfo
(
objectCreation
.
Type
,
cancellationToken
).
Symbol
;
if
(
typeSymbol
!=
null
&&
typeSymbol
.
IsKind
(
SymbolKind
.
NamedType
)
&&
(
typeSymbol
as
IT
ypeSymbol
).
TypeKind
==
TypeKind
.
Delegate
)
if
(
typeSymbol
!=
null
&&
typeSymbol
.
IsKind
(
SymbolKind
.
NamedType
)
&&
(
(
ITypeSymbol
)
t
ypeSymbol
).
TypeKind
==
TypeKind
.
Delegate
)
{
return
(
typeSymbol
,
0
);
}
...
...
@@ -168,7 +175,7 @@ protected override int GetPositionBeforeParameterListClosingBrace(SyntaxNode mat
};
}
private
SyntaxNode
GetMatchingNode
(
SyntaxNode
node
,
bool
restrictToDeclarations
)
private
SyntaxNode
?
GetMatchingNode
(
SyntaxNode
node
,
bool
restrictToDeclarations
)
{
var
matchKinds
=
restrictToDeclarations
?
_declarationKinds
...
...
@@ -214,7 +221,7 @@ private bool InSymbolHeader(SyntaxNode matchingNode, int position)
return
true
;
}
public
override
SyntaxNode
FindNodeToUpdate
(
Document
document
,
SyntaxNode
node
)
public
override
SyntaxNode
?
FindNodeToUpdate
(
Document
document
,
SyntaxNode
node
)
{
if
(
_updatableNodeKinds
.
Contains
(
node
.
Kind
()))
{
...
...
@@ -237,18 +244,18 @@ public override SyntaxNode FindNodeToUpdate(Document document, SyntaxNode node)
return
node
.
AncestorsAndSelf
().
Any
(
n
=>
n
==
nodeContainingOriginal
)
?
matchingNode
:
null
;
}
private
SyntaxNode
GetNodeContainingTargetNode
(
SyntaxNode
matchingNode
)
private
SyntaxNode
?
GetNodeContainingTargetNode
(
SyntaxNode
matchingNode
)
{
switch
(
matchingNode
.
Kind
())
{
case
SyntaxKind
.
InvocationExpression
:
return
(
matchingNode
as
InvocationExpressionSyntax
).
Expression
;
return
(
(
InvocationExpressionSyntax
)
matchingNode
).
Expression
;
case
SyntaxKind
.
ElementAccessExpression
:
return
(
matchingNode
as
ElementAccessExpressionSyntax
).
ArgumentList
;
return
(
(
ElementAccessExpressionSyntax
)
matchingNode
).
ArgumentList
;
case
SyntaxKind
.
ObjectCreationExpression
:
return
(
matchingNode
as
ObjectCreationExpressionSyntax
).
Type
;
return
(
(
ObjectCreationExpressionSyntax
)
matchingNode
).
Type
;
case
SyntaxKind
.
ConstructorDeclaration
:
case
SyntaxKind
.
IndexerDeclaration
:
...
...
@@ -288,37 +295,37 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
}
// Update declarations parameter lists
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
MethodDeclaration
,
out
MethodDeclarationSyntax
method
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
MethodDeclaration
,
out
MethodDeclarationSyntax
?
method
))
{
var
updatedParameters
=
UpdateDeclaration
(
method
.
ParameterList
.
Parameters
,
signaturePermutation
,
CreateNewParameterSyntax
);
return
method
.
WithParameterList
(
method
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
LocalFunctionStatement
,
out
LocalFunctionStatementSyntax
localFunction
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
LocalFunctionStatement
,
out
LocalFunctionStatementSyntax
?
localFunction
))
{
var
updatedParameters
=
UpdateDeclaration
(
localFunction
.
ParameterList
.
Parameters
,
signaturePermutation
,
CreateNewParameterSyntax
);
return
localFunction
.
WithParameterList
(
localFunction
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ConstructorDeclaration
,
out
ConstructorDeclarationSyntax
constructor
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ConstructorDeclaration
,
out
ConstructorDeclarationSyntax
?
constructor
))
{
var
updatedParameters
=
UpdateDeclaration
(
constructor
.
ParameterList
.
Parameters
,
signaturePermutation
,
CreateNewParameterSyntax
);
return
constructor
.
WithParameterList
(
constructor
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
IndexerDeclaration
,
out
IndexerDeclarationSyntax
indexer
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
IndexerDeclaration
,
out
IndexerDeclarationSyntax
?
indexer
))
{
var
updatedParameters
=
UpdateDeclaration
(
indexer
.
ParameterList
.
Parameters
,
signaturePermutation
,
CreateNewParameterSyntax
);
return
indexer
.
WithParameterList
(
indexer
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
DelegateDeclaration
,
out
DelegateDeclarationSyntax
delegateDeclaration
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
DelegateDeclaration
,
out
DelegateDeclarationSyntax
?
delegateDeclaration
))
{
var
updatedParameters
=
UpdateDeclaration
(
delegateDeclaration
.
ParameterList
.
Parameters
,
signaturePermutation
,
CreateNewParameterSyntax
);
return
delegateDeclaration
.
WithParameterList
(
delegateDeclaration
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
AnonymousMethodExpression
,
out
AnonymousMethodExpressionSyntax
anonymousMethod
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
AnonymousMethodExpression
,
out
AnonymousMethodExpressionSyntax
?
anonymousMethod
))
{
// Delegates may omit parameters in C#
if
(
anonymousMethod
.
ParameterList
==
null
)
...
...
@@ -330,7 +337,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return
anonymousMethod
.
WithParameterList
(
anonymousMethod
.
ParameterList
.
WithParameters
(
updatedParameters
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
SimpleLambdaExpression
,
out
SimpleLambdaExpressionSyntax
lambda
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
SimpleLambdaExpression
,
out
SimpleLambdaExpressionSyntax
?
lambda
))
{
if
(
signaturePermutation
.
UpdatedConfiguration
.
ToListOfParameters
().
Any
())
{
...
...
@@ -352,7 +359,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
}
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ParenthesizedLambdaExpression
,
out
ParenthesizedLambdaExpressionSyntax
parenLambda
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ParenthesizedLambdaExpression
,
out
ParenthesizedLambdaExpressionSyntax
?
parenLambda
))
{
var
doNotSkipParameterType
=
parenLambda
.
ParameterList
.
Parameters
.
FirstOrDefault
()?.
Type
!=
null
;
...
...
@@ -364,9 +371,9 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
}
// Update reference site argument lists
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
InvocationExpression
,
out
InvocationExpressionSyntax
invocation
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
InvocationExpression
,
out
InvocationExpressionSyntax
?
invocation
))
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbolInfo
=
semanticModel
.
GetSymbolInfo
((
InvocationExpressionSyntax
)
originalNode
,
cancellationToken
);
return
invocation
.
WithArgumentList
(
...
...
@@ -378,11 +385,16 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
IsParamsArrayExpanded
(
semanticModel
,
invocation
,
symbolInfo
,
cancellationToken
)));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
objCreation
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
?
objCreation
))
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbolInfo
=
semanticModel
.
GetSymbolInfo
((
ObjectCreationExpressionSyntax
)
originalNode
,
cancellationToken
);
if
(
objCreation
.
ArgumentList
==
null
)
{
return
updatedNode
;
}
return
objCreation
.
WithArgumentList
(
UpdateArgumentList
(
declarationSymbol
,
...
...
@@ -392,10 +404,10 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
IsParamsArrayExpanded
(
semanticModel
,
objCreation
,
symbolInfo
,
cancellationToken
)));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
,
out
ConstructorInitializerSyntax
constructorInit
)
||
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
,
out
ConstructorInitializerSyntax
?
constructorInit
)
||
updatedNode
.
IsKind
(
SyntaxKind
.
BaseConstructorInitializer
,
out
constructorInit
))
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbolInfo
=
semanticModel
.
GetSymbolInfo
((
ConstructorInitializerSyntax
)
originalNode
,
cancellationToken
);
return
constructorInit
.
WithArgumentList
(
...
...
@@ -407,9 +419,9 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
IsParamsArrayExpanded
(
semanticModel
,
constructorInit
,
symbolInfo
,
cancellationToken
)));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ElementAccessExpression
,
out
ElementAccessExpressionSyntax
elementAccess
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ElementAccessExpression
,
out
ElementAccessExpressionSyntax
?
elementAccess
))
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbolInfo
=
semanticModel
.
GetSymbolInfo
((
ElementAccessExpressionSyntax
)
originalNode
,
cancellationToken
);
return
elementAccess
.
WithArgumentList
(
...
...
@@ -421,11 +433,16 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
IsParamsArrayExpanded
(
semanticModel
,
elementAccess
,
symbolInfo
,
cancellationToken
)));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
Attribute
,
out
AttributeSyntax
attribute
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
Attribute
,
out
AttributeSyntax
?
attribute
))
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
symbolInfo
=
semanticModel
.
GetSymbolInfo
((
AttributeSyntax
)
originalNode
,
cancellationToken
);
if
(
attribute
.
ArgumentList
==
null
)
{
return
updatedNode
;
}
return
attribute
.
WithArgumentList
(
UpdateAttributeArgumentList
(
declarationSymbol
,
...
...
@@ -436,7 +453,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
}
// Handle references in crefs
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
NameMemberCref
,
out
NameMemberCrefSyntax
nameMemberCref
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
NameMemberCref
,
out
NameMemberCrefSyntax
?
nameMemberCref
))
{
if
(
nameMemberCref
.
Parameters
==
null
||
!
nameMemberCref
.
Parameters
.
Parameters
.
Any
())
...
...
@@ -520,14 +537,26 @@ private bool IsParamsArrayExpanded(SemanticModel semanticModel, SyntaxNode node,
if
(
node
is
AttributeSyntax
attribute
)
{
if
(
attribute
.
ArgumentList
==
null
)
{
return
false
;
}
argumentCount
=
attribute
.
ArgumentList
.
Arguments
.
Count
;
lastArgumentIsNamed
=
attribute
.
ArgumentList
.
Arguments
.
LastOrDefault
()?.
NameColon
!=
null
||
attribute
.
ArgumentList
.
Arguments
.
LastOrDefault
()?.
NameEquals
!=
null
;
lastArgumentExpression
=
attribute
.
ArgumentList
.
Arguments
.
LastOrDefault
()?.
Expression
;
var
lastArgument
=
attribute
.
ArgumentList
.
Arguments
.
LastOrDefault
();
if
(
lastArgument
==
null
)
{
return
false
;
}
lastArgumentExpression
=
lastArgument
.
Expression
;
}
else
{
BaseArgumentListSyntax
argumentList
=
node
switch
BaseArgumentListSyntax
?
argumentList
=
node
switch
{
InvocationExpressionSyntax
invocation
=>
invocation
.
ArgumentList
,
ObjectCreationExpressionSyntax
objectCreation
=>
objectCreation
.
ArgumentList
,
...
...
@@ -536,9 +565,21 @@ private bool IsParamsArrayExpanded(SemanticModel semanticModel, SyntaxNode node,
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
node
.
Kind
())
};
if
(
argumentList
==
null
)
{
return
false
;
}
argumentCount
=
argumentList
.
Arguments
.
Count
;
lastArgumentIsNamed
=
argumentList
.
Arguments
.
LastOrDefault
()?.
NameColon
!=
null
;
lastArgumentExpression
=
argumentList
.
Arguments
.
LastOrDefault
()?.
Expression
;
var
lastArgument
=
argumentList
.
Arguments
.
LastOrDefault
();
if
(
lastArgument
==
null
)
{
return
false
;
}
lastArgumentExpression
=
lastArgument
.
Expression
;
}
return
IsParamsArrayExpandedHelper
(
symbolInfo
.
Symbol
,
argumentCount
,
lastArgumentIsNamed
,
semanticModel
,
lastArgumentExpression
,
cancellationToken
);
...
...
@@ -751,8 +792,8 @@ private ImmutableArray<SyntaxNode> VerifyAndPermuteParamNodes(IEnumerable<XmlEle
CancellationToken
cancellationToken
)
{
var
symbol
=
symbolAndProjectId
.
Symbol
;
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
Get
Required
SyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
Get
Required
SemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
nodes
=
root
.
DescendantNodes
().
ToImmutableArray
();
var
convertedMethodGroups
=
nodes
...
...
@@ -765,7 +806,7 @@ private ImmutableArray<SyntaxNode> VerifyAndPermuteParamNodes(IEnumerable<XmlEle
return
false
;
}
ISymbol
convertedType
=
semanticModel
.
GetTypeInfo
(
n
,
cancellationToken
).
ConvertedType
;
ISymbol
?
convertedType
=
semanticModel
.
GetTypeInfo
(
n
,
cancellationToken
).
ConvertedType
;
if
(
convertedType
!=
null
)
{
...
...
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
浏览文件 @
63f23e38
...
...
@@ -43,7 +43,7 @@ internal abstract class AbstractChangeSignatureService : ILanguageService
/// Given a SyntaxNode for which we want to reorder parameters/arguments, find the
/// SyntaxNode of a kind where we know how to reorder parameters/arguments.
/// </summary>
public
abstract
SyntaxNode
FindNodeToUpdate
(
Document
document
,
SyntaxNode
node
);
public
abstract
SyntaxNode
?
FindNodeToUpdate
(
Document
document
,
SyntaxNode
node
);
public
abstract
Task
<
ImmutableArray
<
SymbolAndProjectId
>>
DetermineCascadedSymbolsFromDelegateInvokeAsync
(
SymbolAndProjectId
<
IMethodSymbol
>
symbolAndProjectId
,
Document
document
,
CancellationToken
cancellationToken
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录