Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
73a80651
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,发现更多精彩内容 >>
提交
73a80651
编写于
3月 26, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unnecessary 'this' expressions
上级
5d72eb34
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
167 addition
and
167 deletion
+167
-167
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
...ressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
+1
-1
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
...ssionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
+1
-1
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
...rs/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
+5
-5
src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs
...achableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs
+1
-1
src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs
...xes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs
+1
-1
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs
...lineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs
+1
-1
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
...InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
+1
-1
src/Features/CSharp/Portable/Completion/KeywordRecommenders/AbstractSpecialTypePreselectingKeywordRecommender.cs
...ders/AbstractSpecialTypePreselectingKeywordRecommender.cs
+1
-1
src/Features/CSharp/Portable/Completion/KeywordRecommenders/AbstractSyntacticSingleKeywordRecommender.cs
...Recommenders/AbstractSyntacticSingleKeywordRecommender.cs
+5
-5
src/Features/CSharp/Portable/ConvertBetweenRegularAndVerbatimString/AbstractConvertBetweenRegularAndVerbatimStringCodeRefactoringProvider.cs
...BetweenRegularAndVerbatimStringCodeRefactoringProvider.cs
+2
-2
src/Features/CSharp/Portable/Debugging/BreakpointResolver.cs
src/Features/CSharp/Portable/Debugging/BreakpointResolver.cs
+1
-1
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.Analyzer.cs
.../Portable/ExtractMethod/CSharpMethodExtractor.Analyzer.cs
+4
-4
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.CallSiteContainerRewriter.cs
...xtractor.CSharpCodeGenerator.CallSiteContainerRewriter.cs
+19
-19
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
...dExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
+14
-14
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
...or.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
+5
-5
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
...actor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
+5
-5
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
...xtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
+41
-41
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
...es/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
+1
-1
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
...e/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
+5
-5
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs
...le/ExtractMethod/CSharpSelectionResult.StatementResult.cs
+7
-7
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs
...es/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs
+13
-13
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs
...CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs
+9
-9
src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs
...terizedMember/CSharpGenerateParameterizedMemberService.cs
+11
-11
src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
...CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
+1
-1
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
...Variable/CSharpIntroduceVariableService_IntroduceLocal.cs
+1
-1
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
...onalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
+2
-2
src/Features/CSharp/Portable/LanguageServices/CSharpSymbolDisplayService.SymbolDescriptionBuilder.cs
...es/CSharpSymbolDisplayService.SymbolDescriptionBuilder.cs
+6
-6
src/Features/CSharp/Portable/LanguageServices/CSharpSymbolDisplayService.cs
...p/Portable/LanguageServices/CSharpSymbolDisplayService.cs
+1
-1
src/Features/CSharp/Portable/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs
...seIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs
+1
-1
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
...hing/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
+1
-1
未找到文件。
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
浏览文件 @
73a80651
...
...
@@ -66,7 +66,7 @@ protected override IndexerDeclarationSyntax WithGenerateBody(SemanticModel seman
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
return
this
.
TryConvertToExpressionBodyForBaseProperty
(
return
TryConvertToExpressionBodyForBaseProperty
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
);
}
...
...
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
浏览文件 @
73a80651
...
...
@@ -66,7 +66,7 @@ protected override PropertyDeclarationSyntax WithGenerateBody(SemanticModel sema
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
return
this
.
TryConvertToExpressionBodyForBaseProperty
(
return
TryConvertToExpressionBodyForBaseProperty
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
);
}
...
...
src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
浏览文件 @
73a80651
...
...
@@ -80,7 +80,7 @@ public override Location GetDiagnosticLocation(SyntaxNode declaration)
=>
GetDiagnosticLocation
((
TDeclaration
)
declaration
);
protected
virtual
Location
GetDiagnosticLocation
(
TDeclaration
declaration
)
=>
this
.
GetBody
(
declaration
).
Statements
[
0
].
GetLocation
();
=>
GetBody
(
declaration
).
Statements
[
0
].
GetLocation
();
public
bool
CanOfferUseExpressionBody
(
OptionSet
optionSet
,
TDeclaration
declaration
,
bool
forAnalyzer
)
...
...
@@ -95,7 +95,7 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
// If the analyzer is disabled completely, the refactoring is enabled in both directions.
if
(
userPrefersExpressionBodies
==
forAnalyzer
||
(!
forAnalyzer
&&
analyzerDisabled
))
{
var
expressionBody
=
this
.
GetExpressionBody
(
declaration
);
var
expressionBody
=
GetExpressionBody
(
declaration
);
if
(
expressionBody
==
null
)
{
// They don't have an expression body. See if we could convert the block they
...
...
@@ -127,7 +127,7 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
SyntaxNode
declaration
,
ParseOptions
options
,
ExpressionBodyPreference
conversionPreference
,
out
ArrowExpressionClauseSyntax
expressionWhenOnSingleLine
,
out
SyntaxToken
semicolonWhenOnSingleLine
)
{
var
body
=
this
.
GetBody
(
declaration
);
var
body
=
GetBody
(
declaration
);
return
body
.
TryConvertToArrowExpressionBody
(
declaration
.
Kind
(),
options
,
conversionPreference
,
...
...
@@ -140,7 +140,7 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
if
(
this
.
TryConvertToExpressionBodyWorker
(
if
(
TryConvertToExpressionBodyWorker
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
))
{
...
...
@@ -167,7 +167,7 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
var
userPrefersBlockBodies
=
preference
==
ExpressionBodyPreference
.
Never
;
var
analyzerDisabled
=
currentOptionValue
.
Notification
.
Severity
==
ReportDiagnostic
.
Suppress
;
var
expressionBodyOpt
=
this
.
GetExpressionBody
(
declaration
);
var
expressionBodyOpt
=
GetExpressionBody
(
declaration
);
var
canOffer
=
expressionBodyOpt
?.
TryConvertToBlock
(
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
),
false
,
block
:
out
_
)
==
true
;
if
(!
canOffer
)
...
...
src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs
浏览文件 @
73a80651
...
...
@@ -110,7 +110,7 @@ private class MyCodeAction : CustomCodeActions.DocumentChangeAction
CodeActionPriority
priority
)
:
base
(
title
,
createChangedDocument
,
title
)
{
this
.
Priority
=
priority
;
Priority
=
priority
;
}
internal
override
CodeActionPriority
Priority
{
get
;
}
...
...
src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs
浏览文件 @
73a80651
...
...
@@ -115,7 +115,7 @@ public MyCodeAction(string title, Func<CancellationToken, Task<Document>> create
public
MyCodeAction
(
string
title
,
CodeActionPriority
priority
,
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
title
,
createChangedDocument
)
{
this
.
Priority
=
priority
;
Priority
=
priority
;
}
#endif
}
...
...
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs
浏览文件 @
73a80651
...
...
@@ -84,7 +84,7 @@ public override SyntaxNode VisitAnonymousObjectMemberDeclarator(AnonymousObjectM
// Should become:
// var a = new { x = 42; };
nameEquals
=
SyntaxFactory
.
NameEquals
(
identifier
);
expression
=
(
ExpressionSyntax
)
this
.
Visit
(
expression
);
expression
=
(
ExpressionSyntax
)
Visit
(
expression
);
return
node
.
Update
(
nameEquals
,
expression
).
WithAdditionalAnnotations
(
Simplifier
.
Annotation
,
Formatter
.
Annotation
);
}
...
...
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
浏览文件 @
73a80651
...
...
@@ -88,7 +88,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context
.
RegisterRefactoring
(
new
MyCodeAction
(
CSharpFeaturesResources
.
Inline_temporary_variable
,
c
=>
this
.
InlineTemporaryAsync
(
document
,
variableDeclarator
,
c
)),
c
=>
InlineTemporaryAsync
(
document
,
variableDeclarator
,
c
)),
variableDeclarator
.
Span
);
}
...
...
src/Features/CSharp/Portable/Completion/KeywordRecommenders/AbstractSpecialTypePreselectingKeywordRecommender.cs
浏览文件 @
73a80651
...
...
@@ -22,7 +22,7 @@ internal abstract class AbstractSpecialTypePreselectingKeywordRecommender : Abst
protected
override
bool
ShouldPreselect
(
CSharpSyntaxContext
context
,
CancellationToken
cancellationToken
)
{
return
context
.
InferredTypes
.
Any
(
t
=>
t
.
SpecialType
==
this
.
SpecialType
);
return
context
.
InferredTypes
.
Any
(
t
=>
t
.
SpecialType
==
SpecialType
);
}
}
}
src/Features/CSharp/Portable/Completion/KeywordRecommenders/AbstractSyntacticSingleKeywordRecommender.cs
浏览文件 @
73a80651
...
...
@@ -25,9 +25,9 @@ internal abstract partial class AbstractSyntacticSingleKeywordRecommender : IKey
bool
isValidInPreprocessorContext
=
false
,
bool
shouldFormatOnCommit
=
false
)
{
this
.
KeywordKind
=
keywordKind
;
KeywordKind
=
keywordKind
;
_isValidInPreprocessorContext
=
isValidInPreprocessorContext
;
this
.
ShouldFormatOnCommit
=
shouldFormatOnCommit
;
ShouldFormatOnCommit
=
shouldFormatOnCommit
;
}
protected
virtual
Task
<
bool
>
IsValidContextAsync
(
int
position
,
CSharpSyntaxContext
context
,
CancellationToken
cancellationToken
)
...
...
@@ -42,12 +42,12 @@ protected virtual Task<bool> IsValidContextAsync(int position, CSharpSyntaxConte
CSharpSyntaxContext
context
,
CancellationToken
cancellationToken
)
{
var
syntaxKind
=
await
this
.
RecommendKeywordAsync
(
position
,
context
,
cancellationToken
).
ConfigureAwait
(
false
);
var
syntaxKind
=
await
RecommendKeywordAsync
(
position
,
context
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
syntaxKind
.
HasValue
)
{
return
SpecializedCollections
.
SingletonEnumerable
(
new
RecommendedKeyword
(
SyntaxFacts
.
GetText
(
syntaxKind
.
Value
),
shouldFormatOnCommit
:
this
.
ShouldFormatOnCommit
,
shouldFormatOnCommit
:
ShouldFormatOnCommit
,
matchPriority
:
ShouldPreselect
(
context
,
cancellationToken
)
?
SymbolMatchPriority
.
Keyword
:
MatchPriority
.
Default
));
}
...
...
@@ -72,7 +72,7 @@ protected virtual Task<bool> IsValidContextAsync(int position, CSharpSyntaxConte
return
null
;
}
return
this
.
KeywordKind
;
return
KeywordKind
;
}
internal
TestAccessor
GetTestAccessor
()
...
...
src/Features/CSharp/Portable/ConvertBetweenRegularAndVerbatimString/AbstractConvertBetweenRegularAndVerbatimStringCodeRefactoringProvider.cs
浏览文件 @
73a80651
...
...
@@ -94,7 +94,7 @@ private Task<Document> ConvertToRegularStringAsync(Document document, TStringExp
protected
void
AddVerbatimStringText
(
IVirtualCharService
charService
,
StringBuilder
sb
,
SyntaxToken
stringToken
)
{
var
isInterpolation
=
this
.
IsInterpolation
;
var
isInterpolation
=
IsInterpolation
;
var
chars
=
charService
.
TryConvertToVirtualChars
(
stringToken
);
foreach
(
var
vc
in
chars
)
...
...
@@ -128,7 +128,7 @@ private static bool IsOpenOrCloseBrace(char ch)
protected
void
AddRegularStringText
(
IVirtualCharService
charService
,
StringBuilder
sb
,
SyntaxToken
stringToken
)
{
var
isInterpolation
=
this
.
IsInterpolation
;
var
isInterpolation
=
IsInterpolation
;
var
chars
=
charService
.
TryConvertToVirtualChars
(
stringToken
);
foreach
(
var
vc
in
chars
)
...
...
src/Features/CSharp/Portable/Debugging/BreakpointResolver.cs
浏览文件 @
73a80651
...
...
@@ -48,7 +48,7 @@ protected override bool HasMethodBody(IMethodSymbol method, CancellationToken ca
out
IList
<
NameAndArity
>
nameParts
,
out
int
?
parameterCount
)
{
var
text
=
this
.
Text
;
var
text
=
Text
;
Debug
.
Assert
(
text
!=
null
);
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.Analyzer.cs
浏览文件 @
73a80651
...
...
@@ -92,7 +92,7 @@ protected override int GetIndexOfVariableInfoToUseAsReturnValue(IList<VariableIn
protected
override
ITypeSymbol
GetRangeVariableType
(
SemanticModel
model
,
IRangeVariableSymbol
symbol
)
{
var
info
=
model
.
GetSpeculativeTypeInfo
(
this
.
SelectionResult
.
FinalSpan
.
Start
,
SyntaxFactory
.
ParseName
(
symbol
.
Name
),
SpeculativeBindingOption
.
BindAsExpression
);
var
info
=
model
.
GetSpeculativeTypeInfo
(
SelectionResult
.
FinalSpan
.
Start
,
SyntaxFactory
.
ParseName
(
symbol
.
Name
),
SpeculativeBindingOption
.
BindAsExpression
);
if
(
Microsoft
.
CodeAnalysis
.
Shared
.
Extensions
.
ISymbolExtensions
.
IsErrorType
(
info
.
Type
))
{
return
null
;
...
...
@@ -105,7 +105,7 @@ protected override ITypeSymbol GetRangeVariableType(SemanticModel model, IRangeV
protected
override
Tuple
<
SyntaxNode
,
SyntaxNode
>
GetFlowAnalysisNodeRange
()
{
var
csharpSelectionResult
=
this
.
SelectionResult
as
CSharpSelectionResult
;
var
csharpSelectionResult
=
SelectionResult
as
CSharpSelectionResult
;
var
first
=
csharpSelectionResult
.
GetFirstStatement
();
var
last
=
csharpSelectionResult
.
GetLastStatement
();
...
...
@@ -130,13 +130,13 @@ protected override bool ContainsReturnStatementInSelectedCode(IEnumerable<Syntax
protected
override
bool
ReadOnlyFieldAllowed
()
{
var
scope
=
this
.
SelectionResult
.
GetContainingScopeOf
<
ConstructorDeclarationSyntax
>();
var
scope
=
SelectionResult
.
GetContainingScopeOf
<
ConstructorDeclarationSyntax
>();
return
scope
==
null
;
}
protected
override
ITypeSymbol
GetSymbolType
(
SemanticModel
semanticModel
,
ISymbol
symbol
)
{
var
selectionOperation
=
semanticModel
.
GetOperation
(
this
.
SelectionResult
.
GetContainingScope
());
var
selectionOperation
=
semanticModel
.
GetOperation
(
SelectionResult
.
GetContainingScope
());
switch
(
symbol
)
{
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.CallSiteContainerRewriter.cs
浏览文件 @
73a80651
...
...
@@ -125,7 +125,7 @@ public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatem
// for every kind of extract methods
public
override
SyntaxNode
VisitBlock
(
BlockSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
// make sure we visit nodes under the block
return
base
.
VisitBlock
(
node
);
...
...
@@ -136,7 +136,7 @@ public override SyntaxNode VisitBlock(BlockSyntax node)
public
override
SyntaxNode
VisitSwitchSection
(
SwitchSectionSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
// make sure we visit nodes under the switch section
return
base
.
VisitSwitchSection
(
node
);
...
...
@@ -148,7 +148,7 @@ public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node)
// only for single statement or expression
public
override
SyntaxNode
VisitLabeledStatement
(
LabeledStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitLabeledStatement
(
node
);
}
...
...
@@ -158,7 +158,7 @@ public override SyntaxNode VisitLabeledStatement(LabeledStatementSyntax node)
public
override
SyntaxNode
VisitElseClause
(
ElseClauseSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitElseClause
(
node
);
}
...
...
@@ -168,7 +168,7 @@ public override SyntaxNode VisitElseClause(ElseClauseSyntax node)
public
override
SyntaxNode
VisitIfStatement
(
IfStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitIfStatement
(
node
);
}
...
...
@@ -180,7 +180,7 @@ public override SyntaxNode VisitIfStatement(IfStatementSyntax node)
public
override
SyntaxNode
VisitLockStatement
(
LockStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitLockStatement
(
node
);
}
...
...
@@ -191,7 +191,7 @@ public override SyntaxNode VisitLockStatement(LockStatementSyntax node)
public
override
SyntaxNode
VisitFixedStatement
(
FixedStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitFixedStatement
(
node
);
}
...
...
@@ -202,7 +202,7 @@ public override SyntaxNode VisitFixedStatement(FixedStatementSyntax node)
public
override
SyntaxNode
VisitUsingStatement
(
UsingStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitUsingStatement
(
node
);
}
...
...
@@ -214,7 +214,7 @@ public override SyntaxNode VisitUsingStatement(UsingStatementSyntax node)
public
override
SyntaxNode
VisitForEachStatement
(
ForEachStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitForEachStatement
(
node
);
}
...
...
@@ -225,7 +225,7 @@ public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
public
override
SyntaxNode
VisitForEachVariableStatement
(
ForEachVariableStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitForEachVariableStatement
(
node
);
}
...
...
@@ -236,7 +236,7 @@ public override SyntaxNode VisitForEachVariableStatement(ForEachVariableStatemen
public
override
SyntaxNode
VisitForStatement
(
ForStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitForStatement
(
node
);
}
...
...
@@ -250,7 +250,7 @@ public override SyntaxNode VisitForStatement(ForStatementSyntax node)
public
override
SyntaxNode
VisitDoStatement
(
DoStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitDoStatement
(
node
);
}
...
...
@@ -261,7 +261,7 @@ public override SyntaxNode VisitDoStatement(DoStatementSyntax node)
public
override
SyntaxNode
VisitWhileStatement
(
WhileStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitWhileStatement
(
node
);
}
...
...
@@ -349,7 +349,7 @@ private SyntaxList<MemberDeclarationSyntax> ReplaceMembers(SyntaxList<MemberDecl
public
override
SyntaxNode
VisitGlobalStatement
(
GlobalStatementSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitGlobalStatement
(
node
);
}
...
...
@@ -359,7 +359,7 @@ public override SyntaxNode VisitGlobalStatement(GlobalStatementSyntax node)
public
override
SyntaxNode
VisitConstructorDeclaration
(
ConstructorDeclarationSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitConstructorDeclaration
(
node
);
}
...
...
@@ -370,7 +370,7 @@ public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyn
public
override
SyntaxNode
VisitClassDeclaration
(
ClassDeclarationSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitClassDeclaration
(
node
);
}
...
...
@@ -381,7 +381,7 @@ public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
public
override
SyntaxNode
VisitStructDeclaration
(
StructDeclarationSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitStructDeclaration
(
node
);
}
...
...
@@ -392,7 +392,7 @@ public override SyntaxNode VisitStructDeclaration(StructDeclarationSyntax node)
public
override
SyntaxNode
VisitAccessorList
(
AccessorListSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
)
{
return
base
.
VisitAccessorList
(
node
);
}
...
...
@@ -403,7 +403,7 @@ public override SyntaxNode VisitAccessorList(AccessorListSyntax node)
public
override
SyntaxNode
VisitCompilationUnit
(
CompilationUnitSyntax
node
)
{
if
(
node
!=
this
.
ContainerOfStatementsOrFieldToReplace
.
Parent
)
if
(
node
!=
ContainerOfStatementsOrFieldToReplace
.
Parent
)
{
// make sure we visit nodes under the block
return
base
.
VisitCompilationUnit
(
node
);
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
浏览文件 @
73a80651
...
...
@@ -44,11 +44,11 @@ protected override SyntaxToken CreateMethodName()
{
var
methodName
=
GenerateMethodNameFromUserPreference
();
var
containingScope
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
var
containingScope
=
CSharpSelectionResult
.
GetContainingScope
();
methodName
=
GetMethodNameBasedOnExpression
(
methodName
,
containingScope
);
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
var
nameGenerator
=
new
UniqueNameGenerator
(
semanticModel
);
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
containingScope
,
methodName
));
}
...
...
@@ -99,13 +99,13 @@ private string GetMethodNameBasedOnExpression(string methodName, SyntaxNode expr
protected
override
IEnumerable
<
StatementSyntax
>
GetInitialStatementsForMethodDefinitions
()
{
Contract
.
ThrowIfFalse
(
IsExtractMethodOnExpression
(
this
.
CSharpSelectionResult
));
Contract
.
ThrowIfFalse
(
IsExtractMethodOnExpression
(
CSharpSelectionResult
));
ExpressionSyntax
expression
=
null
;
// special case for array initializer
var
returnType
=
this
.
AnalyzerResult
.
ReturnType
;
var
containingScope
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
var
returnType
=
AnalyzerResult
.
ReturnType
;
var
containingScope
=
CSharpSelectionResult
.
GetContainingScope
();
if
(
returnType
.
TypeKind
==
TypeKind
.
Array
&&
containingScope
is
InitializerExpressionSyntax
)
{
...
...
@@ -118,7 +118,7 @@ protected override IEnumerable<StatementSyntax> GetInitialStatementsForMethodDef
expression
=
containingScope
as
ExpressionSyntax
;
}
if
(
this
.
AnalyzerResult
.
HasReturnType
)
if
(
AnalyzerResult
.
HasReturnType
)
{
return
SpecializedCollections
.
SingletonEnumerable
<
StatementSyntax
>(
SyntaxFactory
.
ReturnStatement
(
...
...
@@ -134,7 +134,7 @@ protected override IEnumerable<StatementSyntax> GetInitialStatementsForMethodDef
private
ExpressionSyntax
WrapInCheckedExpressionIfNeeded
(
ExpressionSyntax
expression
)
{
var
kind
=
this
.
CSharpSelectionResult
.
UnderCheckedExpressionContext
();
var
kind
=
CSharpSelectionResult
.
UnderCheckedExpressionContext
();
if
(
kind
==
SyntaxKind
.
None
)
{
return
expression
;
...
...
@@ -158,7 +158,7 @@ protected override SyntaxNode GetOutermostCallSiteContainerToProcess(Cancellatio
private
SyntaxNode
GetCallSiteContainerFromExpression
()
{
var
container
=
this
.
CSharpSelectionResult
.
GetInnermostStatementContainer
();
var
container
=
CSharpSelectionResult
.
GetInnermostStatementContainer
();
Contract
.
ThrowIfNull
(
container
);
Contract
.
ThrowIfFalse
(
container
.
IsStatementContainerNode
()
||
...
...
@@ -171,22 +171,22 @@ private SyntaxNode GetCallSiteContainerFromExpression()
protected
override
SyntaxNode
GetFirstStatementOrInitializerSelectedAtCallSite
()
{
var
scope
=
(
SyntaxNode
)
this
.
CSharpSelectionResult
.
GetContainingScopeOf
<
StatementSyntax
>();
var
scope
=
(
SyntaxNode
)
CSharpSelectionResult
.
GetContainingScopeOf
<
StatementSyntax
>();
if
(
scope
==
null
)
{
scope
=
this
.
CSharpSelectionResult
.
GetContainingScopeOf
<
FieldDeclarationSyntax
>();
scope
=
CSharpSelectionResult
.
GetContainingScopeOf
<
FieldDeclarationSyntax
>();
}
if
(
scope
==
null
)
{
scope
=
this
.
CSharpSelectionResult
.
GetContainingScopeOf
<
ConstructorInitializerSyntax
>();
scope
=
CSharpSelectionResult
.
GetContainingScopeOf
<
ConstructorInitializerSyntax
>();
}
if
(
scope
==
null
)
{
// This is similar to FieldDeclaration case but we only want to do this
// if the member has an expression body.
scope
=
this
.
CSharpSelectionResult
.
GetContainingScopeOf
<
ArrowExpressionClauseSyntax
>().
Parent
;
scope
=
CSharpSelectionResult
.
GetContainingScopeOf
<
ArrowExpressionClauseSyntax
>().
Parent
;
}
return
scope
;
...
...
@@ -202,7 +202,7 @@ protected override SyntaxNode GetLastStatementOrInitializerSelectedAtCallSite()
var
callSignature
=
CreateCallSignature
().
WithAdditionalAnnotations
(
callSiteAnnotation
);
var
invocation
=
callSignature
.
IsKind
(
SyntaxKind
.
AwaitExpression
,
out
AwaitExpressionSyntax
awaitExpr
)
?
awaitExpr
.
Expression
:
callSignature
;
var
sourceNode
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
var
sourceNode
=
CSharpSelectionResult
.
GetContainingScope
();
Contract
.
ThrowIfTrue
(
sourceNode
.
Parent
is
MemberAccessExpressionSyntax
&&
((
MemberAccessExpressionSyntax
)
sourceNode
.
Parent
).
Name
==
sourceNode
,
"invalid scope. given scope is not an expression"
);
...
...
@@ -211,7 +211,7 @@ protected override SyntaxNode GetLastStatementOrInitializerSelectedAtCallSite()
// code, we make the enclosing statement semantically explicit. This ends up being a little
// bit more work because we need to annotate the sourceNode so that we can get back to it
// after rewriting the enclosing statement.
var
updatedDocument
=
this
.
SemanticDocument
.
Document
;
var
updatedDocument
=
SemanticDocument
.
Document
;
var
sourceNodeAnnotation
=
new
SyntaxAnnotation
();
var
enclosingStatementAnnotation
=
new
SyntaxAnnotation
();
var
newEnclosingStatement
=
enclosingStatement
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
浏览文件 @
73a80651
...
...
@@ -50,8 +50,8 @@ public static bool IsExtractMethodOnMultipleStatements(SelectionResult code)
protected
override
IEnumerable
<
StatementSyntax
>
GetInitialStatementsForMethodDefinitions
()
{
var
firstSeen
=
false
;
var
firstStatementUnderContainer
=
this
.
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
var
lastStatementUnderContainer
=
this
.
CSharpSelectionResult
.
GetLastStatementUnderContainer
();
var
firstStatementUnderContainer
=
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
var
lastStatementUnderContainer
=
CSharpSelectionResult
.
GetLastStatementUnderContainer
();
var
list
=
new
List
<
StatementSyntax
>();
foreach
(
var
statement
in
GetStatementsFromContainer
(
firstStatementUnderContainer
.
Parent
))
...
...
@@ -89,7 +89,7 @@ protected override SyntaxNode GetOutermostCallSiteContainerToProcess(Cancellatio
}
else
{
var
firstStatement
=
this
.
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
var
firstStatement
=
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
return
firstStatement
.
Parent
;
}
}
...
...
@@ -109,12 +109,12 @@ private SyntaxList<StatementSyntax> GetStatementsFromContainer(SyntaxNode node)
protected
override
SyntaxNode
GetFirstStatementOrInitializerSelectedAtCallSite
()
{
return
this
.
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
return
CSharpSelectionResult
.
GetFirstStatementUnderContainer
();
}
protected
override
SyntaxNode
GetLastStatementOrInitializerSelectedAtCallSite
()
{
return
this
.
CSharpSelectionResult
.
GetLastStatementUnderContainer
();
return
CSharpSelectionResult
.
GetLastStatementUnderContainer
();
}
protected
override
Task
<
SyntaxNode
>
GetStatementOrInitializerContainingInvocationToExtractedMethodAsync
(
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
浏览文件 @
73a80651
...
...
@@ -41,9 +41,9 @@ public static bool IsExtractMethodOnSingleStatement(SelectionResult code)
protected
override
IEnumerable
<
StatementSyntax
>
GetInitialStatementsForMethodDefinitions
()
{
Contract
.
ThrowIfFalse
(
IsExtractMethodOnSingleStatement
(
this
.
CSharpSelectionResult
));
Contract
.
ThrowIfFalse
(
IsExtractMethodOnSingleStatement
(
CSharpSelectionResult
));
return
SpecializedCollections
.
SingletonEnumerable
<
StatementSyntax
>(
this
.
CSharpSelectionResult
.
GetFirstStatement
());
return
SpecializedCollections
.
SingletonEnumerable
<
StatementSyntax
>(
CSharpSelectionResult
.
GetFirstStatement
());
}
protected
override
SyntaxNode
GetOutermostCallSiteContainerToProcess
(
CancellationToken
cancellationToken
)
...
...
@@ -55,21 +55,21 @@ protected override SyntaxNode GetOutermostCallSiteContainerToProcess(Cancellatio
}
else
{
var
firstStatement
=
this
.
CSharpSelectionResult
.
GetFirstStatement
();
var
firstStatement
=
CSharpSelectionResult
.
GetFirstStatement
();
return
firstStatement
.
Parent
;
}
}
protected
override
SyntaxNode
GetFirstStatementOrInitializerSelectedAtCallSite
()
{
return
this
.
CSharpSelectionResult
.
GetFirstStatement
();
return
CSharpSelectionResult
.
GetFirstStatement
();
}
protected
override
SyntaxNode
GetLastStatementOrInitializerSelectedAtCallSite
()
{
// it is a single statement case. either first statement is same as last statement or
// last statement belongs (embedded statement) to the first statement.
return
this
.
CSharpSelectionResult
.
GetFirstStatement
();
return
CSharpSelectionResult
.
GetFirstStatement
();
}
protected
override
Task
<
SyntaxNode
>
GetStatementOrInitializerContainingInvocationToExtractedMethodAsync
(
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
浏览文件 @
73a80651
...
...
@@ -81,20 +81,20 @@ private abstract partial class CSharpCodeGenerator : CodeGenerator<StatementSynt
bool
localFunction
)
:
base
(
insertionPoint
,
selectionResult
,
analyzerResult
,
options
,
localFunction
)
{
Contract
.
ThrowIfFalse
(
this
.
SemanticDocument
==
selectionResult
.
SemanticDocument
);
Contract
.
ThrowIfFalse
(
SemanticDocument
==
selectionResult
.
SemanticDocument
);
var
nameToken
=
CreateMethodName
();
_methodName
=
nameToken
.
WithAdditionalAnnotations
(
this
.
MethodNameAnnotation
);
_methodName
=
nameToken
.
WithAdditionalAnnotations
(
MethodNameAnnotation
);
}
private
CSharpSelectionResult
CSharpSelectionResult
{
get
{
return
(
CSharpSelectionResult
)
this
.
SelectionResult
;
}
get
{
return
(
CSharpSelectionResult
)
SelectionResult
;
}
}
protected
override
SyntaxNode
GetPreviousMember
(
SemanticDocument
document
)
{
var
node
=
this
.
InsertionPoint
.
With
(
document
).
GetContext
();
var
node
=
InsertionPoint
.
With
(
document
).
GetContext
();
return
(
node
.
Parent
is
GlobalStatementSyntax
)
?
node
.
Parent
:
node
;
}
...
...
@@ -106,7 +106,7 @@ protected override OperationStatus<IMethodSymbol> GenerateMethodDefinition(bool
attributes
:
ImmutableArray
<
AttributeData
>.
Empty
,
accessibility
:
Accessibility
.
Private
,
modifiers
:
CreateMethodModifiers
(),
returnType
:
this
.
AnalyzerResult
.
ReturnType
,
returnType
:
AnalyzerResult
.
ReturnType
,
refKind
:
RefKind
.
None
,
explicitInterfaceImplementations
:
default
,
name
:
_methodName
.
ToString
(),
...
...
@@ -116,15 +116,15 @@ protected override OperationStatus<IMethodSymbol> GenerateMethodDefinition(bool
methodKind
:
localFunction
?
MethodKind
.
LocalFunction
:
MethodKind
.
Ordinary
);
return
result
.
With
(
this
.
MethodDefinitionAnnotation
.
AddAnnotationToSymbol
(
MethodDefinitionAnnotation
.
AddAnnotationToSymbol
(
Formatter
.
Annotation
.
AddAnnotationToSymbol
(
methodSymbol
)));
}
protected
override
async
Task
<
SyntaxNode
>
GenerateBodyForCallSiteContainerAsync
(
CancellationToken
cancellationToken
)
{
var
container
=
this
.
GetOutermostCallSiteContainerToProcess
(
cancellationToken
);
var
container
=
GetOutermostCallSiteContainerToProcess
(
cancellationToken
);
var
variableMapToRemove
=
CreateVariableDeclarationToRemoveMap
(
this
.
AnalyzerResult
.
GetVariablesToMoveIntoMethodDefinition
(
cancellationToken
),
cancellationToken
);
AnalyzerResult
.
GetVariablesToMoveIntoMethodDefinition
(
cancellationToken
),
cancellationToken
);
var
firstStatementToRemove
=
GetFirstStatementOrInitializerSelectedAtCallSite
();
var
lastStatementToRemove
=
GetLastStatementOrInitializerSelectedAtCallSite
();
...
...
@@ -145,7 +145,7 @@ protected override async Task<SyntaxNode> GenerateBodyForCallSiteContainerAsync(
private
async
Task
<
IEnumerable
<
SyntaxNode
>>
CreateStatementsOrInitializerToInsertAtCallSiteAsync
(
CancellationToken
cancellationToken
)
{
var
selectedNode
=
this
.
GetFirstStatementOrInitializerSelectedAtCallSite
();
var
selectedNode
=
GetFirstStatementOrInitializerSelectedAtCallSite
();
// field initializer, constructor initializer, expression bodied member case
if
(
selectedNode
is
ConstructorInitializerSyntax
||
...
...
@@ -153,13 +153,13 @@ private async Task<IEnumerable<SyntaxNode>> CreateStatementsOrInitializerToInser
IsExpressionBodiedMember
(
selectedNode
)
||
IsExpressionBodiedAccessor
(
selectedNode
))
{
var
statement
=
await
GetStatementOrInitializerContainingInvocationToExtractedMethodAsync
(
this
.
CallSiteAnnotation
,
cancellationToken
).
ConfigureAwait
(
false
);
var
statement
=
await
GetStatementOrInitializerContainingInvocationToExtractedMethodAsync
(
CallSiteAnnotation
,
cancellationToken
).
ConfigureAwait
(
false
);
return
SpecializedCollections
.
SingletonEnumerable
(
statement
);
}
// regular case
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
context
=
this
.
InsertionPoint
.
GetContext
();
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
var
context
=
InsertionPoint
.
GetContext
();
var
postProcessor
=
new
PostProcessor
(
semanticModel
,
context
.
SpanStart
);
var
statements
=
SpecializedCollections
.
EmptyEnumerable
<
StatementSyntax
>();
...
...
@@ -180,18 +180,18 @@ private bool IsExpressionBodiedAccessor(SyntaxNode node)
private
SimpleNameSyntax
CreateMethodNameForInvocation
()
{
return
this
.
AnalyzerResult
.
MethodTypeParametersInDeclaration
.
Count
==
0
return
AnalyzerResult
.
MethodTypeParametersInDeclaration
.
Count
==
0
?
(
SimpleNameSyntax
)
SyntaxFactory
.
IdentifierName
(
_methodName
)
:
SyntaxFactory
.
GenericName
(
_methodName
,
SyntaxFactory
.
TypeArgumentList
(
CreateMethodCallTypeVariables
()));
}
private
SeparatedSyntaxList
<
TypeSyntax
>
CreateMethodCallTypeVariables
()
{
Contract
.
ThrowIfTrue
(
this
.
AnalyzerResult
.
MethodTypeParametersInDeclaration
.
Count
==
0
);
Contract
.
ThrowIfTrue
(
AnalyzerResult
.
MethodTypeParametersInDeclaration
.
Count
==
0
);
// propagate any type variable used in extracted code
var
typeVariables
=
new
List
<
TypeSyntax
>();
foreach
(
var
methodTypeParameter
in
this
.
AnalyzerResult
.
MethodTypeParametersInDeclaration
)
foreach
(
var
methodTypeParameter
in
AnalyzerResult
.
MethodTypeParametersInDeclaration
)
{
typeVariables
.
Add
(
SyntaxFactory
.
ParseTypeName
(
methodTypeParameter
.
Name
));
}
...
...
@@ -207,7 +207,7 @@ protected SyntaxNode GetCallSiteContainerFromOutermostMoveInVariable(Cancellatio
return
null
;
}
var
idToken
=
outmostVariable
.
GetIdentifierTokenAtDeclaration
(
this
.
SemanticDocument
);
var
idToken
=
outmostVariable
.
GetIdentifierTokenAtDeclaration
(
SemanticDocument
);
var
declStatement
=
idToken
.
GetAncestor
<
LocalDeclarationStatementSyntax
>();
Contract
.
ThrowIfNull
(
declStatement
);
Contract
.
ThrowIfFalse
(
declStatement
.
Parent
.
IsStatementContainerNode
());
...
...
@@ -217,15 +217,15 @@ protected SyntaxNode GetCallSiteContainerFromOutermostMoveInVariable(Cancellatio
private
DeclarationModifiers
CreateMethodModifiers
()
{
var
isUnsafe
=
this
.
CSharpSelectionResult
.
ShouldPutUnsafeModifier
();
var
isAsync
=
this
.
CSharpSelectionResult
.
ShouldPutAsyncModifier
();
var
isStatic
=
!
this
.
AnalyzerResult
.
UseInstanceMember
;
var
isReadOnly
=
this
.
AnalyzerResult
.
ShouldBeReadOnly
;
var
isUnsafe
=
CSharpSelectionResult
.
ShouldPutUnsafeModifier
();
var
isAsync
=
CSharpSelectionResult
.
ShouldPutAsyncModifier
();
var
isStatic
=
!
AnalyzerResult
.
UseInstanceMember
;
var
isReadOnly
=
AnalyzerResult
.
ShouldBeReadOnly
;
// Static local functions are only supported in C# 8.0 and later
var
languageVersion
=
((
CSharpParseOptions
)
this
.
SemanticDocument
.
SyntaxTree
.
Options
).
LanguageVersion
;
var
languageVersion
=
((
CSharpParseOptions
)
SemanticDocument
.
SyntaxTree
.
Options
).
LanguageVersion
;
if
(
LocalFunction
&&
(!
this
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferStaticLocalFunction
).
Value
||
languageVersion
<
LanguageVersion
.
CSharp8
))
if
(
LocalFunction
&&
(!
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferStaticLocalFunction
).
Value
||
languageVersion
<
LanguageVersion
.
CSharp8
))
{
isStatic
=
false
;
}
...
...
@@ -261,7 +261,7 @@ private OperationStatus<ImmutableArray<SyntaxNode>> CreateMethodBody(Cancellatio
private
IEnumerable
<
StatementSyntax
>
WrapInCheckStatementIfNeeded
(
IEnumerable
<
StatementSyntax
>
statements
)
{
var
kind
=
this
.
CSharpSelectionResult
.
UnderCheckedStatementContext
();
var
kind
=
CSharpSelectionResult
.
UnderCheckedStatementContext
();
if
(
kind
==
SyntaxKind
.
None
)
{
return
statements
;
...
...
@@ -282,8 +282,8 @@ private IEnumerable<StatementSyntax> WrapInCheckStatementIfNeeded(IEnumerable<St
private
IEnumerable
<
StatementSyntax
>
CleanupCode
(
IEnumerable
<
StatementSyntax
>
statements
)
{
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
context
=
this
.
InsertionPoint
.
GetContext
();
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
var
context
=
InsertionPoint
.
GetContext
();
var
postProcessor
=
new
PostProcessor
(
semanticModel
,
context
.
SpanStart
);
statements
=
postProcessor
.
RemoveRedundantBlock
(
statements
);
...
...
@@ -333,7 +333,7 @@ private OperationStatus CheckActiveStatements(IEnumerable<StatementSyntax> state
IEnumerable
<
StatementSyntax
>
statements
,
CancellationToken
cancellationToken
)
{
var
variableToRemoveMap
=
CreateVariableDeclarationToRemoveMap
(
this
.
AnalyzerResult
.
GetVariablesToMoveOutToCallSiteOrDelete
(
cancellationToken
),
cancellationToken
);
AnalyzerResult
.
GetVariablesToMoveOutToCallSiteOrDelete
(
cancellationToken
),
cancellationToken
);
statements
=
statements
.
Select
(
s
=>
FixDeclarationExpressionsAndDeclarationPatterns
(
s
,
variableToRemoveMap
));
...
...
@@ -521,8 +521,8 @@ private static SyntaxToken ApplyTriviaFromDeclarationToAssignmentIdentifier(Loca
IEnumerable
<
StatementSyntax
>
statements
,
CancellationToken
cancellationToken
)
{
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
context
=
this
.
InsertionPoint
.
GetContext
();
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
var
context
=
InsertionPoint
.
GetContext
();
var
postProcessor
=
new
PostProcessor
(
semanticModel
,
context
.
SpanStart
);
var
declStatements
=
CreateDeclarationStatements
(
AnalyzerResult
.
GetVariablesToSplitOrMoveIntoMethodDefinition
(
cancellationToken
),
cancellationToken
);
...
...
@@ -541,7 +541,7 @@ private ExpressionSyntax CreateAssignmentExpression(SyntaxToken identifier, Expr
protected
override
bool
LastStatementOrHasReturnStatementInReturnableConstruct
()
{
var
lastStatement
=
this
.
GetLastStatementOrInitializerSelectedAtCallSite
();
var
lastStatement
=
GetLastStatementOrInitializerSelectedAtCallSite
();
var
container
=
lastStatement
.
GetAncestorsOrThis
<
SyntaxNode
>().
FirstOrDefault
(
n
=>
n
.
IsReturnableConstruct
());
if
(
container
==
null
)
{
...
...
@@ -584,7 +584,7 @@ protected override ExpressionSyntax CreateCallSignature()
var
methodName
=
CreateMethodNameForInvocation
().
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
var
arguments
=
new
List
<
ArgumentSyntax
>();
foreach
(
var
argument
in
this
.
AnalyzerResult
.
MethodParameters
)
foreach
(
var
argument
in
AnalyzerResult
.
MethodParameters
)
{
var
modifier
=
GetParameterRefSyntaxKind
(
argument
.
ParameterModifier
);
var
refOrOut
=
modifier
==
SyntaxKind
.
None
?
default
:
SyntaxFactory
.
Token
(
modifier
);
...
...
@@ -595,15 +595,15 @@ protected override ExpressionSyntax CreateCallSignature()
var
invocation
=
SyntaxFactory
.
InvocationExpression
(
methodName
,
SyntaxFactory
.
ArgumentList
(
SyntaxFactory
.
SeparatedList
(
arguments
)));
var
shouldPutAsyncModifier
=
this
.
CSharpSelectionResult
.
ShouldPutAsyncModifier
();
var
shouldPutAsyncModifier
=
CSharpSelectionResult
.
ShouldPutAsyncModifier
();
if
(!
shouldPutAsyncModifier
)
{
return
invocation
;
}
if
(
this
.
CSharpSelectionResult
.
ShouldCallConfigureAwaitFalse
())
if
(
CSharpSelectionResult
.
ShouldCallConfigureAwaitFalse
())
{
if
(
this
.
AnalyzerResult
.
ReturnType
.
GetMembers
().
Any
(
x
=>
x
is
IMethodSymbol
if
(
AnalyzerResult
.
ReturnType
.
GetMembers
().
Any
(
x
=>
x
is
IMethodSymbol
{
Name
:
nameof
(
Task
.
ConfigureAwait
),
Parameters
:
{
Length
:
1
}
parameters
...
...
@@ -632,7 +632,7 @@ protected override StatementSyntax CreateAssignmentExpressionStatement(SyntaxTok
ExpressionSyntax
initialValue
,
CancellationToken
cancellationToken
)
{
var
type
=
variable
.
GetVariableType
(
this
.
SemanticDocument
);
var
type
=
variable
.
GetVariableType
(
SemanticDocument
);
var
typeNode
=
type
.
GenerateTypeSyntax
();
var
equalsValueClause
=
initialValue
==
null
?
null
:
SyntaxFactory
.
EqualsValueClause
(
value
:
initialValue
);
...
...
@@ -650,7 +650,7 @@ protected override async Task<GeneratedCode> CreateGeneratedCodeAsync(OperationS
// here, we explicitly insert newline at the end of "{" of auto generated method decl so that anchor knows how to find out
// indentation of inserted statements (from users code) with user code style preserved
var
root
=
newDocument
.
Root
;
var
methodDefinition
=
root
.
GetAnnotatedNodes
<
SyntaxNode
>(
this
.
MethodDefinitionAnnotation
).
First
();
var
methodDefinition
=
root
.
GetAnnotatedNodes
<
SyntaxNode
>(
MethodDefinitionAnnotation
).
First
();
SyntaxNode
newMethodDefinition
=
methodDefinition
switch
{
...
...
@@ -698,9 +698,9 @@ protected StatementSyntax GetStatementContainingInvocationToExtractedMethodWorke
{
var
callSignature
=
CreateCallSignature
();
if
(
this
.
AnalyzerResult
.
HasReturnType
)
if
(
AnalyzerResult
.
HasReturnType
)
{
Contract
.
ThrowIfTrue
(
this
.
AnalyzerResult
.
HasVariableToUseAsReturnValue
);
Contract
.
ThrowIfTrue
(
AnalyzerResult
.
HasVariableToUseAsReturnValue
);
return
SyntaxFactory
.
ReturnStatement
(
callSignature
);
}
...
...
@@ -799,14 +799,14 @@ static bool ReturnOperationBelongsToMethod(SyntaxNode returnOperationSyntax, Syn
protected
SyntaxToken
GenerateMethodNameForStatementGenerators
()
{
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
var
nameGenerator
=
new
UniqueNameGenerator
(
semanticModel
);
var
scope
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
var
scope
=
CSharpSelectionResult
.
GetContainingScope
();
// If extracting a local function, we want to ensure all local variables are considered when generating a unique name.
if
(
LocalFunction
)
{
scope
=
this
.
CSharpSelectionResult
.
GetFirstTokenInSelection
().
Parent
;
scope
=
CSharpSelectionResult
.
GetFirstTokenInSelection
().
Parent
;
}
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
scope
,
GenerateMethodNameFromUserPreference
()));
...
...
@@ -821,7 +821,7 @@ protected string GenerateMethodNameFromUserPreference()
}
// For local functions, pascal case and camel case should be the most common and therefore we only consider those cases.
var
namingPreferences
=
this
.
Options
.
GetOption
(
NamingStyleOptions
.
NamingPreferences
,
LanguageNames
.
CSharp
);
var
namingPreferences
=
Options
.
GetOption
(
NamingStyleOptions
.
NamingPreferences
,
LanguageNames
.
CSharp
);
var
localFunctionPreferences
=
namingPreferences
.
SymbolSpecifications
.
Where
(
symbol
=>
symbol
.
AppliesTo
(
new
SymbolKindOrTypeKind
(
MethodKind
.
LocalFunction
),
CreateMethodModifiers
(),
null
));
var
namingRules
=
namingPreferences
.
Rules
.
NamingRules
;
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
浏览文件 @
73a80651
...
...
@@ -64,7 +64,7 @@ protected override async Task<InsertionPoint> GetInsertionPointAsync(SemanticDoc
if
(
memberNode
is
GlobalStatementSyntax
globalStatement
)
{
// check whether we are extracting whole global statement out
if
(
this
.
OriginalSelectionResult
.
FinalSpan
.
Contains
(
memberNode
.
Span
))
if
(
OriginalSelectionResult
.
FinalSpan
.
Contains
(
memberNode
.
Span
))
{
return
await
InsertionPoint
.
CreateAsync
(
document
,
globalStatement
.
Parent
,
cancellationToken
).
ConfigureAwait
(
false
);
}
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
浏览文件 @
73a80651
...
...
@@ -40,11 +40,11 @@ public override bool ContainingScopeHasAsyncKeyword()
public
override
SyntaxNode
?
GetContainingScope
()
{
Contract
.
ThrowIfNull
(
this
.
SemanticDocument
);
Contract
.
ThrowIfFalse
(
this
.
SelectionInExpression
);
Contract
.
ThrowIfNull
(
SemanticDocument
);
Contract
.
ThrowIfFalse
(
SelectionInExpression
);
var
firstToken
=
this
.
GetFirstTokenInSelection
();
var
lastToken
=
this
.
GetLastTokenInSelection
();
var
firstToken
=
GetFirstTokenInSelection
();
var
lastToken
=
GetLastTokenInSelection
();
return
firstToken
.
GetCommonRoot
(
lastToken
).
GetAncestorOrThis
<
ExpressionSyntax
>();
}
...
...
@@ -55,7 +55,7 @@ public override bool ContainingScopeHasAsyncKeyword()
throw
ExceptionUtilities
.
Unreachable
;
}
var
model
=
this
.
SemanticDocument
.
SemanticModel
;
var
model
=
SemanticDocument
.
SemanticModel
;
// special case for array initializer and explicit cast
if
(
node
.
IsArrayInitializer
())
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.StatementResult.cs
浏览文件 @
73a80651
...
...
@@ -31,7 +31,7 @@ private class StatementResult : CSharpSelectionResult
public
override
bool
ContainingScopeHasAsyncKeyword
()
{
var
node
=
this
.
GetContainingScope
();
var
node
=
GetContainingScope
();
return
node
switch
{
...
...
@@ -46,11 +46,11 @@ public override bool ContainingScopeHasAsyncKeyword()
public
override
SyntaxNode
GetContainingScope
()
{
Contract
.
ThrowIfNull
(
this
.
SemanticDocument
);
Contract
.
ThrowIfTrue
(
this
.
SelectionInExpression
);
Contract
.
ThrowIfNull
(
SemanticDocument
);
Contract
.
ThrowIfTrue
(
SelectionInExpression
);
// it contains statements
var
firstToken
=
this
.
GetFirstTokenInSelection
();
var
firstToken
=
GetFirstTokenInSelection
();
return
firstToken
.
GetAncestors
<
SyntaxNode
>().
FirstOrDefault
(
n
=>
{
return
n
is
AccessorDeclarationSyntax
||
...
...
@@ -66,10 +66,10 @@ public override SyntaxNode GetContainingScope()
public
override
ITypeSymbol
GetContainingScopeType
()
{
Contract
.
ThrowIfTrue
(
this
.
SelectionInExpression
);
Contract
.
ThrowIfTrue
(
SelectionInExpression
);
var
node
=
this
.
GetContainingScope
();
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
node
=
GetContainingScope
();
var
semanticModel
=
SemanticDocument
.
SemanticModel
;
switch
(
node
)
{
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.cs
浏览文件 @
73a80651
...
...
@@ -111,9 +111,9 @@ public StatementSyntax GetLastStatement()
public
StatementSyntax
GetFirstStatementUnderContainer
()
{
Contract
.
ThrowIfTrue
(
this
.
SelectionInExpression
);
Contract
.
ThrowIfTrue
(
SelectionInExpression
);
var
firstToken
=
this
.
GetFirstTokenInSelection
();
var
firstToken
=
GetFirstTokenInSelection
();
var
statement
=
firstToken
.
Parent
.
GetStatementUnderContainer
();
Contract
.
ThrowIfNull
(
statement
);
...
...
@@ -122,13 +122,13 @@ public StatementSyntax GetFirstStatementUnderContainer()
public
StatementSyntax
GetLastStatementUnderContainer
()
{
Contract
.
ThrowIfTrue
(
this
.
SelectionInExpression
);
Contract
.
ThrowIfTrue
(
SelectionInExpression
);
var
lastToken
=
this
.
GetLastTokenInSelection
();
var
lastToken
=
GetLastTokenInSelection
();
var
statement
=
lastToken
.
Parent
.
GetStatementUnderContainer
();
Contract
.
ThrowIfNull
(
statement
);
var
firstStatementUnderContainer
=
this
.
GetFirstStatementUnderContainer
();
var
firstStatementUnderContainer
=
GetFirstStatementUnderContainer
();
Contract
.
ThrowIfFalse
(
statement
.
Parent
==
firstStatementUnderContainer
.
Parent
);
return
statement
;
...
...
@@ -136,8 +136,8 @@ public StatementSyntax GetLastStatementUnderContainer()
public
SyntaxNode
GetInnermostStatementContainer
()
{
Contract
.
ThrowIfFalse
(
this
.
SelectionInExpression
);
var
containingScope
=
this
.
GetContainingScope
();
Contract
.
ThrowIfFalse
(
SelectionInExpression
);
var
containingScope
=
GetContainingScope
();
var
statements
=
containingScope
.
GetAncestorsOrThis
<
StatementSyntax
>();
StatementSyntax
last
=
null
;
...
...
@@ -152,23 +152,23 @@ public SyntaxNode GetInnermostStatementContainer()
}
// expression bodied member case
var
expressionBodiedMember
=
this
.
GetContainingScopeOf
<
ArrowExpressionClauseSyntax
>();
var
expressionBodiedMember
=
GetContainingScopeOf
<
ArrowExpressionClauseSyntax
>();
if
(
expressionBodiedMember
!=
null
)
{
// the class/struct declaration is the innermost statement container, since the
// member does not have a block body
return
this
.
GetContainingScopeOf
<
TypeDeclarationSyntax
>();
return
GetContainingScopeOf
<
TypeDeclarationSyntax
>();
}
// constructor initializer case
var
constructorInitializer
=
this
.
GetContainingScopeOf
<
ConstructorInitializerSyntax
>();
var
constructorInitializer
=
GetContainingScopeOf
<
ConstructorInitializerSyntax
>();
if
(
constructorInitializer
!=
null
)
{
return
constructorInitializer
.
Parent
;
}
// field initializer case
var
field
=
this
.
GetContainingScopeOf
<
FieldDeclarationSyntax
>();
var
field
=
GetContainingScopeOf
<
FieldDeclarationSyntax
>();
if
(
field
!=
null
)
{
return
field
.
Parent
;
...
...
@@ -181,7 +181,7 @@ public SyntaxNode GetInnermostStatementContainer()
public
bool
ShouldPutUnsafeModifier
()
{
var
token
=
this
.
GetFirstTokenInSelection
();
var
token
=
GetFirstTokenInSelection
();
var
ancestors
=
token
.
GetAncestors
<
SyntaxNode
>();
// if enclosing type contains unsafe keyword, we don't need to put it again
...
...
@@ -207,7 +207,7 @@ public SyntaxKind UnderCheckedStatementContext()
private
SyntaxKind
UnderCheckedContext
<
T
>()
where
T
:
SyntaxNode
{
var
token
=
this
.
GetFirstTokenInSelection
();
var
token
=
GetFirstTokenInSelection
();
var
contextNode
=
token
.
Parent
.
GetAncestor
<
T
>();
if
(
contextNode
==
null
)
{
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionValidator.cs
浏览文件 @
73a80651
...
...
@@ -32,15 +32,15 @@ internal partial class CSharpSelectionValidator : SelectionValidator
public
override
async
Task
<
SelectionResult
>
GetValidSelectionAsync
(
CancellationToken
cancellationToken
)
{
if
(!
this
.
ContainsValidSelection
)
if
(!
ContainsValidSelection
)
{
return
NullSelection
;
}
var
text
=
this
.
SemanticDocument
.
Text
;
var
root
=
this
.
SemanticDocument
.
Root
;
var
model
=
this
.
SemanticDocument
.
SemanticModel
;
var
doc
=
this
.
SemanticDocument
;
var
text
=
SemanticDocument
.
Text
;
var
root
=
SemanticDocument
.
Root
;
var
model
=
SemanticDocument
.
SemanticModel
;
var
doc
=
SemanticDocument
;
// go through pipe line and calculate information about the user selection
var
selectionInfo
=
GetInitialSelectionInfo
(
root
,
text
);
...
...
@@ -80,7 +80,7 @@ public override async Task<SelectionResult> GetValidSelectionAsync(CancellationT
selectionInfo
.
Status
,
selectionInfo
.
OriginalSpan
,
selectionInfo
.
FinalSpan
,
this
.
Options
,
Options
,
selectionInfo
.
SelectionInExpression
,
doc
,
selectionInfo
.
FirstTokenInFinalSpan
,
...
...
@@ -163,7 +163,7 @@ private TextSpan GetControlFlowSpan(SelectionInfo selectionInfo)
private
SelectionInfo
GetInitialSelectionInfo
(
SyntaxNode
root
,
SourceText
text
)
{
var
adjustedSpan
=
GetAdjustedSpan
(
text
,
this
.
OriginalSpan
);
var
adjustedSpan
=
GetAdjustedSpan
(
text
,
OriginalSpan
);
var
firstTokenInSelection
=
root
.
FindTokenOnRightOfPosition
(
adjustedSpan
.
Start
,
includeSkipped
:
false
);
var
lastTokenInSelection
=
root
.
FindTokenOnLeftOfPosition
(
adjustedSpan
.
End
,
includeSkipped
:
false
);
...
...
@@ -486,14 +486,14 @@ public SelectionInfo WithStatus(Func<OperationStatus, OperationStatus> statusGet
public
SelectionInfo
With
(
Action
<
SelectionInfo
>
valueSetter
)
{
var
newInfo
=
this
.
Clone
();
var
newInfo
=
Clone
();
valueSetter
(
newInfo
);
return
newInfo
;
}
public
SelectionInfo
Clone
()
{
return
(
SelectionInfo
)
this
.
MemberwiseClone
();
return
(
SelectionInfo
)
MemberwiseClone
();
}
}
}
...
...
src/Features/CSharp/Portable/GenerateMember/GenerateParameterizedMember/CSharpGenerateParameterizedMemberService.cs
浏览文件 @
73a80651
...
...
@@ -36,7 +36,7 @@ public InvocationExpressionInfo(SemanticDocument document, State state)
protected
override
ImmutableArray
<
ParameterName
>
DetermineParameterNames
(
CancellationToken
cancellationToken
)
{
return
this
.
Document
.
SemanticModel
.
GenerateParameterNames
(
return
Document
.
SemanticModel
.
GenerateParameterNames
(
_invocationExpression
.
ArgumentList
,
cancellationToken
);
}
...
...
@@ -47,17 +47,17 @@ protected override ITypeSymbol DetermineReturnTypeWorker(CancellationToken cance
{
// Defer to the type inferrer to figure out what the return type of this new method
// should be.
var
typeInference
=
this
.
Document
.
Document
.
GetLanguageService
<
ITypeInferenceService
>();
var
typeInference
=
Document
.
Document
.
GetLanguageService
<
ITypeInferenceService
>();
var
inferredType
=
typeInference
.
InferType
(
this
.
Document
.
SemanticModel
,
_invocationExpression
,
objectAsDefault
:
true
,
name
:
this
.
State
.
IdentifierToken
.
ValueText
,
cancellationToken
:
cancellationToken
);
Document
.
SemanticModel
,
_invocationExpression
,
objectAsDefault
:
true
,
name
:
State
.
IdentifierToken
.
ValueText
,
cancellationToken
:
cancellationToken
);
return
inferredType
;
}
protected
override
ImmutableArray
<
ITypeParameterSymbol
>
GetCapturedTypeParameters
(
CancellationToken
cancellationToken
)
{
var
result
=
new
List
<
ITypeParameterSymbol
>();
var
semanticModel
=
this
.
Document
.
SemanticModel
;
var
semanticModel
=
Document
.
SemanticModel
;
foreach
(
var
argument
in
_invocationExpression
.
ArgumentList
.
Arguments
)
{
var
type
=
argument
.
DetermineParameterType
(
semanticModel
,
cancellationToken
);
...
...
@@ -75,8 +75,8 @@ protected override ImmutableArray<ITypeParameterSymbol> GenerateTypeParameters(C
//
// TODO(cyrusn): If we do capture method type variables, then we should probably
// capture their constraints as well.
var
genericName
=
(
GenericNameSyntax
)
this
.
State
.
SimpleNameOpt
;
var
semanticModel
=
this
.
Document
.
SemanticModel
;
var
genericName
=
(
GenericNameSyntax
)
State
.
SimpleNameOpt
;
var
semanticModel
=
Document
.
SemanticModel
;
if
(
genericName
.
TypeArgumentList
.
Arguments
.
Count
==
1
)
{
...
...
@@ -121,7 +121,7 @@ private ITypeParameterSymbol GetMethodTypeParameter(TypeSyntax type, Cancellatio
{
if
(
type
is
IdentifierNameSyntax
)
{
var
info
=
this
.
Document
.
SemanticModel
.
GetTypeInfo
(
type
,
cancellationToken
);
var
info
=
Document
.
SemanticModel
.
GetTypeInfo
(
type
,
cancellationToken
);
if
(
info
.
Type
is
ITypeParameterSymbol
typeParameter
&&
typeParameter
.
TypeParameterKind
==
TypeParameterKind
.
Method
)
{
...
...
@@ -147,7 +147,7 @@ protected override ImmutableArray<ITypeSymbol> DetermineParameterTypes(Cancellat
ArgumentSyntax
argument
,
CancellationToken
cancellationToken
)
{
return
argument
.
DetermineParameterType
(
this
.
Document
.
SemanticModel
,
cancellationToken
);
return
argument
.
DetermineParameterType
(
Document
.
SemanticModel
,
cancellationToken
);
}
protected
override
ImmutableArray
<
bool
>
DetermineParameterOptionality
(
CancellationToken
cancellationToken
)
...
...
@@ -155,7 +155,7 @@ protected override ImmutableArray<bool> DetermineParameterOptionality(Cancellati
protected
override
bool
IsIdentifierName
()
{
return
this
.
State
.
SimpleNameOpt
.
Kind
()
==
SyntaxKind
.
IdentifierName
;
return
State
.
SimpleNameOpt
.
Kind
()
==
SyntaxKind
.
IdentifierName
;
}
protected
override
bool
IsImplicitReferenceConversion
(
Compilation
compilation
,
ITypeSymbol
sourceType
,
ITypeSymbol
targetType
)
...
...
@@ -172,7 +172,7 @@ protected override ImmutableArray<ITypeSymbol> DetermineTypeArguments(Cancellati
{
foreach
(
var
typeArgument
in
((
GenericNameSyntax
)
State
.
SimpleNameOpt
).
TypeArgumentList
.
Arguments
)
{
var
typeInfo
=
this
.
Document
.
SemanticModel
.
GetTypeInfo
(
typeArgument
,
cancellationToken
);
var
typeInfo
=
Document
.
SemanticModel
.
GetTypeInfo
(
typeArgument
,
cancellationToken
);
result
.
Add
(
typeInfo
.
Type
);
}
}
...
...
src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs
浏览文件 @
73a80651
...
...
@@ -505,7 +505,7 @@ private IMethodSymbol GetMethodSymbolIfPresent(SemanticModel semanticModel, Expr
var
typeArguments
=
state
.
SimpleName
.
Arity
==
genericName
.
TypeArgumentList
.
Arguments
.
Count
?
genericName
.
TypeArgumentList
.
Arguments
.
OfType
<
SyntaxNode
>().
ToList
()
:
Enumerable
.
Repeat
<
SyntaxNode
>(
null
,
state
.
SimpleName
.
Arity
);
return
this
.
GetTypeParameters
(
state
,
semanticModel
,
typeArguments
,
cancellationToken
);
return
GetTypeParameters
(
state
,
semanticModel
,
typeArguments
,
cancellationToken
);
}
return
ImmutableArray
<
ITypeParameterSymbol
>.
Empty
;
...
...
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
浏览文件 @
73a80651
...
...
@@ -43,7 +43,7 @@ internal partial class CSharpIntroduceVariableService
var
declarationStatement
=
SyntaxFactory
.
LocalDeclarationStatement
(
modifiers
,
SyntaxFactory
.
VariableDeclaration
(
this
.
GetTypeSyntax
(
document
,
expression
,
cancellationToken
),
GetTypeSyntax
(
document
,
expression
,
cancellationToken
),
SyntaxFactory
.
SingletonSeparatedList
(
SyntaxFactory
.
VariableDeclarator
(
newLocalNameToken
.
WithAdditionalAnnotations
(
RenameAnnotation
.
Create
()),
null
,
...
...
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
浏览文件 @
73a80651
...
...
@@ -169,7 +169,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
var
nextToken
=
expressionStatement
.
GetLastToken
().
GetNextToken
();
// Fade out the code up to the expression statement.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
UnnecessaryWithSuggestionDescriptor
,
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
UnnecessaryWithSuggestionDescriptor
,
Location
.
Create
(
tree
,
TextSpan
.
FromBounds
(
firstStatement
.
SpanStart
,
previousToken
.
Span
.
End
)),
additionalLocations
,
properties
));
...
...
@@ -183,7 +183,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
// If the if-statement extends past the expression statement, then fade out the rest.
if
(
nextToken
.
Span
.
Start
<
ifStatement
.
Span
.
End
)
{
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
UnnecessaryWithSuggestionDescriptor
,
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
UnnecessaryWithSuggestionDescriptor
,
Location
.
Create
(
tree
,
TextSpan
.
FromBounds
(
nextToken
.
Span
.
Start
,
ifStatement
.
Span
.
End
)),
additionalLocations
,
properties
));
}
...
...
src/Features/CSharp/Portable/LanguageServices/CSharpSymbolDisplayService.SymbolDescriptionBuilder.cs
浏览文件 @
73a80651
...
...
@@ -105,7 +105,7 @@ protected override void AddAwaitableExtensionPrefix()
{
EqualsValueClauseSyntax
initializer
=
null
;
var
variableDeclarator
=
await
this
.
GetFirstDeclarationAsync
<
VariableDeclaratorSyntax
>(
symbol
).
ConfigureAwait
(
false
);
var
variableDeclarator
=
await
GetFirstDeclarationAsync
<
VariableDeclaratorSyntax
>(
symbol
).
ConfigureAwait
(
false
);
if
(
variableDeclarator
!=
null
)
{
initializer
=
variableDeclarator
.
Initializer
;
...
...
@@ -113,7 +113,7 @@ protected override void AddAwaitableExtensionPrefix()
if
(
initializer
==
null
)
{
var
enumMemberDeclaration
=
await
this
.
GetFirstDeclarationAsync
<
EnumMemberDeclarationSyntax
>(
symbol
).
ConfigureAwait
(
false
);
var
enumMemberDeclaration
=
await
GetFirstDeclarationAsync
<
EnumMemberDeclarationSyntax
>(
symbol
).
ConfigureAwait
(
false
);
if
(
enumMemberDeclaration
!=
null
)
{
initializer
=
enumMemberDeclaration
.
EqualsValue
;
...
...
@@ -131,7 +131,7 @@ protected override void AddAwaitableExtensionPrefix()
private
async
Task
<
ImmutableArray
<
SymbolDisplayPart
>>
GetInitializerSourcePartsAsync
(
ILocalSymbol
symbol
)
{
var
syntax
=
await
this
.
GetFirstDeclarationAsync
<
VariableDeclaratorSyntax
>(
symbol
).
ConfigureAwait
(
false
);
var
syntax
=
await
GetFirstDeclarationAsync
<
VariableDeclaratorSyntax
>(
symbol
).
ConfigureAwait
(
false
);
if
(
syntax
!=
null
)
{
return
await
GetInitializerSourcePartsAsync
(
syntax
.
Initializer
).
ConfigureAwait
(
false
);
...
...
@@ -143,7 +143,7 @@ protected override void AddAwaitableExtensionPrefix()
private
async
Task
<
ImmutableArray
<
SymbolDisplayPart
>>
GetInitializerSourcePartsAsync
(
IParameterSymbol
symbol
)
{
var
syntax
=
await
this
.
GetFirstDeclarationAsync
<
ParameterSyntax
>(
symbol
).
ConfigureAwait
(
false
);
var
syntax
=
await
GetFirstDeclarationAsync
<
ParameterSyntax
>(
symbol
).
ConfigureAwait
(
false
);
if
(
syntax
!=
null
)
{
return
await
GetInitializerSourcePartsAsync
(
syntax
.
Default
).
ConfigureAwait
(
false
);
...
...
@@ -156,7 +156,7 @@ protected override void AddAwaitableExtensionPrefix()
{
foreach
(
var
syntaxRef
in
symbol
.
DeclaringSyntaxReferences
)
{
var
syntax
=
await
syntaxRef
.
GetSyntaxAsync
(
this
.
CancellationToken
).
ConfigureAwait
(
false
);
var
syntax
=
await
syntaxRef
.
GetSyntaxAsync
(
CancellationToken
).
ConfigureAwait
(
false
);
if
(
syntax
is
T
tSyntax
)
{
return
tSyntax
;
...
...
@@ -176,7 +176,7 @@ protected override void AddAwaitableExtensionPrefix()
{
return
await
Classifier
.
GetClassifiedSymbolDisplayPartsAsync
(
semanticModel
,
equalsValue
.
Value
.
Span
,
this
.
Workspace
,
cancellationToken
:
this
.
CancellationToken
).
ConfigureAwait
(
false
);
Workspace
,
cancellationToken
:
CancellationToken
).
ConfigureAwait
(
false
);
}
}
...
...
src/Features/CSharp/Portable/LanguageServices/CSharpSymbolDisplayService.cs
浏览文件 @
73a80651
...
...
@@ -28,7 +28,7 @@ public override ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(Semantic
protected
override
AbstractSymbolDescriptionBuilder
CreateDescriptionBuilder
(
Workspace
workspace
,
SemanticModel
semanticModel
,
int
position
,
CancellationToken
cancellationToken
)
{
return
new
SymbolDescriptionBuilder
(
this
,
semanticModel
,
position
,
workspace
,
this
.
AnonymousTypeDisplayService
,
cancellationToken
);
return
new
SymbolDescriptionBuilder
(
this
,
semanticModel
,
position
,
workspace
,
AnonymousTypeDisplayService
,
cancellationToken
);
}
}
}
src/Features/CSharp/Portable/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs
浏览文件 @
73a80651
...
...
@@ -44,7 +44,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
context
.
RegisterCodeFix
(
new
MyCodeAction
(
CSharpFeaturesResources
.
Use_is_null_check
,
c
=>
this
.
FixAsync
(
context
.
Document
,
diagnostic
,
c
)),
c
=>
FixAsync
(
context
.
Document
,
diagnostic
,
c
)),
context
.
Diagnostics
);
}
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
浏览文件 @
73a80651
...
...
@@ -98,7 +98,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext context)
context
.
ReportDiagnostic
(
DiagnosticHelper
.
Create
(
this
.
Descriptor
,
isExpression
.
GetLocation
(),
Descriptor
,
isExpression
.
GetLocation
(),
styleOption
.
Notification
.
Severity
,
SpecializedCollections
.
EmptyCollection
<
Location
>(),
ImmutableDictionary
<
string
,
string
>.
Empty
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录