Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
582fe695
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,发现更多精彩内容 >>
提交
582fe695
编写于
5月 14, 2018
作者:
A
Alireza Habibi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renamings.
上级
ec5566ba
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
50 deletion
+51
-50
src/Features/CSharp/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.cs
...eRefactorings/InvertIf/InvertIfCodeRefactoringProvider.cs
+13
-11
src/Features/Core/Portable/CodeRefactorings/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs
...rings/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs
+36
-37
src/Features/VisualBasic/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.MultiLine.vb
...ngs/InvertIf/InvertIfCodeRefactoringProvider.MultiLine.vb
+1
-1
src/Features/VisualBasic/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.SingleLine.vb
...gs/InvertIf/InvertIfCodeRefactoringProvider.SingleLine.vb
+1
-1
未找到文件。
src/Features/CSharp/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.cs
浏览文件 @
582fe695
...
...
@@ -27,7 +27,7 @@ internal sealed class CSharpInvertIfCodeRefactoringProvider : AbstractInvertIfCo
SemanticModel
semanticModel
,
IfStatementSyntax
ifStatement
,
InvertIfStyle
invertIfStyle
,
SyntaxNode
subsequen
ce
SingleExitPointOpt
,
SyntaxNode
subsequen
t
SingleExitPointOpt
,
SyntaxNode
negatedExpression
,
CancellationToken
cancellationToken
)
{
...
...
@@ -98,7 +98,7 @@ internal sealed class CSharpInvertIfCodeRefactoringProvider : AbstractInvertIfCo
return
root
.
ReplaceNode
(
ifNode
,
updatedIf
);
}
case
InvertIfStyle
.
SwapIfBodyWithSubsequen
ce
:
case
InvertIfStyle
.
SwapIfBodyWithSubsequen
tStatements
:
{
var
ifBody
=
ifNode
.
Statement
;
...
...
@@ -119,7 +119,7 @@ internal sealed class CSharpInvertIfCodeRefactoringProvider : AbstractInvertIfCo
return
root
.
ReplaceNode
(
currentParent
,
updatedParent
);
}
case
InvertIfStyle
.
WithNearmostJump
:
case
InvertIfStyle
.
WithNearmostJump
Statement
:
{
var
newIfBody
=
GetNearmostAncestorJumpStatement
();
var
updatedIf
=
ifNode
.
WithCondition
(
negatedCondition
)
...
...
@@ -152,9 +152,9 @@ StatementSyntax GetNearmostAncestorJumpStatement()
}
}
case
InvertIfStyle
.
WithSubsequen
ceExitPoi
nt
:
case
InvertIfStyle
.
WithSubsequen
tExitPointStateme
nt
:
{
var
newIfBody
=
(
StatementSyntax
)
subsequen
ce
SingleExitPointOpt
;
var
newIfBody
=
(
StatementSyntax
)
subsequen
t
SingleExitPointOpt
;
var
updatedIf
=
ifNode
.
WithCondition
(
negatedCondition
)
.
WithStatement
(
SyntaxFactory
.
Block
(
newIfBody
));
...
...
@@ -170,7 +170,7 @@ StatementSyntax GetNearmostAncestorJumpStatement()
return
root
.
ReplaceNode
(
currentParent
,
updatedParent
);
}
case
InvertIfStyle
.
MoveSubsequen
ce
ToElseBody
:
case
InvertIfStyle
.
MoveSubsequen
tStatements
ToElseBody
:
{
var
currentParent
=
ifNode
.
Parent
;
var
statements
=
GetStatements
(
currentParent
);
...
...
@@ -338,7 +338,7 @@ private static void AssertStatementRange(StatementSyntax firstStatement, Stateme
}
#endif
protected
override
IEnumerable
<(
SyntaxNode
first
,
SyntaxNode
last
)>
GetSubsequentStatementRange
(
IfStatementSyntax
ifStatement
)
protected
override
IEnumerable
<(
SyntaxNode
first
,
SyntaxNode
last
)>
GetSubsequentStatementRange
s
(
IfStatementSyntax
ifStatement
)
{
StatementSyntax
innerStatement
=
ifStatement
;
foreach
(
var
node
in
ifStatement
.
Ancestors
())
...
...
@@ -349,16 +349,18 @@ protected override IEnumerable<(SyntaxNode first, SyntaxNode last)> GetSubsequen
case
SyntaxKind
.
Block
:
if
(
nextStatement
!=
null
)
{
AssertStatementRange
(
nextStatement
,
((
BlockSyntax
)
node
).
Statements
.
Last
());
yield
return
(
nextStatement
,
((
BlockSyntax
)
node
).
Statements
.
Last
());
var
lastStatement
=
((
BlockSyntax
)
node
).
Statements
.
Last
();
AssertStatementRange
(
nextStatement
,
lastStatement
);
yield
return
(
nextStatement
,
lastStatement
);
}
break
;
case
SyntaxKind
.
SwitchSection
:
if
(
nextStatement
!=
null
)
{
AssertStatementRange
(
nextStatement
,
((
SwitchSectionSyntax
)
node
).
Statements
.
Last
());
yield
return
(
nextStatement
,
((
SwitchSectionSyntax
)
node
).
Statements
.
Last
());
var
lastStatement
=
((
SwitchSectionSyntax
)
node
).
Statements
.
Last
();
AssertStatementRange
(
nextStatement
,
lastStatement
);
yield
return
(
nextStatement
,
lastStatement
);
}
yield
break
;
...
...
src/Features/Core/Portable/CodeRefactorings/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs
浏览文件 @
582fe695
...
...
@@ -56,7 +56,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
}
var
document
=
context
.
Document
;
SyntaxNode
subsequen
ce
SingleExitPointOpt
=
null
;
SyntaxNode
subsequen
t
SingleExitPointOpt
=
null
;
InvertIfStyle
invertIfStyle
;
if
(
IsElselessIfStatement
(
ifStatement
))
...
...
@@ -64,7 +64,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
invertIfStyle
=
GetInvertIfStyle
(
ifStatement
,
await
document
.
GetSemanticModelAsync
().
ConfigureAwait
(
false
),
ref
subsequen
ce
SingleExitPointOpt
);
ref
subsequen
t
SingleExitPointOpt
);
}
else
{
...
...
@@ -74,7 +74,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
context
.
RegisterRefactoring
(
new
MyCodeAction
(
GetTitle
(),
c
=>
InvertIfAsync
(
document
,
ifStatement
,
invertIfStyle
,
subsequen
ce
SingleExitPointOpt
,
c
)));
c
=>
InvertIfAsync
(
document
,
ifStatement
,
invertIfStyle
,
subsequen
t
SingleExitPointOpt
,
c
)));
}
protected
enum
InvertIfStyle
...
...
@@ -82,17 +82,17 @@ protected enum InvertIfStyle
// swap if and else
Normal
,
// swap subsequent statements and if body
SwapIfBodyWithSubsequen
ce
,
SwapIfBodyWithSubsequen
tStatements
,
// move subsequent statements to if body
MoveSubsequen
ce
ToElseBody
,
MoveSubsequen
tStatements
ToElseBody
,
// invert and generete else
WithElseClause
,
// invert and generate else, keep if-body empty
MoveIfBodyToElseClause
,
// invert and copy the exit point statement
WithSubsequen
ceExitPoi
nt
,
WithSubsequen
tExitPointStateme
nt
,
// invert and generate return, break, continue
WithNearmostJump
,
WithNearmostJump
Statement
,
// just invert the condition
WithNegatedCondition
,
}
...
...
@@ -100,7 +100,7 @@ protected enum InvertIfStyle
private
InvertIfStyle
GetInvertIfStyle
(
TIfStatementSyntax
ifStatement
,
SemanticModel
semanticModel
,
ref
SyntaxNode
subsequen
ce
SingleExitPointOpt
)
ref
SyntaxNode
subsequen
t
SingleExitPointOpt
)
{
if
(
IsEmptyIfBody
(
ifStatement
))
{
...
...
@@ -115,7 +115,7 @@ protected enum InvertIfStyle
return
InvertIfStyle
.
WithNegatedCondition
;
}
if
(
IsEmptySubsequence
(
ifStatement
))
if
(
NoSubsequentStatements
(
ifStatement
))
{
// No statements if-statement, return with nearmost jump-statement
//
...
...
@@ -134,7 +134,7 @@ protected enum InvertIfStyle
// Body();
// }
//
return
InvertIfStyle
.
WithNearmostJump
;
return
InvertIfStyle
.
WithNearmostJump
Statement
;
}
AnalyzeIfBodyControlFlow
(
...
...
@@ -142,12 +142,12 @@ protected enum InvertIfStyle
out
var
ifBodyEndPointIsReachable
,
out
var
ifBodySingleExitPointOpt
);
AnalyzeSubsequen
ce
ControlFlow
(
AnalyzeSubsequen
t
ControlFlow
(
semanticModel
,
ifStatement
,
out
var
subsequen
ce
EndPontIsReachable
,
out
subsequen
ce
SingleExitPointOpt
);
out
var
subsequen
t
EndPontIsReachable
,
out
subsequen
t
SingleExitPointOpt
);
if
(
subsequen
ce
EndPontIsReachable
)
if
(
subsequen
t
EndPontIsReachable
)
{
if
(
ifBodyEndPointIsReachable
)
{
...
...
@@ -159,7 +159,7 @@ protected enum InvertIfStyle
SubsequentStatementsAreInTheSameBlock
(
ifStatement
)
&&
ifBodySingleExitPointOpt
?.
RawKind
==
GetNearmostParentJumpStatementRawKind
(
ifStatement
))
{
return
InvertIfStyle
.
MoveSubsequen
ce
ToElseBody
;
return
InvertIfStyle
.
MoveSubsequen
tStatements
ToElseBody
;
}
else
{
...
...
@@ -171,10 +171,10 @@ protected enum InvertIfStyle
{
if
(
ifBodyEndPointIsReachable
)
{
if
(
subsequen
ce
SingleExitPointOpt
!=
null
&&
SingleSubsequen
ce
Statement
(
ifStatement
))
if
(
subsequen
t
SingleExitPointOpt
!=
null
&&
SingleSubsequen
t
Statement
(
ifStatement
))
{
return
InvertIfStyle
.
WithSubsequen
ceExitPoi
nt
;
return
InvertIfStyle
.
WithSubsequen
tExitPointStateme
nt
;
}
else
{
...
...
@@ -185,7 +185,7 @@ protected enum InvertIfStyle
{
if
(
SubsequentStatementsAreInTheSameBlock
(
ifStatement
))
{
return
InvertIfStyle
.
SwapIfBodyWithSubsequen
ce
;
return
InvertIfStyle
.
SwapIfBodyWithSubsequen
tStatements
;
}
else
{
...
...
@@ -195,9 +195,9 @@ protected enum InvertIfStyle
}
}
private
bool
IsEmptySubsequence
(
TIfStatementSyntax
ifStatement
)
private
bool
NoSubsequentStatements
(
TIfStatementSyntax
ifStatement
)
{
foreach
(
var
range
in
GetSubsequentStatementRange
(
ifStatement
))
foreach
(
var
range
in
GetSubsequentStatementRange
s
(
ifStatement
))
{
if
(!
IsEmptyStatementRange
(
range
))
{
...
...
@@ -219,9 +219,9 @@ private bool SingleIfBodyStatement(TIfStatementSyntax ifStatement)
return
range
.
first
==
range
.
last
;
}
private
bool
SingleSubsequen
ce
Statement
(
TIfStatementSyntax
ifStatement
)
private
bool
SingleSubsequen
t
Statement
(
TIfStatementSyntax
ifStatement
)
{
using
(
var
e
=
GetSubsequentStatementRange
(
ifStatement
).
GetEnumerator
())
using
(
var
e
=
GetSubsequentStatementRange
s
(
ifStatement
).
GetEnumerator
())
{
return
e
.
MoveNext
()
&&
e
.
Current
.
first
==
e
.
Current
.
last
&&
!
e
.
MoveNext
();
}
...
...
@@ -231,7 +231,7 @@ private bool SingleSubsequenceStatement(TIfStatementSyntax ifStatement)
Document
document
,
TIfStatementSyntax
ifStatement
,
InvertIfStyle
invertIfStyle
,
SyntaxNode
subsequen
ce
SingleExitPointOpt
,
SyntaxNode
subsequen
t
SingleExitPointOpt
,
CancellationToken
cancellationToken
)
{
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -247,25 +247,24 @@ private bool SingleSubsequenceStatement(TIfStatementSyntax ifStatement)
semanticModel
,
ifStatement
,
invertIfStyle
,
subsequen
ce
SingleExitPointOpt
,
subsequen
t
SingleExitPointOpt
,
negatedExpression
,
cancellationToken
));
}
private
void
AnalyzeSubsequenceControlFlow
(
private
void
AnalyzeSubsequentControlFlow
(
SemanticModel
semanticModel
,
TIfStatementSyntax
ifStatement
,
out
bool
subsequen
ce
EndPontIsReachable
,
out
SyntaxNode
subsequen
ce
SingleExitPointOpt
)
out
bool
subsequen
t
EndPontIsReachable
,
out
SyntaxNode
subsequen
t
SingleExitPointOpt
)
{
subsequen
ce
EndPontIsReachable
=
true
;
subsequen
ce
SingleExitPointOpt
=
null
;
subsequen
t
EndPontIsReachable
=
true
;
subsequen
t
SingleExitPointOpt
=
null
;
foreach
(
var
range
in
GetSubsequentStatementRange
(
ifStatement
))
foreach
(
var
range
in
GetSubsequentStatementRange
s
(
ifStatement
))
{
AnalyzeControlFlow
(
semanticModel
,
range
,
out
subsequen
ceEndPontIsReachable
,
out
subsequence
SingleExitPointOpt
);
if
(!
subsequen
ce
EndPontIsReachable
)
AnalyzeControlFlow
(
semanticModel
,
range
,
out
subsequen
tEndPontIsReachable
,
out
subsequent
SingleExitPointOpt
);
if
(!
subsequen
t
EndPontIsReachable
)
{
return
;
}
...
...
@@ -298,7 +297,7 @@ private bool SingleSubsequenceStatement(TIfStatementSyntax ifStatement)
private
bool
SubsequentStatementsAreInTheSameBlock
(
TIfStatementSyntax
ifStatement
)
{
var
(
start
,
_
)
=
GetSubsequentStatementRange
(
ifStatement
).
First
();
var
(
start
,
_
)
=
GetSubsequentStatementRange
s
(
ifStatement
).
First
();
return
ifStatement
.
Parent
==
start
.
Parent
;
}
...
...
@@ -310,7 +309,7 @@ private bool SubsequentStatementsAreInTheSameBlock(TIfStatementSyntax ifStatemen
protected
abstract
bool
IsEmptyStatementRange
((
SyntaxNode
first
,
SyntaxNode
last
)
range
);
protected
abstract
(
SyntaxNode
first
,
SyntaxNode
last
)
GetIfBodyStatementRange
(
TIfStatementSyntax
ifStatement
);
protected
abstract
IEnumerable
<(
SyntaxNode
first
,
SyntaxNode
last
)>
GetSubsequentStatementRange
(
TIfStatementSyntax
ifStatement
);
protected
abstract
IEnumerable
<(
SyntaxNode
first
,
SyntaxNode
last
)>
GetSubsequentStatementRange
s
(
TIfStatementSyntax
ifStatement
);
protected
abstract
TextSpan
GetHeaderSpan
(
TIfStatementSyntax
ifStatement
);
protected
abstract
string
GetTitle
();
...
...
@@ -320,7 +319,7 @@ private bool SubsequentStatementsAreInTheSameBlock(TIfStatementSyntax ifStatemen
SemanticModel
semanticModel
,
TIfStatementSyntax
ifStatement
,
InvertIfStyle
invertIfStyle
,
SyntaxNode
subsequen
ce
SingleExitPointOpt
,
SyntaxNode
subsequen
t
SingleExitPointOpt
,
SyntaxNode
negatedExpression
,
CancellationToken
cancellationToken
);
...
...
src/Features/VisualBasic/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.MultiLine.vb
浏览文件 @
582fe695
...
...
@@ -74,7 +74,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.InvertIf
Throw
New
NotImplementedException
()
End
Function
Protected
Overrides
Function
GetSubsequentStatementRange
(
ifStatement
As
MultiLineIfBlockSyntax
)
As
IEnumerable
(
Of
(
first
As
SyntaxNode
,
last
As
SyntaxNode
))
Protected
Overrides
Function
GetSubsequentStatementRange
s
(
ifStatement
As
MultiLineIfBlockSyntax
)
As
IEnumerable
(
Of
(
first
As
SyntaxNode
,
last
As
SyntaxNode
))
Throw
New
NotImplementedException
()
End
Function
...
...
src/Features/VisualBasic/Portable/CodeRefactorings/InvertIf/InvertIfCodeRefactoringProvider.SingleLine.vb
浏览文件 @
582fe695
...
...
@@ -125,7 +125,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.InvertIf
Throw
New
NotImplementedException
()
End
Function
Protected
Overrides
Function
GetSubsequentStatementRange
(
ifStatement
As
SingleLineIfStatementSyntax
)
As
IEnumerable
(
Of
(
first
As
SyntaxNode
,
last
As
SyntaxNode
))
Protected
Overrides
Function
GetSubsequentStatementRange
s
(
ifStatement
As
SingleLineIfStatementSyntax
)
As
IEnumerable
(
Of
(
first
As
SyntaxNode
,
last
As
SyntaxNode
))
Throw
New
NotImplementedException
()
End
Function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录