Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
8ae03859
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,发现更多精彩内容 >>
未验证
提交
8ae03859
编写于
3月 02, 2020
作者:
M
msftbot[bot]
提交者:
GitHub
3月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #42087 from CyrusNajmabadi/useHelperExtension2
Use helper extension to simplify code.
上级
a698120f
86609a95
变更
54
隐藏空白更改
内联
并排
Showing
54 changed file
with
224 addition
and
325 deletion
+224
-325
src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs
...harp/CompleteStatement/CompleteStatementCommandHandler.cs
+2
-2
src/EditorFeatures/CSharp/DocumentationComments/DocumentationCommentCommandHandler.cs
...cumentationComments/DocumentationCommentCommandHandler.cs
+1
-1
src/EditorFeatures/CSharp/Formatting/TypingFormattingRule.cs
src/EditorFeatures/CSharp/Formatting/TypingFormattingRule.cs
+2
-1
src/Features/CSharp/Portable/AddImport/CSharpAddImportFeatureService.cs
...Sharp/Portable/AddImport/CSharpAddImportFeatureService.cs
+4
-4
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
.../Portable/ChangeSignature/CSharpChangeSignatureService.cs
+8
-14
src/Features/CSharp/Portable/ChangeSignature/UnifiedArgumentSyntax.cs
.../CSharp/Portable/ChangeSignature/UnifiedArgumentSyntax.cs
+9
-8
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
...InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
+4
-5
src/Features/CSharp/Portable/CodeRefactorings/LambdaSimplifier/LambdaSimplifierCodeRefactoringProvider.cs
...mbdaSimplifier/LambdaSimplifierCodeRefactoringProvider.cs
+1
-2
src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs
...ders/DeclarationNameCompletionProvider.DeclarationInfo.cs
+1
-1
src/Features/CSharp/Portable/Completion/CompletionProviders/ObjectInitializerCompletionProvider.cs
...ompletionProviders/ObjectInitializerCompletionProvider.cs
+1
-6
src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs
...on/CompletionProviders/XmlDocCommentCompletionProvider.cs
+5
-6
src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs
...le/Completion/KeywordRecommenders/InKeywordRecommender.cs
+2
-2
src/Features/CSharp/Portable/Completion/KeywordRecommenders/NewKeywordRecommender.cs
...e/Completion/KeywordRecommenders/NewKeywordRecommender.cs
+1
-2
src/Features/CSharp/Portable/Completion/KeywordRecommenders/UsingKeywordRecommender.cs
...Completion/KeywordRecommenders/UsingKeywordRecommender.cs
+2
-3
src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
.../SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
+3
-2
src/Features/CSharp/Portable/ConvertLinq/ConvertForEachToLinqQuery/CSharpConvertForEachToLinqQueryProvider.cs
...achToLinqQuery/CSharpConvertForEachToLinqQueryProvider.cs
+1
-1
src/Features/CSharp/Portable/Debugging/DataTipInfoGetter.cs
src/Features/CSharp/Portable/Debugging/DataTipInfoGetter.cs
+2
-2
src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
...Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
+11
-16
src/Features/CSharp/Portable/EditAndContinue/StatementSyntaxComparer.cs
...Sharp/Portable/EditAndContinue/StatementSyntaxComparer.cs
+3
-2
src/Features/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
...atures/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
+7
-12
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
...dExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
+1
-1
src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
...CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
+10
-16
src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs
...ble/ImplementInterface/CSharpImplementInterfaceService.cs
+3
-3
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
...eDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
+1
-3
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService.Rewriter.cs
...roduceVariable/CSharpIntroduceVariableService.Rewriter.cs
+2
-2
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
...onalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
+2
-5
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs
...ess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs
+3
-2
src/Features/CSharp/Portable/QuickInfo/CSharpSyntacticQuickInfoProvider.cs
...rp/Portable/QuickInfo/CSharpSyntacticQuickInfoProvider.cs
+2
-2
src/Features/CSharp/Portable/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs
...aultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs
+1
-2
src/Features/CSharp/Portable/SignatureHelp/SignatureHelpUtilities.cs
...s/CSharp/Portable/SignatureHelp/SignatureHelpUtilities.cs
+3
-2
src/Features/CSharp/Portable/TypeStyle/UseExplicitTypeCodeFixProvider.cs
...harp/Portable/TypeStyle/UseExplicitTypeCodeFixProvider.cs
+2
-2
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs
...eDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs
+2
-2
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
...construction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
+1
-2
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs
...UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs
+2
-2
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
...LocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
+21
-27
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
...PatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
+4
-8
src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs
...s/CSharp/Portable/Classification/ClassificationHelpers.cs
+5
-8
src/Workspaces/CSharp/Portable/FindSymbols/CSharpDeclaredSymbolInfoFactoryService.cs
...ble/FindSymbols/CSharpDeclaredSymbolInfoFactoryService.cs
+4
-4
src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
...rp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
+9
-10
src/Workspaces/CSharp/Portable/Simplification/CSharpSimplificationService.Expander.cs
...le/Simplification/CSharpSimplificationService.Expander.cs
+1
-2
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/ExpressionSimplifier.cs
...rtable/Simplification/Simplifiers/ExpressionSimplifier.cs
+2
-4
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/ExpressionSyntaxExtensions.cs
.../Compiler/CSharp/Extensions/ExpressionSyntaxExtensions.cs
+6
-8
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/TypeSyntaxExtensions.cs
...nsions/Compiler/CSharp/Extensions/TypeSyntaxExtensions.cs
+2
-4
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SuppressFormattingRule.cs
...ompiler/CSharp/Formatting/Rules/SuppressFormattingRule.cs
+5
-5
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs
...Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs
+9
-16
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpTypeStyleHelper.State.cs
...CSharp/Utilities/TypeStyle/CSharpTypeStyleHelper.State.cs
+2
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseExplicitTypeHelper.cs
...CSharp/Utilities/TypeStyle/CSharpUseExplicitTypeHelper.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs
...CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs
+3
-5
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/CastExpressionSyntaxExtensions.cs
...space/CSharp/Extensions/CastExpressionSyntaxExtensions.cs
+4
-4
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTokenExtensions.cs
...e/CSharp/Extensions/ContextQuery/SyntaxTokenExtensions.cs
+1
-2
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
...ce/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
+27
-44
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ParenthesizedExpressionSyntaxExtensions.cs
...arp/Extensions/ParenthesizedExpressionSyntaxExtensions.cs
+5
-24
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/SemanticModelExtensions.cs
...ns/Workspace/CSharp/Extensions/SemanticModelExtensions.cs
+4
-4
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
...nguageServices/CSharpTypeInferenceService.TypeInferrer.cs
+4
-4
未找到文件。
src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs
浏览文件 @
8ae03859
...
...
@@ -193,12 +193,12 @@ private static void BeforeExecuteCommand(TypeCharCommandArgs args, CommandExecut
private
static
bool
IsInConditionOfDoStatement
(
SyntaxNode
currentNode
,
SnapshotPoint
caret
)
{
if
(!
currentNode
.
IsKind
(
SyntaxKind
.
DoStatement
))
if
(!
currentNode
.
IsKind
(
SyntaxKind
.
DoStatement
,
out
DoStatementSyntax
doStatement
))
{
return
false
;
}
var
condition
=
((
DoStatementSyntax
)
currentNode
)
.
Condition
;
var
condition
=
doStatement
.
Condition
;
return
(
caret
>=
condition
.
Span
.
Start
&&
caret
<=
condition
.
Span
.
End
);
}
...
...
src/EditorFeatures/CSharp/DocumentationComments/DocumentationCommentCommandHandler.cs
浏览文件 @
8ae03859
...
...
@@ -135,7 +135,7 @@ protected override List<string> GetDocumentationCommentStubLines(MemberDeclarati
{
var
returnType
=
member
.
GetMemberType
();
if
(
returnType
!=
null
&&
!(
returnType
.
IsKind
(
SyntaxKind
.
PredefinedType
)
&&
((
PredefinedTypeSyntax
)
returnType
)
.
Keyword
.
IsKindOrHasMatchingText
(
SyntaxKind
.
VoidKeyword
)))
!(
returnType
.
IsKind
(
SyntaxKind
.
PredefinedType
,
out
PredefinedTypeSyntax
predefinedType
)
&&
predefinedType
.
Keyword
.
IsKindOrHasMatchingText
(
SyntaxKind
.
VoidKeyword
)))
{
list
.
Add
(
"/// <returns></returns>"
);
}
...
...
src/EditorFeatures/CSharp/Formatting/TypingFormattingRule.cs
浏览文件 @
8ae03859
...
...
@@ -4,6 +4,7 @@
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Formatting
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.CSharp.Utilities
;
...
...
@@ -74,7 +75,7 @@ private bool TryAddSuppressionOnMissingCloseBraceCase(List<SuppressOperation> li
return
false
;
}
if
(
node
.
IsKind
(
SyntaxKind
.
Block
)
&&
((
BlockSyntax
)
node
)
.
Statements
.
Count
>=
1
)
if
(
node
.
IsKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
)
&&
block
.
Statements
.
Count
>=
1
)
{
// In the case of a block, see if the first statement is on the same line
// as the open curly. If so then we'll want to consider the end of the
...
...
src/Features/CSharp/Portable/AddImport/CSharpAddImportFeatureService.cs
浏览文件 @
8ae03859
...
...
@@ -54,13 +54,13 @@ protected override bool CanAddImport(SyntaxNode node, CancellationToken cancella
case
CS7036
:
case
CS0428
:
case
CS1061
:
if
(
node
.
IsKind
(
SyntaxKind
.
ConditionalAccessExpression
))
if
(
node
.
IsKind
(
SyntaxKind
.
ConditionalAccessExpression
,
out
ConditionalAccessExpressionSyntax
conditionalAccess
))
{
node
=
(
node
as
ConditionalAccessExpressionSyntax
)
.
WhenNotNull
;
node
=
conditionalAccess
.
WhenNotNull
;
}
else
if
(
node
.
IsKind
(
SyntaxKind
.
MemberBindingExpression
))
else
if
(
node
.
IsKind
(
SyntaxKind
.
MemberBindingExpression
,
out
MemberBindingExpressionSyntax
memberBinding1
))
{
node
=
(
node
as
MemberBindingExpressionSyntax
)
.
Name
;
node
=
memberBinding1
.
Name
;
}
else
if
(
node
.
Parent
.
IsKind
(
SyntaxKind
.
CollectionInitializerExpression
))
{
...
...
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
浏览文件 @
8ae03859
...
...
@@ -122,17 +122,13 @@ public CSharpChangeSignatureService()
return
(
symbol
,
selectedIndex
);
}
if
(
matchingNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
))
if
(
matchingNode
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
objectCreation
)
&&
token
.
Parent
.
AncestorsAndSelf
().
Any
(
a
=>
a
==
objectCreation
.
Type
))
{
var
objectCreation
=
matchingNode
as
ObjectCreationExpressionSyntax
;
if
(
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
ITypeSymbol
).
TypeKind
==
TypeKind
.
Delegate
)
{
var
typeSymbol
=
semanticModel
.
GetSymbolInfo
(
objectCreation
.
Type
,
cancellationToken
).
Symbol
;
if
(
typeSymbol
!=
null
&&
typeSymbol
.
IsKind
(
SymbolKind
.
NamedType
)
&&
(
typeSymbol
as
ITypeSymbol
).
TypeKind
==
TypeKind
.
Delegate
)
{
return
(
typeSymbol
,
0
);
}
return
(
typeSymbol
,
0
);
}
}
...
...
@@ -358,10 +354,9 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return
objCreation
.
WithArgumentList
(
objCreation
.
ArgumentList
.
WithArguments
(
newArguments
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
)
||
updatedNode
.
IsKind
(
SyntaxKind
.
BaseConstructorInitializer
))
if
(
updatedNode
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
,
out
ConstructorInitializerSyntax
constructorInit
)
||
updatedNode
.
IsKind
(
SyntaxKind
.
BaseConstructorInitializer
,
out
constructorInit
))
{
var
constructorInit
=
(
ConstructorInitializerSyntax
)
updatedNode
;
var
newArguments
=
PermuteArgumentList
(
document
,
declarationSymbol
,
constructorInit
.
ArgumentList
.
Arguments
,
signaturePermutation
);
return
constructorInit
.
WithArgumentList
(
constructorInit
.
ArgumentList
.
WithArguments
(
newArguments
).
WithAdditionalAnnotations
(
changeSignatureFormattingAnnotation
));
}
...
...
@@ -573,13 +568,12 @@ private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElem
for
(
var
i
=
0
;
i
<
structuredContent
.
Count
;
i
++)
{
var
content
=
structuredContent
[
i
];
if
(!
content
.
IsKind
(
SyntaxKind
.
XmlElement
))
if
(!
content
.
IsKind
(
SyntaxKind
.
XmlElement
,
out
XmlElementSyntax
xmlElement
))
{
updatedNodeList
.
Add
(
content
);
continue
;
}
var
xmlElement
=
content
as
XmlElementSyntax
;
if
(
xmlElement
.
StartTag
.
Name
.
ToString
()
!=
DocumentationCommentXmlNames
.
ParameterElementName
)
{
updatedNodeList
.
Add
(
content
);
...
...
src/Features/CSharp/Portable/ChangeSignature/UnifiedArgumentSyntax.cs
浏览文件 @
8ae03859
...
...
@@ -4,6 +4,7 @@
using
System.Diagnostics
;
using
Microsoft.CodeAnalysis.ChangeSignature
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
namespace
Microsoft.CodeAnalysis.CSharp.ChangeSignature
...
...
@@ -32,8 +33,8 @@ public SyntaxNode NameColon
{
get
{
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
)
?
((
ArgumentSyntax
)
_argument
)
.
NameColon
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
,
out
ArgumentSyntax
argument
)
?
argument
.
NameColon
:
((
AttributeArgumentSyntax
)
_argument
).
NameColon
;
}
}
...
...
@@ -42,8 +43,8 @@ public IUnifiedArgumentSyntax WithNameColon(SyntaxNode nameColonSyntax)
{
Debug
.
Assert
(
nameColonSyntax
is
NameColonSyntax
);
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
)
?
Create
(
((
ArgumentSyntax
)
_argument
)
.
WithNameColon
((
NameColonSyntax
)
nameColonSyntax
))
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
,
out
ArgumentSyntax
argument
)
?
Create
(
argument
.
WithNameColon
((
NameColonSyntax
)
nameColonSyntax
))
:
Create
(((
AttributeArgumentSyntax
)
_argument
).
WithNameColon
((
NameColonSyntax
)
nameColonSyntax
));
}
...
...
@@ -54,8 +55,8 @@ public string GetName()
public
IUnifiedArgumentSyntax
WithName
(
string
name
)
{
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
)
?
Create
(
((
ArgumentSyntax
)
_argument
)
.
WithNameColon
(
SyntaxFactory
.
NameColon
(
SyntaxFactory
.
IdentifierName
(
name
))))
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
,
out
ArgumentSyntax
argument
)
?
Create
(
argument
.
WithNameColon
(
SyntaxFactory
.
NameColon
(
SyntaxFactory
.
IdentifierName
(
name
))))
:
Create
(((
AttributeArgumentSyntax
)
_argument
).
WithNameColon
(
SyntaxFactory
.
NameColon
(
SyntaxFactory
.
IdentifierName
(
name
))));
}
...
...
@@ -68,8 +69,8 @@ public SyntaxNode Expression
{
get
{
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
)
?
((
ArgumentSyntax
)
_argument
)
.
Expression
return
_argument
.
IsKind
(
SyntaxKind
.
Argument
,
out
ArgumentSyntax
argument
)
?
argument
.
Expression
:
((
AttributeArgumentSyntax
)
_argument
).
Expression
;
}
}
...
...
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
浏览文件 @
8ae03859
...
...
@@ -53,7 +53,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
}
if
(!
variableDeclarator
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
variableDeclaration
)
||
!
variableDeclarat
or
.
Parent
.
IsParentKind
(
SyntaxKind
.
LocalDeclarationStatement
))
!
variableDeclarat
ion
.
IsParentKind
(
SyntaxKind
.
LocalDeclarationStatement
))
{
return
;
}
...
...
@@ -292,9 +292,9 @@ private static IEnumerable<IdentifierNameSyntax> FindReferenceAnnotatedNodes(Syn
var
annotatedNodesAndTokens
=
root
.
GetAnnotatedNodesAndTokens
(
ReferenceAnnotation
);
foreach
(
var
nodeOrToken
in
annotatedNodesAndTokens
)
{
if
(
nodeOrToken
.
IsNode
&&
nodeOrToken
.
AsNode
().
IsKind
(
SyntaxKind
.
IdentifierName
))
if
(
nodeOrToken
.
IsNode
&&
nodeOrToken
.
AsNode
().
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
identifierName
))
{
yield
return
(
IdentifierNameSyntax
)
nodeOrToken
.
AsNode
()
;
yield
return
identifierName
;
}
}
}
...
...
@@ -394,9 +394,8 @@ private SyntaxNode RemoveDeclaratorFromScope(VariableDeclaratorSyntax variableDe
private
ExpressionSyntax
SkipRedundantExteriorParentheses
(
ExpressionSyntax
expression
)
{
while
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
while
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenthesized
))
{
var
parenthesized
=
(
ParenthesizedExpressionSyntax
)
expression
;
if
(
parenthesized
.
Expression
==
null
||
parenthesized
.
Expression
.
IsMissing
)
{
...
...
src/Features/CSharp/Portable/CodeRefactorings/LambdaSimplifier/LambdaSimplifierCodeRefactoringProvider.cs
浏览文件 @
8ae03859
...
...
@@ -133,12 +133,11 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var
argument
=
invocation
.
ArgumentList
.
Arguments
[
i
];
if
(
argument
.
NameColon
!=
null
||
argument
.
RefOrOutKeyword
.
Kind
()
!=
SyntaxKind
.
None
||
!
argument
.
Expression
.
IsKind
(
SyntaxKind
.
IdentifierName
))
!
argument
.
Expression
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
identifierName
))
{
return
false
;
}
var
identifierName
=
(
IdentifierNameSyntax
)
argument
.
Expression
;
if
(
identifierName
.
Identifier
.
ValueText
!=
paramNames
[
i
].
ValueText
)
{
return
false
;
...
...
src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs
浏览文件 @
8ae03859
...
...
@@ -113,7 +113,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
private
static
bool
IsPossibleOutVariableDeclaration
(
SyntaxToken
token
,
SemanticModel
semanticModel
,
int
position
,
ITypeInferenceService
typeInferenceService
,
CancellationToken
cancellationToken
,
out
NameDeclarationInfo
result
)
{
if
(!
token
.
IsKind
(
SyntaxKind
.
IdentifierToken
)
||
!
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
IdentifierName
)
))
if
(!
token
.
IsKind
(
SyntaxKind
.
IdentifierToken
)
||
!
token
.
Parent
.
IsKind
(
SyntaxKind
.
IdentifierName
))
{
result
=
default
;
return
false
;
...
...
src/Features/CSharp/Portable/Completion/CompletionProviders/ObjectInitializerCompletionProvider.cs
浏览文件 @
8ae03859
...
...
@@ -118,13 +118,8 @@ internal override bool IsInsertionTrigger(SourceText text, int characterPosition
}
// new Goo { bar = $$
if
(
token
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
))
if
(
token
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
ObjectCreationExpression
,
out
ObjectCreationExpressionSyntax
objectCreation
))
{
if
(!(
token
.
Parent
.
Parent
is
ObjectCreationExpressionSyntax
objectCreation
))
{
return
null
;
}
var
type
=
semanticModel
.
GetSymbolInfo
(
objectCreation
.
Type
,
cancellationToken
).
Symbol
as
ITypeSymbol
;
if
(
type
is
ITypeParameterSymbol
typeParameterSymbol
)
{
...
...
src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs
浏览文件 @
8ae03859
...
...
@@ -194,15 +194,14 @@ private bool IsAttributeNameContext(SyntaxToken token, int position, out string
// <elem attr$$
(
elementName
,
attributes
)
=
GetElementNameAndAttributes
(
token
.
Parent
.
Parent
);
}
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlCrefAttribute
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlNameAttribute
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlTextAttribute
))
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlCrefAttribute
,
out
XmlAttributeSyntax
attributeSyntax
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlNameAttribute
,
out
attributeSyntax
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlTextAttribute
,
out
attributeSyntax
))
{
// In the following, 'attr1' may be a regular text attribute, or one of the special 'cref' or 'name' attributes
// <elem attr1="" $$
// <elem attr1="" $$attr2
// <elem attr1="" attr2$$
var
attributeSyntax
=
(
XmlAttributeSyntax
)
token
.
Parent
;
if
(
token
==
attributeSyntax
.
EndQuoteToken
)
{
...
...
@@ -263,12 +262,12 @@ private bool IsAttributeValueContext(SyntaxToken token, out string tagName, out
// Handle the other general text attributes: foo="bar$$
attributeSyntax
=
xmlText
;
}
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlNameAttribute
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlTextAttribute
))
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlNameAttribute
,
out
attributeSyntax
)
||
token
.
Parent
.
IsKind
(
SyntaxKind
.
XmlTextAttribute
,
out
attributeSyntax
))
{
// When there's no attribute value yet, the parent attribute is returned:
// name="$$
// foo="$$
attributeSyntax
=
(
XmlAttributeSyntax
)
token
.
Parent
;
if
(
token
!=
attributeSyntax
.
StartQuoteToken
)
{
attributeSyntax
=
null
;
...
...
src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs
浏览文件 @
8ae03859
...
...
@@ -130,8 +130,8 @@ private bool IsValidContextInJoinClause(CSharpSyntaxContext context, Cancellatio
// case:
// join x |
if
(
joinClause
.
Type
!=
null
&&
joinClause
.
Type
.
IsKind
(
SyntaxKind
.
IdentifierName
)
&&
token
==
((
IdentifierNameSyntax
)
joinClause
.
Type
)
.
Identifier
&&
joinClause
.
Type
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
joinIdentifier
)
&&
token
==
joinIdentifier
.
Identifier
&&
!
joinClause
.
Type
.
IsPotentialTypeName
(
context
.
SemanticModel
,
cancellationToken
))
{
return
true
;
...
...
src/Features/CSharp/Portable/Completion/KeywordRecommenders/NewKeywordRecommender.cs
浏览文件 @
8ae03859
...
...
@@ -101,9 +101,8 @@ private static bool IsNewConstraintContext(CSharpSyntaxContext context)
var
token
=
context
.
TargetToken
;
if
(
token
.
Kind
()
==
SyntaxKind
.
CommaToken
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameterConstraintClause
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameterConstraintClause
,
out
TypeParameterConstraintClauseSyntax
constraintClause
))
{
var
constraintClause
=
token
.
Parent
as
TypeParameterConstraintClauseSyntax
;
if
(!
constraintClause
.
Constraints
.
OfType
<
ClassOrStructConstraintSyntax
>()
.
Any
(
c
=>
c
.
ClassOrStructKeyword
.
Kind
()
==
SyntaxKind
.
StructKeyword
))
...
...
src/Features/CSharp/Portable/Completion/KeywordRecommenders/UsingKeywordRecommender.cs
浏览文件 @
8ae03859
...
...
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using
System.Threading
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
...
...
@@ -106,10 +107,8 @@ private static bool IsUsingDirectiveContext(CSharpSyntaxContext context, Cancell
}
if
(
token
.
Kind
()
==
SyntaxKind
.
OpenBraceToken
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
NamespaceDeclaration
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
NamespaceDeclaration
,
out
NamespaceDeclarationSyntax
ns
))
{
var
ns
=
(
NamespaceDeclarationSyntax
)
token
.
Parent
;
// a child using can't come before externs
var
nextToken
=
originalToken
.
GetNextToken
(
includeSkipped
:
true
);
if
(
nextToken
.
Kind
()
==
SyntaxKind
.
ExternKeyword
)
...
...
src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs
浏览文件 @
8ae03859
...
...
@@ -123,8 +123,9 @@ private bool IsLambdaExpression(SemanticModel semanticModel, int position, Synta
// A lambda that is being typed may be parsed as a tuple without names
// For example, "(a, b" could be the start of either a tuple or lambda
// But "(a: b, c" cannot be a lambda
if
(
token
.
SyntaxTree
.
IsPossibleTupleContext
(
token
,
position
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
TupleExpression
)
&&
!((
TupleExpressionSyntax
)
token
.
Parent
).
HasNames
())
if
(
token
.
SyntaxTree
.
IsPossibleTupleContext
(
token
,
position
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
TupleExpression
,
out
TupleExpressionSyntax
tupleExpression
)
&&
!
tupleExpression
.
HasNames
())
{
position
=
token
.
Parent
.
SpanStart
;
}
...
...
src/Features/CSharp/Portable/ConvertLinq/ConvertForEachToLinqQuery/CSharpConvertForEachToLinqQueryProvider.cs
浏览文件 @
8ae03859
...
...
@@ -288,7 +288,7 @@ bool TryProcessLocalDeclarationStatement(LocalDeclarationStatementSyntax localDe
statement
.
SpanStart
,
cancellationToken
),
memberDeclarationSymbol
)).
Count
();
if
(
forEachInfo
.
ForEachStatement
.
IsParentKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
)
&&
forEachInfo
.
ForEachStatement
.
Parent
.
Parent
==
memberDeclarationSyntax
)
block
.
Parent
==
memberDeclarationSyntax
)
{
// Check that
// a. There are either just a single 'yield return' or 'yield return' with 'yield break' just after.
...
...
src/Features/CSharp/Portable/Debugging/DataTipInfoGetter.cs
浏览文件 @
8ae03859
...
...
@@ -77,9 +77,9 @@ internal static async Task<DebugDataTipInfo> GetInfoAsync(Document document, int
// NOTE(cyrusn): This behavior is to mimic what we did in Dev10, I'm not sure if it's
// necessary or not.
if
(
expression
.
IsKind
(
SyntaxKind
.
InvocationExpression
))
if
(
expression
.
IsKind
(
SyntaxKind
.
InvocationExpression
,
out
InvocationExpressionSyntax
invocation
))
{
expression
=
((
InvocationExpressionSyntax
)
expression
)
.
Expression
;
expression
=
invocation
.
Expression
;
}
string
textOpt
=
null
;
...
...
src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -123,9 +123,9 @@ private enum ForEachPart
/// </returns>
internal
override
SyntaxNode
?
TryGetDeclarationBody
(
SyntaxNode
node
,
bool
isMember
)
{
if
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclarator
))
if
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclarator
,
out
VariableDeclaratorSyntax
?
variableDeclarator
))
{
return
((
VariableDeclaratorSyntax
)
node
)
.
Initializer
?.
Value
;
return
variableDeclarator
.
Initializer
?.
Value
;
}
return
SyntaxUtilities
.
TryGetMethodDeclarationBody
(
node
);
...
...
@@ -447,9 +447,8 @@ internal override SyntaxNode FindPartner(SyntaxNode leftRoot, SyntaxNode rightRo
}
SyntaxNode
?
rightEqualsClause
;
if
(
leftEqualsClause
.
Parent
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
))
if
(
leftEqualsClause
.
Parent
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
,
out
PropertyDeclarationSyntax
?
leftDeclaration
))
{
var
leftDeclaration
=
(
PropertyDeclarationSyntax
)
leftEqualsClause
.
Parent
;
var
leftSymbol
=
leftModel
.
GetDeclaredSymbol
(
leftDeclaration
,
cancellationToken
);
RoslynDebug
.
Assert
(
leftSymbol
!=
null
);
...
...
@@ -780,10 +779,10 @@ protected override bool AreEquivalentActiveStatements(SyntaxNode oldStatement, S
// closing brace of a using statement or a block that contains using local declarations:
if
(
statementPart
==
2
)
{
if
(
oldStatement
.
Parent
.
IsKind
(
SyntaxKind
.
UsingStatement
))
if
(
oldStatement
.
Parent
.
IsKind
(
SyntaxKind
.
UsingStatement
,
out
UsingStatementSyntax
?
oldUsing
))
{
return
newStatement
.
Parent
.
IsKind
(
SyntaxKind
.
UsingStatement
)
&&
AreEquivalentActiveStatements
(
(
UsingStatementSyntax
)
oldStatement
.
Parent
,
(
UsingStatementSyntax
)
newStatement
.
Parent
);
return
newStatement
.
Parent
.
IsKind
(
SyntaxKind
.
UsingStatement
,
out
UsingStatementSyntax
?
newUsing
)
&&
AreEquivalentActiveStatements
(
oldUsing
,
newUsing
);
}
return
HasEquivalentUsingDeclarations
((
BlockSyntax
)
oldStatement
,
(
BlockSyntax
)
newStatement
);
...
...
@@ -928,10 +927,8 @@ internal override bool IsInterfaceDeclaration(SyntaxNode node)
}
internal
override
bool
HasBackingField
(
SyntaxNode
propertyOrIndexerDeclaration
)
{
return
propertyOrIndexerDeclaration
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
)
&&
SyntaxUtilities
.
HasBackingField
((
PropertyDeclarationSyntax
)
propertyOrIndexerDeclaration
);
}
=>
propertyOrIndexerDeclaration
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
,
out
PropertyDeclarationSyntax
?
propertyDecl
)
&&
SyntaxUtilities
.
HasBackingField
(
propertyDecl
);
internal
override
bool
IsDeclarationWithInitializer
(
SyntaxNode
declaration
)
{
...
...
@@ -3370,11 +3367,9 @@ private static bool AreSwitchSectionsEquivalent(SwitchSectionSyntax oldSection,
private
static
bool
AreLabelsEquivalent
(
SwitchLabelSyntax
oldLabel
,
SwitchLabelSyntax
newLabel
)
{
if
(
oldLabel
.
IsKind
(
SyntaxKind
.
CasePatternSwitchLabel
)
&&
newLabel
.
IsKind
(
SyntaxKind
.
CasePatternSwitchLabel
))
if
(
oldLabel
.
IsKind
(
SyntaxKind
.
CasePatternSwitchLabel
,
out
CasePatternSwitchLabelSyntax
?
oldCasePatternLabel
)
&&
newLabel
.
IsKind
(
SyntaxKind
.
CasePatternSwitchLabel
,
out
CasePatternSwitchLabelSyntax
?
newCasePatternLabel
))
{
var
oldCasePatternLabel
=
(
CasePatternSwitchLabelSyntax
)
oldLabel
;
var
newCasePatternLabel
=
(
CasePatternSwitchLabelSyntax
)
newLabel
;
// ignore the actual when expressions:
return
SyntaxFactory
.
AreEquivalent
(
oldCasePatternLabel
.
Pattern
,
newCasePatternLabel
.
Pattern
)
&&
(
oldCasePatternLabel
.
WhenClause
!=
null
)
==
(
newCasePatternLabel
.
WhenClause
!=
null
);
...
...
@@ -3467,7 +3462,7 @@ private static bool AreLabelsEquivalent(SwitchLabelSyntax oldLabel, SwitchLabelS
ReportUnmatchedStatements
<
UsingStatementSyntax
>(
diagnostics
,
match
,
n
=>
n
.
IsKind
(
SyntaxKind
.
UsingStatement
)
&&
((
UsingStatementSyntax
)
n
)
.
Declaration
is
null
,
n
=>
n
.
IsKind
(
SyntaxKind
.
UsingStatement
,
out
UsingStatementSyntax
?
usingStatement
)
&&
usingStatement
.
Declaration
is
null
,
oldActiveStatement
,
newActiveStatement
,
areEquivalent
:
AreEquivalentActiveStatements
,
...
...
src/Features/CSharp/Portable/EditAndContinue/StatementSyntaxComparer.cs
浏览文件 @
8ae03859
...
...
@@ -7,6 +7,7 @@
using
System.Diagnostics
;
using
System.Diagnostics.CodeAnalysis
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Roslyn.Utilities
;
...
...
@@ -1037,9 +1038,9 @@ private static void GetLocalNames(BlockSyntax block, ref List<SyntaxToken>? resu
{
foreach
(
var
child
in
block
.
ChildNodes
())
{
if
(
child
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
))
if
(
child
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
LocalDeclarationStatementSyntax
?
localDecl
))
{
GetLocalNames
(
((
LocalDeclarationStatementSyntax
)
child
)
.
Declaration
,
ref
result
);
GetLocalNames
(
localDecl
.
Declaration
,
ref
result
);
}
}
}
...
...
src/Features/CSharp/Portable/EditAndContinue/SyntaxUtilities.cs
浏览文件 @
8ae03859
...
...
@@ -216,27 +216,22 @@ public static SyntaxNode TryGetEffectiveGetterBody(ArrowExpressionClauseSyntax p
public
static
SyntaxTokenList
?
TryGetFieldOrPropertyModifiers
(
SyntaxNode
node
)
{
if
(
node
.
IsKind
(
SyntaxKind
.
FieldDeclaration
))
{
return
((
FieldDeclarationSyntax
)
node
).
Modifiers
;
}
if
(
node
.
IsKind
(
SyntaxKind
.
FieldDeclaration
,
out
FieldDeclarationSyntax
fieldDecl
))
return
fieldDecl
.
Modifiers
;
if
(
node
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
))
{
return
((
PropertyDeclarationSyntax
)
node
).
Modifiers
;
}
if
(
node
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
,
out
PropertyDeclarationSyntax
propertyDecl
))
return
propertyDecl
.
Modifiers
;
return
null
;
}
public
static
bool
IsParameterlessConstructor
(
SyntaxNode
declaration
)
{
if
(!
declaration
.
IsKind
(
SyntaxKind
.
ConstructorDeclaration
))
if
(!
declaration
.
IsKind
(
SyntaxKind
.
ConstructorDeclaration
,
out
ConstructorDeclarationSyntax
ctor
))
{
return
false
;
}
var
ctor
=
(
ConstructorDeclarationSyntax
)
declaration
;
return
ctor
.
ParameterList
.
Parameters
.
Count
==
0
;
}
...
...
@@ -305,8 +300,8 @@ public static bool IsSuspensionPoint(SyntaxNode node)
// each declarator in the declaration translates to a suspension point: await DisposeAsync
if
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclarator
)
&&
node
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
)
&&
((
LocalDeclarationStatementSyntax
)
node
.
Parent
.
Parent
)
.
AwaitKeyword
.
IsKind
(
SyntaxKind
.
AwaitKeyword
))
node
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
LocalDeclarationStatementSyntax
localDecl
)
&&
localDecl
.
AwaitKeyword
.
IsKind
(
SyntaxKind
.
AwaitKeyword
))
{
return
true
;
}
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
浏览文件 @
8ae03859
...
...
@@ -200,7 +200,7 @@ protected override SyntaxNode GetLastStatementOrInitializerSelectedAtCallSite()
{
var
enclosingStatement
=
GetFirstStatementOrInitializerSelectedAtCallSite
();
var
callSignature
=
CreateCallSignature
().
WithAdditionalAnnotations
(
callSiteAnnotation
);
var
invocation
=
callSignature
.
IsKind
(
SyntaxKind
.
AwaitExpression
)
?
((
AwaitExpressionSyntax
)
callSignature
)
.
Expression
:
callSignature
;
var
invocation
=
callSignature
.
IsKind
(
SyntaxKind
.
AwaitExpression
,
out
AwaitExpressionSyntax
awaitExpr
)
?
awaitExpr
.
Expression
:
callSignature
;
var
sourceNode
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
Contract
.
ThrowIfTrue
(
...
...
src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
浏览文件 @
8ae03859
...
...
@@ -94,7 +94,7 @@ protected override bool IsInInterfaceList(ExpressionSyntax expression)
{
if
(
expression
is
TypeSyntax
&&
expression
.
Parent
is
BaseTypeSyntax
baseType
&&
expression
.
Parent
.
IsParentKind
(
SyntaxKind
.
BaseList
,
out
BaseListSyntax
baseList
)
&&
baseType
.
IsParentKind
(
SyntaxKind
.
BaseList
,
out
BaseListSyntax
baseList
)
&&
baseType
.
Type
==
expression
)
{
// If it's after the first item, then it's definitely an interface.
...
...
@@ -112,7 +112,7 @@ protected override bool IsInInterfaceList(ExpressionSyntax expression)
if
(
expression
is
TypeSyntax
&&
expression
.
IsParentKind
(
SyntaxKind
.
TypeConstraint
,
out
TypeConstraintSyntax
typeConstraint
)
&&
expression
.
Pare
nt
.
IsParentKind
(
SyntaxKind
.
TypeParameterConstraintClause
,
out
TypeParameterConstraintClauseSyntax
constraintClause
))
typeConstrai
nt
.
IsParentKind
(
SyntaxKind
.
TypeParameterConstraintClause
,
out
TypeParameterConstraintClauseSyntax
constraintClause
))
{
var
index
=
constraintClause
.
Constraints
.
IndexOf
(
typeConstraint
);
...
...
@@ -429,27 +429,21 @@ protected override bool TryGetNameParts(ExpressionSyntax expression, out IList<s
if
(
generateTypeServiceStateOptions
.
IsDelegateAllowed
)
{
// MyD1 z1 = goo;
if
(
nameOrMemberAccessExpression
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
))
if
(
nameOrMemberAccessExpression
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
variableDeclaration
)
&&
variableDeclaration
.
Variables
.
Count
!=
0
)
{
var
variableDeclaration
=
(
VariableDeclarationSyntax
)
nameOrMemberAccessExpression
.
Parent
;
if
(
variableDeclaration
.
Variables
.
Count
!=
0
)
var
firstVarDeclWithInitializer
=
variableDeclaration
.
Variables
.
FirstOrDefault
(
var
=>
var
.
Initializer
!=
null
&&
var
.
Initializer
.
Value
!=
null
)
;
if
(
firstVarDeclWithInitializer
!=
null
&&
firstVarDeclWithInitializer
.
Initializer
!=
null
&&
firstVarDeclWithInitializer
.
Initializer
.
Value
!=
null
)
{
var
firstVarDeclWithInitializer
=
variableDeclaration
.
Variables
.
FirstOrDefault
(
var
=>
var
.
Initializer
!=
null
&&
var
.
Initializer
.
Value
!=
null
);
if
(
firstVarDeclWithInitializer
!=
null
&&
firstVarDeclWithInitializer
.
Initializer
!=
null
&&
firstVarDeclWithInitializer
.
Initializer
.
Value
!=
null
)
{
generateTypeServiceStateOptions
.
DelegateCreationMethodSymbol
=
GetMethodSymbolIfPresent
(
semanticModel
,
firstVarDeclWithInitializer
.
Initializer
.
Value
,
cancellationToken
);
}
generateTypeServiceStateOptions
.
DelegateCreationMethodSymbol
=
GetMethodSymbolIfPresent
(
semanticModel
,
firstVarDeclWithInitializer
.
Initializer
.
Value
,
cancellationToken
);
}
}
// var w1 = (MyD1)goo;
if
(
nameOrMemberAccessExpression
.
Parent
.
IsKind
(
SyntaxKind
.
CastExpression
))
if
(
nameOrMemberAccessExpression
.
Parent
.
IsKind
(
SyntaxKind
.
CastExpression
,
out
CastExpressionSyntax
castExpression
)
&&
castExpression
.
Expression
!=
null
)
{
var
castExpression
=
(
CastExpressionSyntax
)
nameOrMemberAccessExpression
.
Parent
;
if
(
castExpression
.
Expression
!=
null
)
{
generateTypeServiceStateOptions
.
DelegateCreationMethodSymbol
=
GetMethodSymbolIfPresent
(
semanticModel
,
castExpression
.
Expression
,
cancellationToken
);
}
generateTypeServiceStateOptions
.
DelegateCreationMethodSymbol
=
GetMethodSymbolIfPresent
(
semanticModel
,
castExpression
.
Expression
,
cancellationToken
);
}
}
...
...
src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs
浏览文件 @
8ae03859
...
...
@@ -33,7 +33,7 @@ public CSharpImplementInterfaceService()
if
(!
cancellationToken
.
IsCancellationRequested
)
{
if
(
node
is
TypeSyntax
interfaceNode
&&
interfaceNode
.
Parent
is
BaseTypeSyntax
baseType
&&
interfaceNode
.
Parent
.
IsParentKind
(
SyntaxKind
.
BaseList
)
&&
baseType
.
IsParentKind
(
SyntaxKind
.
BaseList
)
&&
baseType
.
Type
==
interfaceNode
)
{
if
(
interfaceNode
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
ClassDeclaration
)
||
...
...
@@ -78,9 +78,9 @@ protected override bool CanImplementDisposePattern(INamedTypeSymbol symbol, Synt
// The dispose pattern is only applicable if the implementing type is a class that does not already declare any conflicting
// members named 'disposedValue' or 'Dispose' (because we will be generating a 'disposedValue' field and a couple of methods
// named 'Dispose' as part of implementing the dispose pattern).
return
(
classDecl
!=
null
)
&&
return
classDecl
!=
null
&&
classDecl
.
IsKind
(
SyntaxKind
.
ClassDeclaration
)
&&
(
symbol
!=
null
)
&&
symbol
!=
null
&&
!
symbol
.
GetMembers
().
Any
(
m
=>
(
m
.
MetadataName
==
"Dispose"
)
||
(
m
.
MetadataName
==
"disposedValue"
));
}
...
...
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -84,7 +84,7 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
}
var
argumentExpression
=
argumentNode
.
Expression
;
if
(
argumentExpression
.
Kind
()
!=
SyntaxKind
.
IdentifierName
)
if
(
!
argumentExpression
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
identifierName
)
)
{
// has to be exactly the form "out i". i.e. "out this.i" or "out v[i]" are legal
// cases for out-arguments, but could not be converted to an out-variable-declaration.
...
...
@@ -107,8 +107,6 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
return
;
}
var
identifierName
=
(
IdentifierNameSyntax
)
argumentExpression
;
// Don't offer to inline variables named "_". It can cause is to create a discard symbol
// which would cause a break.
if
(
identifierName
.
Identifier
.
ValueText
==
"_"
)
...
...
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService.Rewriter.cs
浏览文件 @
8ae03859
...
...
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Simplification
;
...
...
@@ -40,9 +41,8 @@ public override SyntaxNode VisitParenthesizedExpression(ParenthesizedExpressionS
{
var
newNode
=
base
.
VisitParenthesizedExpression
(
node
);
if
(
node
!=
newNode
&&
newNode
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
newNode
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenthesizedExpression
))
{
var
parenthesizedExpression
=
(
ParenthesizedExpressionSyntax
)
newNode
;
var
innerExpression
=
parenthesizedExpression
.
OpenParenToken
.
GetNextToken
().
Parent
;
if
(
innerExpression
.
HasAnnotation
(
_replacementAnnotation
))
{
...
...
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -82,13 +82,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
innerStatement
=
block
.
Statements
[
0
];
}
if
(!
innerStatement
.
IsKind
(
SyntaxKind
.
ExpressionStatement
))
if
(!
innerStatement
.
IsKind
(
SyntaxKind
.
ExpressionStatement
,
out
ExpressionStatementSyntax
expressionStatement
))
{
return
;
}
var
expressionStatement
=
(
ExpressionStatementSyntax
)
innerStatement
;
// Check that it's of the form: "if (a != null) { a(); }
if
(!(
expressionStatement
.
Expression
is
InvocationExpressionSyntax
invocationExpression
))
{
...
...
@@ -239,12 +237,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
}
var
previousStatement
=
parentBlock
.
Statements
[
ifIndex
-
1
];
if
(!
previousStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
))
if
(!
previousStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
LocalDeclarationStatementSyntax
localDeclarationStatement
))
{
return
false
;
}
var
localDeclarationStatement
=
(
LocalDeclarationStatementSyntax
)
previousStatement
;
var
variableDeclaration
=
localDeclarationStatement
.
Declaration
;
if
(
variableDeclaration
.
Variables
.
Count
!=
1
)
...
...
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs
浏览文件 @
8ae03859
...
...
@@ -99,9 +99,10 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
SyntaxFactory
.
MemberBindingExpression
(
SyntaxFactory
.
IdentifierName
(
nameof
(
Action
.
Invoke
))),
invocationExpression
.
ArgumentList
)));
newStatement
=
newStatement
.
WithPrependedLeadingTrivia
(
ifStatement
.
GetLeadingTrivia
());
if
(
ifStatement
.
Parent
.
IsKind
(
SyntaxKind
.
ElseClause
)
&&
ifStatement
.
Statement
.
IsKind
(
SyntaxKind
.
Block
))
if
(
ifStatement
.
Parent
.
IsKind
(
SyntaxKind
.
ElseClause
)
&&
ifStatement
.
Statement
.
IsKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
))
{
newStatement
=
((
BlockSyntax
)
ifStatement
.
Statement
)
.
WithStatements
(
SyntaxFactory
.
SingletonList
(
newStatement
));
newStatement
=
block
.
WithStatements
(
SyntaxFactory
.
SingletonList
(
newStatement
));
}
newStatement
=
newStatement
.
WithAdditionalAnnotations
(
Formatter
.
Annotation
);
...
...
src/Features/CSharp/Portable/QuickInfo/CSharpSyntacticQuickInfoProvider.cs
浏览文件 @
8ae03859
...
...
@@ -38,8 +38,8 @@ public CSharpSyntacticQuickInfoProvider()
}
// Don't show for interpolations
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
Interpolation
)
&&
((
InterpolationSyntax
)
token
.
Parent
)
.
CloseBraceToken
==
token
)
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
Interpolation
,
out
InterpolationSyntax
?
interpolation
)
&&
interpolation
.
CloseBraceToken
==
token
)
{
return
null
;
}
...
...
src/Features/CSharp/Portable/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs
浏览文件 @
8ae03859
...
...
@@ -45,9 +45,8 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
if
(
token
.
Span
==
context
.
Span
&&
token
.
IsKind
(
SyntaxKind
.
DefaultKeyword
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
DefaultLiteralExpression
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
DefaultLiteralExpression
,
out
LiteralExpressionSyntax
defaultLiteral
))
{
var
defaultLiteral
=
(
LiteralExpressionSyntax
)
token
.
Parent
;
var
semanticModel
=
await
context
.
Document
.
GetSemanticModelAsync
(
context
.
CancellationToken
).
ConfigureAwait
(
false
);
var
(
newExpression
,
displayText
)
=
GetReplacementExpressionAndText
(
...
...
src/Features/CSharp/Portable/SignatureHelp/SignatureHelpUtilities.cs
浏览文件 @
8ae03859
...
...
@@ -108,9 +108,10 @@ internal static TextSpan GetSignatureHelpSpan(AttributeArgumentListSyntax argume
{
// Don't dismiss if the user types ( to start a parenthesized expression or tuple
// Note that the tuple initially parses as a parenthesized expression
if
(
token
.
IsKind
(
SyntaxKind
.
OpenParenToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
if
(
token
.
IsKind
(
SyntaxKind
.
OpenParenToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenExpr
))
{
var
parenthesizedExpr
=
((
ParenthesizedExpressionSyntax
)
token
.
Parent
)
.
WalkUpParentheses
();
var
parenthesizedExpr
=
parenExpr
.
WalkUpParentheses
();
if
(
parenthesizedExpr
.
Parent
is
ArgumentSyntax
)
{
var
parent
=
parenthesizedExpr
.
Parent
;
...
...
src/Features/CSharp/Portable/TypeStyle/UseExplicitTypeCodeFixProvider.cs
浏览文件 @
8ae03859
...
...
@@ -80,9 +80,9 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
else
if
(
declarationContext
is
DeclarationExpressionSyntax
declarationExpression
)
{
typeSyntax
=
declarationExpression
.
Type
;
if
(
declarationExpression
.
Designation
.
IsKind
(
SyntaxKind
.
ParenthesizedVariableDesignation
))
if
(
declarationExpression
.
Designation
.
IsKind
(
SyntaxKind
.
ParenthesizedVariableDesignation
,
out
ParenthesizedVariableDesignationSyntax
variableDesignation
))
{
parensDesignation
=
(
ParenthesizedVariableDesignationSyntax
)
declarationExpression
.
Designation
;
parensDesignation
=
variable
Designation
;
}
}
else
...
...
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs
浏览文件 @
8ae03859
...
...
@@ -149,8 +149,8 @@ private ExpressionSyntax CreateTupleOrDeclarationExpression(INamedTypeSymbol tup
// i.e. (int x, int y) t = ... will be converted to (int x, int y) = ...
//
// If we had the "var t" form we'll convert that to the declaration expression "var (x, y)"
return
typeNode
.
IsKind
(
SyntaxKind
.
TupleType
)
?
(
ExpressionSyntax
)
CreateTupleExpression
(
(
TupleTypeSyntax
)
typeNode
)
return
typeNode
.
IsKind
(
SyntaxKind
.
TupleType
,
out
TupleTypeSyntax
tupleTypeSyntax
)
?
(
ExpressionSyntax
)
CreateTupleExpression
(
tupleTypeSyntax
)
:
CreateDeclarationExpression
(
tupleType
,
typeNode
);
}
...
...
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -260,12 +260,11 @@ private static bool IsViableTupleTypeSyntax(TypeSyntax type)
return
true
;
}
if
(
type
.
IsKind
(
SyntaxKind
.
TupleType
))
if
(
type
.
IsKind
(
SyntaxKind
.
TupleType
,
out
TupleTypeSyntax
tupleType
))
{
// '(int x, int y) t' can be convered to '(int x, int y)'. So all the elements
// need names.
var
tupleType
=
(
TupleTypeSyntax
)
type
;
foreach
(
var
element
in
tupleType
.
Elements
)
{
if
(
element
.
Identifier
.
IsKind
(
SyntaxKind
.
None
))
...
...
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs
浏览文件 @
8ae03859
...
...
@@ -214,8 +214,8 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
var
constraintClauses
=
default
(
SyntaxList
<
TypeParameterConstraintClauseSyntax
>);
var
body
=
anonymousFunction
.
Body
.
IsKind
(
SyntaxKind
.
Block
)
?
(
BlockSyntax
)
anonymousFunction
.
Body
var
body
=
anonymousFunction
.
Body
.
IsKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
)
?
block
:
null
;
var
expressionBody
=
anonymousFunction
.
Body
is
ExpressionSyntax
expression
...
...
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -291,21 +291,18 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
{
// var t = (Type)(<anonymous function>)
var
containingStatement
=
anonymousFunction
.
GetAncestor
<
StatementSyntax
>();
if
(
containingStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
))
if
(
containingStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
localDeclaration
)
&&
localDeclaration
.
Declaration
.
Variables
.
Count
==
1
)
{
localDeclaration
=
(
LocalDeclarationStatementSyntax
)
containingStatement
;
if
(
localDeclaration
.
Declaration
.
Variables
.
Count
==
1
)
var
variableDeclarator
=
localDeclaration
.
Declaration
.
Variables
[
0
]
;
if
(
variableDeclarator
.
Initializer
!=
null
)
{
var
va
riableDeclarator
=
localDeclaration
.
Declaration
.
Variables
[
0
]
;
if
(
va
riableDeclarator
.
Initializer
!=
null
)
var
va
lue
=
variableDeclarator
.
Initializer
.
Value
.
WalkDownParentheses
()
;
if
(
va
lue
is
CastExpressionSyntax
castExpression
)
{
var
value
=
variableDeclarator
.
Initializer
.
Value
.
WalkDownParentheses
();
if
(
value
is
CastExpressionSyntax
castExpression
)
if
(
castExpression
.
Expression
.
WalkDownParentheses
()
==
anonymousFunction
)
{
if
(
castExpression
.
Expression
.
WalkDownParentheses
()
==
anonymousFunction
)
{
return
true
;
}
return
true
;
}
}
}
...
...
@@ -321,8 +318,8 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
// Type t = null;
// t = <anonymous function>
if
(
anonymousFunction
.
IsParentKind
(
SyntaxKind
.
SimpleAssignmentExpression
,
out
AssignmentExpressionSyntax
assignment
)
&&
a
nonymousFunction
.
Par
ent
.
IsParentKind
(
SyntaxKind
.
ExpressionStatement
,
out
ExpressionStatementSyntax
expressionStatement
)
&&
anonymousFunction
.
Parent
.
Par
ent
.
IsParentKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
))
a
ssignm
ent
.
IsParentKind
(
SyntaxKind
.
ExpressionStatement
,
out
ExpressionStatementSyntax
expressionStatement
)
&&
expressionStatem
ent
.
IsParentKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
block
))
{
if
(
assignment
.
Left
.
IsKind
(
SyntaxKind
.
IdentifierName
))
{
...
...
@@ -330,23 +327,20 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
if
(
expressionStatementIndex
>=
1
)
{
var
previousStatement
=
block
.
Statements
[
expressionStatementIndex
-
1
];
if
(
previousStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
))
if
(
previousStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
localDeclaration
)
&&
localDeclaration
.
Declaration
.
Variables
.
Count
==
1
)
{
localDeclaration
=
(
LocalDeclarationStatementSyntax
)
previousStatement
;
if
(
localDeclaration
.
Declaration
.
Variables
.
Count
==
1
)
var
variableDeclarator
=
localDeclaration
.
Declaration
.
Variables
[
0
];
if
(
variableDeclarator
.
Initializer
==
null
||
variableDeclarator
.
Initializer
.
Value
.
IsKind
(
SyntaxKind
.
NullLiteralExpression
,
SyntaxKind
.
DefaultLiteralExpression
,
SyntaxKind
.
DefaultExpression
))
{
var
variableDeclarator
=
localDeclaration
.
Declaration
.
Variables
[
0
];
if
(
variableDeclarator
.
Initializer
==
null
||
variableDeclarator
.
Initializer
.
Value
.
IsKind
(
SyntaxKind
.
NullLiteralExpression
,
SyntaxKind
.
DefaultLiteralExpression
,
SyntaxKind
.
DefaultExpression
))
var
identifierName
=
(
IdentifierNameSyntax
)
assignment
.
Left
;
if
(
variableDeclarator
.
Identifier
.
ValueText
==
identifierName
.
Identifier
.
ValueText
)
{
var
identifierName
=
(
IdentifierNameSyntax
)
assignment
.
Left
;
if
(
variableDeclarator
.
Identifier
.
ValueText
==
identifierName
.
Identifier
.
ValueText
)
{
return
true
;
}
return
true
;
}
}
}
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
浏览文件 @
8ae03859
...
...
@@ -161,30 +161,27 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
castExpression
=
null
;
// The is check has to be in an if check: "if (x is Type)
if
(!
isExpression
.
Parent
.
IsKind
(
SyntaxKind
.
IfStatement
))
if
(!
isExpression
.
Parent
.
IsKind
(
SyntaxKind
.
IfStatement
,
out
ifStatement
))
{
return
false
;
}
ifStatement
=
(
IfStatementSyntax
)
isExpression
.
Parent
;
if
(!
ifStatement
.
Statement
.
IsKind
(
SyntaxKind
.
Block
))
if
(!
ifStatement
.
Statement
.
IsKind
(
SyntaxKind
.
Block
,
out
BlockSyntax
ifBlock
))
{
return
false
;
}
var
ifBlock
=
(
BlockSyntax
)
ifStatement
.
Statement
;
if
(
ifBlock
.
Statements
.
Count
==
0
)
{
return
false
;
}
var
firstStatement
=
ifBlock
.
Statements
[
0
];
if
(!
firstStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
))
if
(!
firstStatement
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
out
localDeclarationStatement
))
{
return
false
;
}
localDeclarationStatement
=
(
LocalDeclarationStatementSyntax
)
firstStatement
;
if
(
localDeclarationStatement
.
Declaration
.
Variables
.
Count
!=
1
)
{
return
false
;
...
...
@@ -197,12 +194,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
}
var
declaratorValue
=
declarator
.
Initializer
.
Value
.
WalkDownParentheses
();
if
(!
declaratorValue
.
IsKind
(
SyntaxKind
.
CastExpression
))
if
(!
declaratorValue
.
IsKind
(
SyntaxKind
.
CastExpression
,
out
castExpression
))
{
return
false
;
}
castExpression
=
(
CastExpressionSyntax
)
declaratorValue
;
if
(!
SyntaxFactory
.
AreEquivalent
(
isExpression
.
Left
.
WalkDownParentheses
(),
castExpression
.
Expression
.
WalkDownParentheses
(),
topLevel
:
false
)
||
!
SyntaxFactory
.
AreEquivalent
(
isExpression
.
Right
.
WalkDownParentheses
(),
castExpression
.
Type
,
topLevel
:
false
))
{
...
...
src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs
浏览文件 @
8ae03859
...
...
@@ -193,11 +193,11 @@ private static bool IsVerbatimStringToken(SyntaxToken token)
{
return
GetClassificationForTypeDeclarationIdentifier
(
token
);
}
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
DelegateDeclaration
)
&&
((
DelegateDeclarationSyntax
)
token
.
Parent
)
.
Identifier
==
token
)
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
DelegateDeclaration
,
out
DelegateDeclarationSyntax
?
delegateDecl
)
&&
delegateDecl
.
Identifier
==
token
)
{
return
ClassificationTypeNames
.
DelegateName
;
}
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameter
)
&&
((
TypeParameterSyntax
)
token
.
Parent
)
.
Identifier
==
token
)
else
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameter
,
out
TypeParameterSyntax
?
typeParameter
)
&&
typeParameter
.
Identifier
==
token
)
{
return
ClassificationTypeNames
.
TypeParameterName
;
}
...
...
@@ -453,13 +453,10 @@ private static bool IsOperator(this SyntaxKind kind)
private
static
bool
IsActualContextualKeyword
(
SyntaxToken
token
)
{
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
LabeledStatement
))
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
LabeledStatement
,
out
LabeledStatementSyntax
?
statement
)
&&
statement
.
Identifier
==
token
)
{
var
statement
=
(
LabeledStatementSyntax
)
token
.
Parent
;
if
(
statement
.
Identifier
==
token
)
{
return
false
;
}
return
false
;
}
// Ensure that the text and value text are the same. Otherwise, the identifier might
...
...
src/Workspaces/CSharp/Portable/FindSymbols/CSharpDeclaredSymbolInfoFactoryService.cs
浏览文件 @
8ae03859
...
...
@@ -78,13 +78,13 @@ private void AddAliasMaps(SyntaxNode node, List<Dictionary<string, string>> alia
{
for
(
var
current
=
node
;
current
!=
null
;
current
=
current
.
Parent
)
{
if
(
current
.
IsKind
(
SyntaxKind
.
NamespaceDeclaration
))
if
(
current
.
IsKind
(
SyntaxKind
.
NamespaceDeclaration
,
out
NamespaceDeclarationSyntax
nsDecl
))
{
ProcessUsings
(
aliasMaps
,
((
NamespaceDeclarationSyntax
)
current
)
.
Usings
);
ProcessUsings
(
aliasMaps
,
nsDecl
.
Usings
);
}
else
if
(
current
.
IsKind
(
SyntaxKind
.
CompilationUnit
))
else
if
(
current
.
IsKind
(
SyntaxKind
.
CompilationUnit
,
out
CompilationUnitSyntax
compilationUnit
))
{
ProcessUsings
(
aliasMaps
,
((
CompilationUnitSyntax
)
current
)
.
Usings
);
ProcessUsings
(
aliasMaps
,
compilationUnit
.
Usings
);
}
}
}
...
...
src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
浏览文件 @
8ae03859
...
...
@@ -590,9 +590,9 @@ private SyntaxToken RenameToken(SyntaxToken oldToken, SyntaxToken newToken, stri
else
{
var
parsedIdentifier
=
SyntaxFactory
.
ParseName
(
currentNewIdentifier
);
if
(
parsedIdentifier
.
IsKind
(
SyntaxKind
.
IdentifierName
))
if
(
parsedIdentifier
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
identifierName
))
{
valueText
=
((
IdentifierNameSyntax
)
parsedIdentifier
)
.
Identifier
.
ValueText
;
valueText
=
identifierName
.
Identifier
.
ValueText
;
}
}
...
...
@@ -730,12 +730,11 @@ private SyntaxToken RenameWithinToken(SyntaxToken oldToken, SyntaxToken newToken
SyntaxToken
token
,
IEnumerable
<
ISymbol
>
newReferencedSymbols
)
{
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
IdentifierName
)
&&
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
ExpressionSyntax
expression
)
&&
token
.
Parent
.
IsParentKind
(
SyntaxKind
.
InvocationExpression
)
&&
token
.
GetPreviousToken
().
Kind
()
!=
SyntaxKind
.
DotToken
&&
token
.
GetNextToken
().
Kind
()
!=
SyntaxKind
.
DotToken
)
{
var
expression
=
(
ExpressionSyntax
)
token
.
Parent
;
var
enclosingMemberDeclaration
=
expression
.
FirstAncestorOrSelf
<
MemberDeclarationSyntax
>();
if
(
enclosingMemberDeclaration
!=
null
)
{
...
...
@@ -1247,17 +1246,17 @@ public static SemanticModel GetSemanticModelForNode(SyntaxNode node, SemanticMod
var
nodeToSpeculate
=
node
.
GetAncestorsOrThis
(
n
=>
SpeculationAnalyzer
.
CanSpeculateOnNode
(
n
)).
LastOrDefault
();
if
(
nodeToSpeculate
==
null
)
{
if
(
node
.
IsKind
(
SyntaxKind
.
NameMemberCref
))
if
(
node
.
IsKind
(
SyntaxKind
.
NameMemberCref
,
out
NameMemberCrefSyntax
nameMember
))
{
nodeToSpeculate
=
((
NameMemberCrefSyntax
)
node
)
.
Name
;
nodeToSpeculate
=
nameMember
.
Name
;
}
else
if
(
node
.
IsKind
(
SyntaxKind
.
QualifiedCref
))
else
if
(
node
.
IsKind
(
SyntaxKind
.
QualifiedCref
,
out
QualifiedCrefSyntax
qualifiedCref
))
{
nodeToSpeculate
=
((
QualifiedCrefSyntax
)
node
)
.
Container
;
nodeToSpeculate
=
qualifiedCref
.
Container
;
}
else
if
(
node
.
IsKind
(
SyntaxKind
.
TypeConstraint
))
else
if
(
node
.
IsKind
(
SyntaxKind
.
TypeConstraint
,
out
TypeConstraintSyntax
typeConstraint
))
{
nodeToSpeculate
=
((
TypeConstraintSyntax
)
node
)
.
Type
;
nodeToSpeculate
=
typeConstraint
.
Type
;
}
else
if
(
node
is
BaseTypeSyntax
baseType
)
{
...
...
src/Workspaces/CSharp/Portable/Simplification/CSharpSimplificationService.Expander.cs
浏览文件 @
8ae03859
...
...
@@ -1064,9 +1064,8 @@ public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax
}
var
rewrittenNode
=
(
InvocationExpressionSyntax
)
base
.
VisitInvocationExpression
(
originalNode
);
if
(
originalNode
.
Expression
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
))
if
(
originalNode
.
Expression
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
,
out
MemberAccessExpressionSyntax
memberAccess
))
{
var
memberAccess
=
(
MemberAccessExpressionSyntax
)
originalNode
.
Expression
;
var
targetSymbol
=
SimplificationHelpers
.
GetOriginalSymbolInfo
(
_semanticModel
,
memberAccess
.
Name
);
if
(
targetSymbol
!=
null
&&
targetSymbol
.
IsReducedExtension
()
&&
memberAccess
.
Expression
!=
null
)
...
...
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/ExpressionSimplifier.cs
浏览文件 @
8ae03859
...
...
@@ -483,7 +483,7 @@ private static bool IsThisOrTypeOrNamespace(MemberAccessExpressionSyntax memberA
if
(
previousToken
.
Kind
()
==
SyntaxKind
.
OpenParenToken
&&
previousToken
.
Parent
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenExpr
)
&&
!
p
reviousToken
.
Parent
.
IsParentKind
(
SyntaxKind
.
ParenthesizedExpression
)
&&
!
p
arenExpr
.
IsParentKind
(
SyntaxKind
.
ParenthesizedExpression
)
&&
parenExpr
.
Expression
.
Kind
()
==
SyntaxKind
.
SimpleMemberAccessExpression
&&
symbol
!=
null
&&
symbol
.
Kind
==
SymbolKind
.
Method
)
{
...
...
@@ -547,10 +547,8 @@ private static bool ParserWouldTreatExpressionAsCast(ExpressionSyntax reducedNod
private
static
bool
IsNameOrMemberAccessButNoExpression
(
SyntaxNode
node
)
{
if
(
node
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
))
if
(
node
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
,
out
MemberAccessExpressionSyntax
memberAccess
))
{
var
memberAccess
=
(
MemberAccessExpressionSyntax
)
node
;
return
memberAccess
.
Expression
.
IsKind
(
SyntaxKind
.
IdentifierName
)
||
IsNameOrMemberAccessButNoExpression
(
memberAccess
.
Expression
);
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/ExpressionSyntaxExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -26,10 +26,8 @@ public static ExpressionSyntax WalkUpParentheses(this ExpressionSyntax expressio
public
static
ExpressionSyntax
WalkDownParentheses
(
this
ExpressionSyntax
expression
)
{
while
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
{
expression
=
((
ParenthesizedExpressionSyntax
)
expression
).
Expression
;
}
while
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenExpression
))
expression
=
parenExpression
.
Expression
;
return
expression
;
}
...
...
@@ -558,15 +556,15 @@ private static bool CanReplace(ISymbol symbol)
var
parentNonExpression
=
expression
.
GetAncestors
().
SkipWhile
(
n
=>
n
is
ExpressionSyntax
).
FirstOrDefault
();
var
topExpression
=
expression
;
while
(
topExpression
.
Parent
is
TypeSyntax
)
while
(
topExpression
.
Parent
is
TypeSyntax
typeSyntax
)
{
topExpression
=
(
TypeSyntax
)
topExpression
.
Parent
;
topExpression
=
typeSyntax
;
}
if
(
parentNonExpression
!=
null
&&
parentNonExpression
.
IsKind
(
SyntaxKind
.
FromClause
)
&&
parentNonExpression
.
IsKind
(
SyntaxKind
.
FromClause
,
out
FromClauseSyntax
fromClause
)
&&
topExpression
!=
null
&&
((
FromClauseSyntax
)
parentNonExpression
)
.
Type
==
topExpression
)
fromClause
.
Type
==
topExpression
)
{
return
false
;
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/TypeSyntaxExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -9,10 +9,8 @@ namespace Microsoft.CodeAnalysis.CSharp.Extensions
internal
static
partial
class
TypeSyntaxExtensions
{
public
static
bool
IsVoid
(
this
TypeSyntax
typeSyntax
)
{
return
typeSyntax
.
IsKind
(
SyntaxKind
.
PredefinedType
)
&&
((
PredefinedTypeSyntax
)
typeSyntax
).
Keyword
.
IsKind
(
SyntaxKind
.
VoidKeyword
);
}
=>
typeSyntax
.
IsKind
(
SyntaxKind
.
PredefinedType
,
out
PredefinedTypeSyntax
predefinedType
)
&&
predefinedType
.
Keyword
.
IsKind
(
SyntaxKind
.
VoidKeyword
);
public
static
bool
IsPartial
(
this
TypeSyntax
typeSyntax
)
{
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/SuppressFormattingRule.cs
浏览文件 @
8ae03859
...
...
@@ -54,10 +54,10 @@ private void AddSpecificNodesSuppressOperations(List<SuppressOperation> list, Sy
}
// ex: `e is Type ( /* positional */ )`
if
(
node
.
IsKind
(
SyntaxKind
.
RecursivePattern
))
if
(
node
.
IsKind
(
SyntaxKind
.
RecursivePattern
,
out
RecursivePatternSyntax
recursivePattern
))
{
var
positional
=
((
RecursivePatternSyntax
)
node
)
.
PositionalPatternClause
;
var
property
=
((
RecursivePatternSyntax
)
node
)
.
PropertyPatternClause
;
var
positional
=
recursivePattern
.
PositionalPatternClause
;
var
property
=
recursivePattern
.
PropertyPatternClause
;
if
(
positional
!=
null
)
{
var
openParenToken
=
positional
.
OpenParenToken
;
...
...
@@ -112,7 +112,7 @@ private void AddSpecificNodesSuppressOperations(List<SuppressOperation> list, Sy
// Formatting should refrain from inserting new lines, unless the user already split across multiple lines
AddSuppressWrappingIfOnSingleLineOperation
(
list
,
isPattern
.
GetFirstToken
(),
isPattern
.
GetLastToken
());
if
(
isPattern
.
Pattern
.
IsKind
(
SyntaxKind
.
RecursivePattern
))
if
(
isPattern
.
Pattern
.
IsKind
(
SyntaxKind
.
RecursivePattern
,
out
recursivePattern
))
{
// ex:
// ```
...
...
@@ -124,7 +124,7 @@ private void AddSpecificNodesSuppressOperations(List<SuppressOperation> list, Sy
// _ = expr is { }$$
// M();
// ```
var
propertyPatternClause
=
((
RecursivePatternSyntax
)
isPattern
.
Pattern
)
.
PropertyPatternClause
;
var
propertyPatternClause
=
recursivePattern
.
PropertyPatternClause
;
if
(
propertyPatternClause
!=
null
)
{
AddSuppressWrappingIfOnSingleLineOperation
(
list
,
isPattern
.
IsKeyword
,
propertyPatternClause
.
GetLastToken
());
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs
浏览文件 @
8ae03859
...
...
@@ -206,16 +206,12 @@ public SyntaxNode GetExpressionOfReturnStatement(SyntaxNode node)
=>
(
node
as
ReturnStatementSyntax
)?.
Expression
;
public
bool
IsThisConstructorInitializer
(
SyntaxToken
token
)
{
return
token
.
Parent
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
)
&&
((
ConstructorInitializerSyntax
)
token
.
Parent
).
ThisOrBaseKeyword
==
token
;
}
=>
token
.
Parent
.
IsKind
(
SyntaxKind
.
ThisConstructorInitializer
,
out
ConstructorInitializerSyntax
constructorInit
)
&&
constructorInit
.
ThisOrBaseKeyword
==
token
;
public
bool
IsBaseConstructorInitializer
(
SyntaxToken
token
)
{
return
token
.
Parent
.
IsKind
(
SyntaxKind
.
BaseConstructorInitializer
)
&&
((
ConstructorInitializerSyntax
)
token
.
Parent
).
ThisOrBaseKeyword
==
token
;
}
=>
token
.
Parent
.
IsKind
(
SyntaxKind
.
BaseConstructorInitializer
,
out
ConstructorInitializerSyntax
constructorInit
)
&&
constructorInit
.
ThisOrBaseKeyword
==
token
;
public
bool
IsQueryKeyword
(
SyntaxToken
token
)
{
...
...
@@ -1277,10 +1273,9 @@ public bool IsUsingOrExternOrImport(SyntaxNode node)
}
public
bool
IsGlobalAttribute
(
SyntaxNode
node
)
{
return
node
.
IsKind
(
SyntaxKind
.
Attribute
)
&&
node
.
Parent
.
IsKind
(
SyntaxKind
.
AttributeList
)
&&
((
AttributeListSyntax
)
node
.
Parent
).
Target
?.
Identifier
.
Kind
()
==
SyntaxKind
.
AssemblyKeyword
;
}
=>
node
.
IsKind
(
SyntaxKind
.
Attribute
)
&&
node
.
Parent
.
IsKind
(
SyntaxKind
.
AttributeList
,
out
AttributeListSyntax
attributeList
)
&&
attributeList
.
Target
?.
Identifier
.
Kind
()
==
SyntaxKind
.
AssemblyKeyword
;
private
static
bool
IsMemberDeclaration
(
SyntaxNode
node
)
{
...
...
@@ -1341,10 +1336,8 @@ public SyntaxNode GetObjectCreationType(SyntaxNode node)
=>
((
ObjectCreationExpressionSyntax
)
node
).
Type
;
public
bool
IsSimpleAssignmentStatement
(
SyntaxNode
statement
)
{
return
statement
.
IsKind
(
SyntaxKind
.
ExpressionStatement
)
&&
((
ExpressionStatementSyntax
)
statement
).
Expression
.
IsKind
(
SyntaxKind
.
SimpleAssignmentExpression
);
}
=>
statement
.
IsKind
(
SyntaxKind
.
ExpressionStatement
,
out
ExpressionStatementSyntax
exprStatement
)
&&
exprStatement
.
Expression
.
IsKind
(
SyntaxKind
.
SimpleAssignmentExpression
);
public
void
GetPartsOfAssignmentStatement
(
SyntaxNode
statement
,
out
SyntaxNode
left
,
out
SyntaxToken
operatorToken
,
out
SyntaxNode
right
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpTypeStyleHelper.State.cs
浏览文件 @
8ae03859
...
...
@@ -60,8 +60,8 @@ internal partial class CSharpTypeStyleHelper
this
.
TypeStylePreference
=
stylePreferences
;
IsTypeApparentInContext
=
declaration
.
IsKind
(
SyntaxKind
.
VariableDeclaration
)
&&
IsTypeApparentInDeclaration
(
(
VariableDeclarationSyntax
)
declaration
,
semanticModel
,
TypeStylePreference
,
cancellationToken
);
declaration
.
IsKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
varDecl
)
&&
IsTypeApparentInDeclaration
(
varDecl
,
semanticModel
,
TypeStylePreference
,
cancellationToken
);
IsInIntrinsicTypeContext
=
IsPredefinedTypeInDeclaration
(
declaration
,
semanticModel
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseExplicitTypeHelper.cs
浏览文件 @
8ae03859
...
...
@@ -86,11 +86,10 @@ protected override bool ShouldAnalyzeForEachStatement(ForEachStatementSyntax for
return
false
;
}
if
(
typeName
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
)
&&
if
(
typeName
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
variableDeclaration
)
&&
typeName
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
LocalDeclarationStatement
,
SyntaxKind
.
ForStatement
,
SyntaxKind
.
UsingStatement
))
{
// check assignment for variable declarations.
var
variableDeclaration
=
(
VariableDeclarationSyntax
)
typeName
.
Parent
;
var
variable
=
variableDeclaration
.
Variables
.
First
();
if
(!
AssignmentSupportsStylePreference
(
variable
.
Identifier
,
typeName
,
variable
.
Initializer
.
Value
,
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs
浏览文件 @
8ae03859
...
...
@@ -106,11 +106,9 @@ protected override bool IsStylePreferred(in State state)
return
false
;
}
if
(
typeName
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
)
&&
if
(
typeName
.
Parent
.
IsKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
variableDeclaration
)
&&
typeName
.
Parent
.
IsParentKind
(
SyntaxKind
.
LocalDeclarationStatement
,
SyntaxKind
.
ForStatement
,
SyntaxKind
.
UsingStatement
))
{
var
variableDeclaration
=
(
VariableDeclarationSyntax
)
typeName
.
Parent
;
// implicitly typed variables cannot be constants.
if
((
variableDeclaration
.
Parent
as
LocalDeclarationStatementSyntax
)?.
IsConst
==
true
)
{
...
...
@@ -336,9 +334,9 @@ private bool IsSwitchExpressionAndCannotUseVar(TypeSyntax typeName, ExpressionSy
foreach
(
var
arm
in
((
SwitchExpressionSyntax
)
initializer
).
Arms
)
{
var
expression
=
arm
.
Expression
;
if
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
if
(
expression
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenExpression
))
{
expression
=
((
ParenthesizedExpressionSyntax
)
expression
)
.
WalkDownParentheses
();
expression
=
parenExpression
.
WalkDownParentheses
();
}
if
(!
expression
.
IsKind
(
SyntaxKind
.
ThrowExpression
)
&&
!
expression
.
IsKind
(
SyntaxKind
.
NullLiteralExpression
)
&&
!
expression
.
IsKind
(
SyntaxKind
.
DefaultLiteralExpression
))
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/CastExpressionSyntaxExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -61,8 +61,8 @@ internal static partial class CastExpressionSyntaxExtensions
}
}
if
(
parentNode
.
IsKind
(
SyntaxKind
.
ConditionalExpression
)
&&
((
ConditionalExpressionSyntax
)
parentNode
)
.
Condition
==
expression
)
if
(
parentNode
.
IsKind
(
SyntaxKind
.
ConditionalExpression
,
out
ConditionalExpressionSyntax
conditionalExpression
)
&&
conditionalExpression
.
Condition
==
expression
)
{
return
semanticModel
.
Compilation
.
GetSpecialType
(
SpecialType
.
System_Boolean
);
}
...
...
@@ -83,10 +83,10 @@ private static bool IsRequiredCastForReferenceEqualityComparison(ITypeSymbol out
{
var
expression
=
castExpression
.
WalkUpParentheses
();
var
parentNode
=
expression
.
Parent
;
if
(
parentNode
.
IsKind
(
SyntaxKind
.
EqualsExpression
)
||
parentNode
.
IsKind
(
SyntaxKind
.
NotEqualsExpression
))
if
(
parentNode
.
IsKind
(
SyntaxKind
.
EqualsExpression
,
out
BinaryExpressionSyntax
binaryExpression
)
||
parentNode
.
IsKind
(
SyntaxKind
.
NotEqualsExpression
,
out
binaryExpression
))
{
// Reference comparison.
var
binaryExpression
=
(
BinaryExpressionSyntax
)
parentNode
;
other
=
binaryExpression
.
Left
==
expression
?
binaryExpression
.
Right
:
binaryExpression
.
Left
;
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTokenExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -272,9 +272,8 @@ public static bool IsAfterPossibleCast(this SyntaxToken token)
return
true
;
}
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
))
if
(
token
.
Parent
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
,
out
ParenthesizedExpressionSyntax
parenExpr
))
{
var
parenExpr
=
token
.
Parent
as
ParenthesizedExpressionSyntax
;
var
expr
=
parenExpr
.
Expression
;
if
(
expr
is
TypeSyntax
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -578,9 +578,9 @@ public static bool IsAttributeNameContext(this SyntaxTree syntaxTree, int positi
// ref $$
// readonly ref $$
if
(
container
.
IsKind
(
SyntaxKind
.
IncompleteMember
))
if
(
container
.
IsKind
(
SyntaxKind
.
IncompleteMember
,
out
IncompleteMemberSyntax
incompleteMember
))
{
return
((
IncompleteMemberSyntax
)
container
)
.
Type
.
IsKind
(
SyntaxKind
.
RefType
);
return
incompleteMember
.
Type
.
IsKind
(
SyntaxKind
.
RefType
);
}
if
(
container
.
IsKind
(
SyntaxKind
.
CompilationUnit
)
||
...
...
@@ -852,10 +852,8 @@ public static bool IsTypeParameterConstraintContext(this SyntaxTree syntaxTree,
// where T : struct, |
// where T : Goo, |
if
(
token
.
IsKind
(
SyntaxKind
.
CommaToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameterConstraintClause
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
TypeParameterConstraintClause
,
out
TypeParameterConstraintClauseSyntax
constraintClause
))
{
var
constraintClause
=
token
.
Parent
as
TypeParameterConstraintClauseSyntax
;
// Check if there's a 'new()' constraint. If there isn't, or we're before it, then
// this is a type parameter constraint context.
var
firstConstructorConstraint
=
constraintClause
.
Constraints
.
FirstOrDefault
(
t
=>
t
is
ConstructorConstraintSyntax
);
...
...
@@ -956,8 +954,8 @@ public static bool IsDefaultExpressionContext(this SyntaxTree syntaxTree, int po
// Bind T to see if it is a type. If it is we don't show signature help.
if
(
name
.
IsParentKind
(
SyntaxKind
.
LessThanExpression
)
&&
name
.
Parent
.
IsParentKind
(
SyntaxKind
.
ConditionalExpression
,
out
ConditionalExpressionSyntax
conditional
)
&&
name
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
ExpressionStatement
)
&&
name
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
GlobalStatement
))
conditional
.
IsParentKind
(
SyntaxKind
.
ExpressionStatement
)
&&
conditional
.
Parent
.
IsParentKind
(
SyntaxKind
.
GlobalStatement
))
{
var
conditionOrType
=
semanticModelOpt
.
GetSymbolInfo
(
conditional
.
Condition
,
cancellationToken
);
if
(
conditionOrType
.
GetBestOrAllSymbols
().
FirstOrDefault
()
!=
null
&&
...
...
@@ -1004,9 +1002,9 @@ public static bool IsDefaultExpressionContext(this SyntaxTree syntaxTree, int po
}
if
(
token
.
IsKind
(
SyntaxKind
.
CommaToken
)
&&
token
.
Parent
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
ParameterList
,
out
ParameterListSyntax
parameterList
)
&&
parameterList
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
{
var
parameterList
=
(
ParameterListSyntax
)
token
.
Parent
;
var
commaIndex
=
parameterList
.
Parameters
.
GetWithSeparators
().
IndexOf
(
token
);
parameterIndex
=
commaIndex
/
2
+
1
;
...
...
@@ -1016,22 +1014,19 @@ public static bool IsDefaultExpressionContext(this SyntaxTree syntaxTree, int po
if
(
token
.
IsKind
(
SyntaxKind
.
CloseBracketToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
AttributeList
)
&&
token
.
Parent
.
IsParentKind
(
SyntaxKind
.
Parameter
,
out
ParameterSyntax
parameter
)
&&
token
.
Parent
.
Parent
.
Parent
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
parameter
.
IsParentKind
(
SyntaxKind
.
ParameterList
,
out
parameterList
)
&&
parameterList
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
{
var
parameterList
=
(
ParameterListSyntax
)
parameter
.
Parent
;
parameterIndex
=
parameterList
.
Parameters
.
IndexOf
(
parameter
);
return
true
;
}
if
(
token
.
IsKind
(
SyntaxKind
.
RefKeyword
,
SyntaxKind
.
InKeyword
,
SyntaxKind
.
OutKeyword
,
SyntaxKind
.
ThisKeyword
,
SyntaxKind
.
ParamsKeyword
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
Parameter
)
&&
token
.
Parent
.
Parent
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
Parameter
,
out
parameter
)
&&
parameter
.
IsParentKind
(
SyntaxKind
.
ParameterList
,
out
parameterList
)
&&
parameterList
.
IsDelegateOrConstructorOrLocalFunctionOrMethodOrOperatorParameterList
(
includeOperators
))
{
parameter
=
(
ParameterSyntax
)
token
.
Parent
;
var
parameterList
=
(
ParameterListSyntax
)
parameter
.
Parent
;
parameterIndex
=
parameterList
.
Parameters
.
IndexOf
(
parameter
);
previousModifier
=
token
.
Kind
();
return
true
;
...
...
@@ -1389,13 +1384,11 @@ public static bool IsPossibleTupleOpenParenOrComma(this SyntaxToken possibleComm
if
(
leftToken
.
IsKind
(
SyntaxKind
.
OpenParenToken
,
SyntaxKind
.
CommaToken
))
{
var
outer
=
UnwrapPossibleTuple
(
leftToken
.
Parent
);
if
(
outer
.
Parent
.
IsKind
(
SyntaxKind
.
ForEachStatement
))
if
(
outer
.
Parent
.
IsKind
(
SyntaxKind
.
ForEachStatement
,
out
ForEachStatementSyntax
@foreach
))
{
var
@foreach
=
(
ForEachStatementSyntax
)
outer
.
Parent
;
if
(
@foreach
.
Expression
==
outer
&&
@foreach
.
Type
.
IsKind
(
SyntaxKind
.
IdentifierName
)
&&
((
IdentifierNameSyntax
)
@foreach
.
Type
)
.
Identifier
.
ValueText
==
"var"
)
@foreach
.
Type
.
IsKind
(
SyntaxKind
.
IdentifierName
,
out
IdentifierNameSyntax
identifierName
)
&&
identifierName
.
Identifier
.
ValueText
==
"var"
)
{
return
true
;
}
...
...
@@ -1577,8 +1570,8 @@ public static bool HasNames(this TupleExpressionSyntax tuple)
// out |
if
(
token
.
IsKind
(
SyntaxKind
.
OutKeyword
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
Argument
)
&&
((
ArgumentSyntax
)
token
.
Parent
)
.
RefKindKeyword
==
token
)
token
.
Parent
.
IsKind
(
SyntaxKind
.
Argument
,
out
ArgumentSyntax
argument
)
&&
argument
.
RefKindKeyword
==
token
)
{
return
true
;
}
...
...
@@ -1879,10 +1872,8 @@ public static bool IsDefiniteCastTypeContext(this SyntaxTree syntaxTree, int pos
}
if
(
token
.
IsKind
(
SyntaxKind
.
EqualsToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
EqualsValueClause
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
EqualsValueClause
,
out
EqualsValueClauseSyntax
equalsValue
))
{
var
equalsValue
=
(
EqualsValueClauseSyntax
)
token
.
Parent
;
if
(
equalsValue
.
IsParentKind
(
SyntaxKind
.
VariableDeclarator
)
&&
equalsValue
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
))
{
...
...
@@ -2175,11 +2166,9 @@ public static bool IsLabelContext(this SyntaxTree syntaxTree, int position, Canc
// goo ? |
if
(
token
.
IsKind
(
SyntaxKind
.
QuestionToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
ConditionalExpression
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
ConditionalExpression
,
out
ConditionalExpressionSyntax
conditionalExpression
))
{
// If the condition is simply a TypeSyntax that binds to a type, treat this as a nullable type.
var
conditionalExpression
=
(
ConditionalExpressionSyntax
)
token
.
Parent
;
return
!(
conditionalExpression
.
Condition
is
TypeSyntax
type
)
||
!
type
.
IsPotentialTypeName
(
semanticModelOpt
,
cancellationToken
);
}
...
...
@@ -2319,9 +2308,8 @@ public static bool IsLabelContext(this SyntaxTree syntaxTree, int position, Canc
// for (; |
// for (; ; |
if
(
token
.
IsKind
(
SyntaxKind
.
SemicolonToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
ForStatement
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
ForStatement
,
out
ForStatementSyntax
forStatement
))
{
var
forStatement
=
(
ForStatementSyntax
)
token
.
Parent
;
if
(
token
==
forStatement
.
FirstSemicolonToken
||
token
==
forStatement
.
SecondSemicolonToken
)
{
...
...
@@ -2331,13 +2319,10 @@ public static bool IsLabelContext(this SyntaxTree syntaxTree, int position, Canc
// for ( |
if
(
token
.
IsKind
(
SyntaxKind
.
OpenParenToken
)
&&
token
.
Parent
.
IsKind
(
SyntaxKind
.
ForStatement
))
token
.
Parent
.
IsKind
(
SyntaxKind
.
ForStatement
,
out
forStatement
)
&&
token
==
forStatement
.
OpenParenToken
)
{
var
forStatement
=
(
ForStatementSyntax
)
token
.
Parent
;
if
(
token
==
forStatement
.
OpenParenToken
)
{
return
true
;
}
return
true
;
}
// for (; ; Goo(), |
...
...
@@ -2517,18 +2502,16 @@ public static bool IsLabelContext(this SyntaxTree syntaxTree, int position, Canc
// $@"{x} { |
if
(
token
.
IsKind
(
SyntaxKind
.
OpenBraceToken
))
{
return
token
.
Parent
.
IsKind
(
SyntaxKind
.
Interpolation
)
&&
((
InterpolationSyntax
)
token
.
Parent
)
.
OpenBraceToken
==
token
;
return
token
.
Parent
.
IsKind
(
SyntaxKind
.
Interpolation
,
out
InterpolationSyntax
interpolation
)
&&
interpolation
.
OpenBraceToken
==
token
;
}
return
false
;
}
public
static
bool
IsInvocationOfVarExpression
(
this
SyntaxToken
token
)
{
return
token
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
InvocationExpression
)
&&
((
InvocationExpressionSyntax
)
token
.
Parent
.
Parent
).
Expression
.
ToString
()
==
"var"
;
}
=>
token
.
Parent
.
Parent
.
IsKind
(
SyntaxKind
.
InvocationExpression
,
out
InvocationExpressionSyntax
invocation
)
&&
invocation
.
Expression
.
ToString
()
==
"var"
;
public
static
bool
IsNameOfContext
(
this
SyntaxTree
syntaxTree
,
int
position
,
SemanticModel
semanticModelOpt
=
null
,
CancellationToken
cancellationToken
=
default
)
{
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ParenthesizedExpressionSyntaxExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -298,9 +298,8 @@ private static bool RemovalMayIntroduceInterpolationAmbiguity(ParenthesizedExpre
return
false
;
}
if
(
ancestor
.
IsKind
(
SyntaxKind
.
Interpolation
))
if
(
ancestor
.
IsKind
(
SyntaxKind
.
Interpolation
,
out
interpolation
))
{
interpolation
=
(
InterpolationSyntax
)
ancestor
;
break
;
}
}
...
...
@@ -563,28 +562,14 @@ private static bool RemovalMayIntroduceCommaListAmbiguity(ParenthesizedExpressio
// We can't remove parentheses from a less-than expression in the following cases:
// F((x < x), x > (1 + 2))
// {(x < x), x > (1 + 2)}
var
lessThanExpression
=
(
BinaryExpressionSyntax
)
node
.
Expression
;
if
(
IsNextExpressionPotentiallyAmbiguous
(
node
))
{
return
true
;
}
return
false
;
return
IsNextExpressionPotentiallyAmbiguous
(
node
);
}
else
if
(
node
.
Expression
.
IsKind
(
SyntaxKind
.
GreaterThanExpression
))
{
// We can't remove parentheses from a greater-than expression in the following cases:
// F(x < x, (x > (1 + 2)))
// {x < x, (x > (1 + 2))}
var
greaterThanExpression
=
(
BinaryExpressionSyntax
)
node
.
Expression
;
if
(
IsPreviousExpressionPotentiallyAmbiguous
(
node
))
{
return
true
;
}
return
false
;
return
IsPreviousExpressionPotentiallyAmbiguous
(
node
);
}
return
false
;
...
...
@@ -615,13 +600,11 @@ private static bool IsPreviousExpressionPotentiallyAmbiguous(ExpressionSyntax no
}
if
(
previousExpression
==
null
||
!
previousExpression
.
IsKind
(
SyntaxKind
.
LessThanExpression
))
!
previousExpression
.
IsKind
(
SyntaxKind
.
LessThanExpression
,
out
BinaryExpressionSyntax
lessThanExpression
))
{
return
false
;
}
var
lessThanExpression
=
(
BinaryExpressionSyntax
)
previousExpression
;
return
(
IsSimpleOrDottedName
(
lessThanExpression
.
Left
)
||
lessThanExpression
.
Left
.
IsKind
(
SyntaxKind
.
CastExpression
))
&&
IsSimpleOrDottedName
(
lessThanExpression
.
Right
);
...
...
@@ -652,13 +635,11 @@ private static bool IsNextExpressionPotentiallyAmbiguous(ExpressionSyntax node)
}
if
(
nextExpression
==
null
||
!
nextExpression
.
IsKind
(
SyntaxKind
.
GreaterThanExpression
))
!
nextExpression
.
IsKind
(
SyntaxKind
.
GreaterThanExpression
,
out
BinaryExpressionSyntax
greaterThanExpression
))
{
return
false
;
}
var
greaterThanExpression
=
(
BinaryExpressionSyntax
)
nextExpression
;
return
IsSimpleOrDottedName
(
greaterThanExpression
.
Left
)
&&
(
greaterThanExpression
.
Right
.
IsKind
(
SyntaxKind
.
ParenthesizedExpression
)
||
greaterThanExpression
.
Right
.
IsKind
(
SyntaxKind
.
CastExpression
));
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/SemanticModelExtensions.cs
浏览文件 @
8ae03859
...
...
@@ -332,7 +332,7 @@ public static ISet<INamespaceSymbol> GetUsingNamespacesInScope(this SemanticMode
if
(
type
!=
null
)
{
if
(
type
.
Parent
is
BaseTypeSyntax
baseType
&&
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
BaseList
,
out
BaseListSyntax
baseList
)
&&
baseType
.
IsParentKind
(
SyntaxKind
.
BaseList
,
out
BaseListSyntax
baseList
)
&&
baseType
.
Type
==
type
)
{
var
containingType
=
semanticModel
.
GetDeclaredSymbol
(
type
.
GetAncestor
<
BaseTypeDeclarationSyntax
>(),
cancellationToken
)
as
INamedTypeSymbol
;
...
...
@@ -350,7 +350,7 @@ public static ISet<INamespaceSymbol> GetUsingNamespacesInScope(this SemanticMode
// 4) The type of a constant must be at least as accessible as the constant itself.
// 5) The type of a field must be at least as accessible as the field itself.
if
(
type
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
,
out
VariableDeclarationSyntax
variableDeclaration
)
&&
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
))
variableDeclaration
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
))
{
return
semanticModel
.
GetDeclaredSymbol
(
variableDeclaration
.
Variables
[
0
],
cancellationToken
).
DeclaredAccessibility
;
...
...
@@ -361,7 +361,7 @@ public static ISet<INamespaceSymbol> GetUsingNamespacesInScope(this SemanticMode
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
EqualsValueClause
)
&&
type
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclarator
)
&&
type
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
,
out
variableDeclaration
)
&&
type
.
Parent
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
))
variableDeclaration
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
))
{
return
semanticModel
.
GetDeclaredSymbol
(
variableDeclaration
.
Variables
[
0
],
cancellationToken
).
DeclaredAccessibility
;
...
...
@@ -420,7 +420,7 @@ public static ISet<INamespaceSymbol> GetUsingNamespacesInScope(this SemanticMode
// 8) The type of an event must be at least as accessible as the event itself.
if
(
type
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
,
out
variableDeclaration
)
&&
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
EventFieldDeclaration
))
variableDeclaration
.
IsParentKind
(
SyntaxKind
.
EventFieldDeclaration
))
{
var
symbol
=
semanticModel
.
GetDeclaredSymbol
(
variableDeclaration
.
Variables
[
0
],
cancellationToken
);
if
(
symbol
!=
null
)
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
浏览文件 @
8ae03859
...
...
@@ -2156,13 +2156,13 @@ private IEnumerable<TypeInferenceInfo> InferTypeInVariableComponentAssignment(Ex
foreach
(
var
arg
in
arguments
)
{
var
expr
=
arg
.
Expression
;
if
(
expr
.
IsKind
(
SyntaxKind
.
DeclarationExpression
))
if
(
expr
.
IsKind
(
SyntaxKind
.
DeclarationExpression
,
out
DeclarationExpressionSyntax
declExpr
))
{
AddTypeAndName
(
(
DeclarationExpressionSyntax
)
e
xpr
,
elementTypesBuilder
,
elementNamesBuilder
);
AddTypeAndName
(
declE
xpr
,
elementTypesBuilder
,
elementNamesBuilder
);
}
else
if
(
expr
.
IsKind
(
SyntaxKind
.
TupleExpression
))
else
if
(
expr
.
IsKind
(
SyntaxKind
.
TupleExpression
,
out
TupleExpressionSyntax
tupleExpr
))
{
AddTypeAndName
(
(
TupleExpressionSyntax
)
e
xpr
,
elementTypesBuilder
,
elementNamesBuilder
);
AddTypeAndName
(
tupleE
xpr
,
elementTypesBuilder
,
elementNamesBuilder
);
}
else
if
(
expr
is
IdentifierNameSyntax
name
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录