Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5fa24d59
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,发现更多精彩内容 >>
提交
5fa24d59
编写于
1月 18, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass along cancellation token where appropriate instead of using CancellationToken.None
上级
01625ff8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
37 addition
and
26 deletion
+37
-26
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
...InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
+1
-1
src/Features/VisualBasic/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.vb
...InlineTemporary/InlineTemporaryCodeRefactoringProvider.vb
+2
-1
src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs
.../CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs
+13
-9
src/Workspaces/CSharp/Portable/Simplification/CSharpSimplificationService.Expander.cs
...le/Simplification/CSharpSimplificationService.Expander.cs
+1
-1
src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb
...alBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb
+18
-12
src/Workspaces/VisualBasic/Portable/Simplification/VisualBasicSimplificationService.Expander.vb
...mplification/VisualBasicSimplificationService.Expander.vb
+2
-2
未找到文件。
src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
浏览文件 @
5fa24d59
...
...
@@ -460,7 +460,7 @@ private ExpressionSyntax SkipRedundantExteriorParentheses(ExpressionSyntax expre
var
newVariableDeclarator
=
await
FindDeclaratorAsync
(
updatedDocument
,
cancellationToken
).
ConfigureAwait
(
false
);
localSymbol
=
(
ILocalSymbol
)
semanticModel
.
GetDeclaredSymbol
(
newVariableDeclarator
,
cancellationToken
);
var
explicitCastExpression
=
newExpression
.
CastIfPossible
(
localSymbol
.
Type
,
newVariableDeclarator
.
SpanStart
,
semanticModel
);
var
explicitCastExpression
=
newExpression
.
CastIfPossible
(
localSymbol
.
Type
,
newVariableDeclarator
.
SpanStart
,
semanticModel
,
cancellationToken
);
if
(
explicitCastExpression
!=
newExpression
)
{
updatedDocument
=
await
updatedDocument
.
ReplaceNodeAsync
(
newExpression
,
explicitCastExpression
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
src/Features/VisualBasic/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.vb
浏览文件 @
5fa24d59
...
...
@@ -412,7 +412,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.InlineTemporary
explicitInitializer
=
explicitInitializer
.
CastIfPossible
(
local
.
Type
,
modifiedIdentifier
.
SpanStart
,
semanticModel
,
wasCastAdded
)
wasCastAdded
,
cancellationToken
)
Return
explicitInitializer
.
WithAdditionalAnnotations
(
s_expressionToInlineAnnotation
)
End
Function
...
...
src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs
浏览文件 @
5fa24d59
...
...
@@ -97,7 +97,8 @@ public static ExpressionSyntax WalkDownParentheses(this ExpressionSyntax express
this
ExpressionSyntax
expression
,
ITypeSymbol
targetType
,
int
position
,
SemanticModel
semanticModel
)
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
{
if
(
targetType
.
ContainsAnonymousType
())
{
...
...
@@ -123,7 +124,7 @@ public static ExpressionSyntax WalkDownParentheses(this ExpressionSyntax express
var
castExpression
=
expression
.
Cast
(
targetType
);
// Ensure that inserting the cast doesn't change the semantics.
var
specAnalyzer
=
new
SpeculationAnalyzer
(
expression
,
castExpression
,
semanticModel
,
CancellationToken
.
None
);
var
specAnalyzer
=
new
SpeculationAnalyzer
(
expression
,
castExpression
,
semanticModel
,
cancellationToken
);
var
speculativeSemanticModel
=
specAnalyzer
.
SpeculativeSemanticModel
;
if
(
speculativeSemanticModel
==
null
)
{
...
...
@@ -131,7 +132,7 @@ public static ExpressionSyntax WalkDownParentheses(this ExpressionSyntax express
}
var
speculatedCastExpression
=
(
CastExpressionSyntax
)
specAnalyzer
.
ReplacedExpression
;
if
(!
speculatedCastExpression
.
IsUnnecessaryCast
(
speculativeSemanticModel
,
CancellationToken
.
None
))
if
(!
speculatedCastExpression
.
IsUnnecessaryCast
(
speculativeSemanticModel
,
cancellationToken
))
{
return
expression
;
}
...
...
@@ -762,7 +763,7 @@ private static bool CanReplace(ISymbol symbol)
return
true
;
}
return
TrySimplify
(
expression
,
semanticModel
,
out
replacementNode
,
out
issueSpan
);
return
TrySimplify
(
expression
,
semanticModel
,
out
replacementNode
,
out
issueSpan
,
cancellationToken
);
}
private
static
bool
TryReduceExplicitName
(
...
...
@@ -1933,7 +1934,8 @@ private static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
ExpressionSyntax
expression
,
SemanticModel
semanticModel
,
out
ExpressionSyntax
replacementNode
,
out
TextSpan
issueSpan
)
out
TextSpan
issueSpan
,
CancellationToken
cancellationToken
)
{
replacementNode
=
null
;
issueSpan
=
default
;
...
...
@@ -1955,7 +1957,7 @@ private static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
.
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
// Ensure that replacement doesn't change semantics.
return
!
ReplacementChangesSemantics
(
memberAccess
,
replacementNode
,
semanticModel
);
return
!
ReplacementChangesSemantics
(
memberAccess
,
replacementNode
,
semanticModel
,
cancellationToken
);
}
return
false
;
...
...
@@ -1971,7 +1973,7 @@ private static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
.
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
// Ensure that replacement doesn't change semantics.
return
!
ReplacementChangesSemantics
(
qualifiedName
,
replacementNode
,
semanticModel
);
return
!
ReplacementChangesSemantics
(
qualifiedName
,
replacementNode
,
semanticModel
,
cancellationToken
);
}
return
false
;
...
...
@@ -1981,9 +1983,11 @@ private static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
return
false
;
}
private
static
bool
ReplacementChangesSemantics
(
ExpressionSyntax
originalExpression
,
ExpressionSyntax
replacedExpression
,
SemanticModel
semanticModel
)
private
static
bool
ReplacementChangesSemantics
(
ExpressionSyntax
originalExpression
,
ExpressionSyntax
replacedExpression
,
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
{
var
speculationAnalyzer
=
new
SpeculationAnalyzer
(
originalExpression
,
replacedExpression
,
semanticModel
,
CancellationToken
.
None
);
var
speculationAnalyzer
=
new
SpeculationAnalyzer
(
originalExpression
,
replacedExpression
,
semanticModel
,
cancellationToken
);
return
speculationAnalyzer
.
ReplacementChangesSemantics
();
}
...
...
src/Workspaces/CSharp/Portable/Simplification/CSharpSimplificationService.Expander.cs
浏览文件 @
5fa24d59
...
...
@@ -106,7 +106,7 @@ private bool TryCastTo(ITypeSymbol targetType, ExpressionSyntax expression, Expr
var
speculativeSemanticModel
=
speculativeAnalyzer
.
SpeculativeSemanticModel
;
var
speculatedExpression
=
speculativeAnalyzer
.
ReplacedExpression
;
var
result
=
speculatedExpression
.
CastIfPossible
(
targetType
,
speculatedExpression
.
SpanStart
,
speculativeSemanticModel
);
var
result
=
speculatedExpression
.
CastIfPossible
(
targetType
,
speculatedExpression
.
SpanStart
,
speculativeSemanticModel
,
_cancellationToken
);
if
(
result
!=
speculatedExpression
)
{
...
...
src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb
浏览文件 @
5fa24d59
...
...
@@ -260,8 +260,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
targetType
As
ITypeSymbol
,
position
As
Integer
,
semanticModel
As
SemanticModel
,
<
Out
>
ByRef
wasCastAdded
As
Boolean
)
As
ExpressionSyntax
<
Out
>
ByRef
wasCastAdded
As
Boolean
,
cancellationToken
As
CancellationToken
)
As
ExpressionSyntax
wasCastAdded
=
False
If
targetType
.
ContainsAnonymousType
()
OrElse
expression
.
IsParentKind
(
SyntaxKind
.
AsNewClause
)
Then
...
...
@@ -282,7 +283,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Dim
castExpression
=
expression
.
Cast
(
targetType
,
isResultPredefinedCast
)
' Ensure that inserting the cast doesn't change the semantics.
Dim
specAnalyzer
=
New
SpeculationAnalyzer
(
expression
,
castExpression
,
semanticModel
,
CancellationToken
.
None
)
Dim
specAnalyzer
=
New
SpeculationAnalyzer
(
expression
,
castExpression
,
semanticModel
,
cancellationToken
)
Dim
speculativeSemanticModel
=
specAnalyzer
.
SpeculativeSemanticModel
If
speculativeSemanticModel
Is
Nothing
Then
Return
expression
...
...
@@ -292,7 +293,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Dim
speculatedCastInnerExpression
=
If
(
isResultPredefinedCast
,
DirectCast
(
speculatedCastExpression
,
PredefinedCastExpressionSyntax
).
Expression
,
DirectCast
(
speculatedCastExpression
,
CastExpressionSyntax
).
Expression
)
If
Not
CastAnalyzer
.
IsUnnecessary
(
speculatedCastExpression
,
speculatedCastInnerExpression
,
speculativeSemanticModel
,
True
,
CancellationToken
.
None
)
Then
If
Not
CastAnalyzer
.
IsUnnecessary
(
speculatedCastExpression
,
speculatedCastInnerExpression
,
speculativeSemanticModel
,
True
,
cancellationToken
)
Then
Return
expression
End
If
...
...
@@ -922,7 +923,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return
True
End
If
Return
expression
.
TrySimplify
(
semanticModel
,
replacementNode
,
issueSpan
)
Return
expression
.
TrySimplify
(
semanticModel
,
replacementNode
,
issueSpan
,
cancellationToken
)
End
Function
<
Extension
()
>
...
...
@@ -1607,9 +1608,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Private
Function
TrySimplify
(
expression
As
ExpressionSyntax
,
semanticModel
As
SemanticModel
,
<
Out
()
>
ByRef
replacementNode
As
ExpressionSyntax
,
<
Out
()
>
ByRef
issueSpan
As
TextSpan
)
As
Boolean
<
Out
>
ByRef
replacementNode
As
ExpressionSyntax
,
<
Out
>
ByRef
issueSpan
As
TextSpan
,
cancellationToken
As
CancellationToken
)
As
Boolean
replacementNode
=
Nothing
issueSpan
=
Nothing
...
...
@@ -1623,7 +1625,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
replacementNode
=
memberAccess
.
Update
(
memberAccess
.
Kind
,
newLeft
,
memberAccess
.
OperatorToken
,
memberAccess
.
Name
).
WithAdditionalAnnotations
(
Simplifier
.
Annotation
)
' Ensure that replacement doesn't change semantics.
Return
Not
ReplacementChangesSemantics
(
memberAccess
,
replacementNode
,
semanticModel
)
Return
Not
ReplacementChangesSemantics
(
memberAccess
,
replacementNode
,
semanticModel
,
cancellationToken
)
End
If
Return
False
...
...
@@ -1642,7 +1644,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
replacementNode
=
qualifiedName
.
Update
(
DirectCast
(
newLeft
,
NameSyntax
),
qualifiedName
.
DotToken
,
qualifiedName
.
Right
).
WithAdditionalAnnotations
(
Simplifier
.
Annotation
)
' Ensure that replacement doesn't change semantics.
Return
Not
ReplacementChangesSemantics
(
qualifiedName
,
replacementNode
,
semanticModel
)
Return
Not
ReplacementChangesSemantics
(
qualifiedName
,
replacementNode
,
semanticModel
,
cancellationToken
)
End
If
Return
False
...
...
@@ -1652,8 +1654,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return
False
End
Function
Private
Function
ReplacementChangesSemantics
(
originalExpression
As
ExpressionSyntax
,
replacedExpression
As
ExpressionSyntax
,
semanticModel
As
SemanticModel
)
As
Boolean
Dim
speculationAnalyzer
=
New
SpeculationAnalyzer
(
originalExpression
,
replacedExpression
,
semanticModel
,
CancellationToken
.
None
)
Private
Function
ReplacementChangesSemantics
(
originalExpression
As
ExpressionSyntax
,
replacedExpression
As
ExpressionSyntax
,
semanticModel
As
SemanticModel
,
cancellationToken
As
CancellationToken
)
As
Boolean
Dim
speculationAnalyzer
=
New
SpeculationAnalyzer
(
originalExpression
,
replacedExpression
,
semanticModel
,
cancellationToken
)
Return
speculationAnalyzer
.
ReplacementChangesSemantics
()
End
Function
...
...
src/Workspaces/VisualBasic/Portable/Simplification/VisualBasicSimplificationService.Expander.vb
浏览文件 @
5fa24d59
...
...
@@ -58,9 +58,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification
Return
AddCast
(
expression
,
targetType
,
semanticModel
)
End
Function
Private
Shared
Function
AddCast
(
expression
As
ExpressionSyntax
,
targetType
As
ITypeSymbol
,
semanticModel
As
SemanticModel
)
As
ExpressionSyntax
Private
Function
AddCast
(
expression
As
ExpressionSyntax
,
targetType
As
ITypeSymbol
,
semanticModel
As
SemanticModel
)
As
ExpressionSyntax
Dim
wasCastAdded
As
Boolean
=
False
Dim
result
=
expression
.
CastIfPossible
(
targetType
,
expression
.
SpanStart
,
semanticModel
,
wasCastAdded
)
Dim
result
=
expression
.
CastIfPossible
(
targetType
,
expression
.
SpanStart
,
semanticModel
,
wasCastAdded
,
_cancellationToken
)
If
wasCastAdded
Then
result
=
result
.
Parenthesize
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录